Terraform Gitlab Backend Feedback
Problem to solve
View TF files stored in Gitlab.com UI when Gitlab is used as the backend
Handling multiple state files for multiple environments when using Gitlab as the backend
Further details
Hi there. I tried Terraform with Gitlab (gitlab.com) as the backend. While it worked after some struggle, I had a question.
As mentioned gitlab is managing the state which is great, but where do we see the state files in the UI? The URL mentioned is this GITLAB_TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}
But I am not sure where I can see the state file remotely in Gitlab (I see docs on where to see this on a self-hosted instance in the folder but I can't do such things in Gitlab.com).
Also, while I see that its making a call to https://gitlab.com/api/v4/projects/${PROJECT_ID}/terraform/state/${PROJECT_NAME}
I don't see such an API documented in the GITLAB website. What API is it actually calling? Passing /terraform/state as the parameter.
UPDATE: I was able to view the terraform file in the URL (with browser/postman) with basic authorization. Now, I understand how this works but its kind of not intuitive.
Also, if I have multiple environments like dev, staging and prod for a repo, how will I manage multiple state files? Can I change CI_PROJECT_NAME to add the suffix like this?
GITLAB_TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}-dev
GITLAB_TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}-prod
UPDATE: I tried doing this and it works. So, looks like I can save multiple states per project like this.
Also, the docs at https://docs.gitlab.com/ee/user/infrastructure/ has a test
stage but don't find it used in the pipeline. Just wanted to let you know.
PS: I removed my question with my pipeline since it worked after I set my branch as protected (My bad, had enabled variables only for protected branches and authentication was failing since I didn't protect the branch which works now)
Who can address the issue
@nagyv-gitlab @nicholasklick @mattkasa @tigerwnz
Other links/references
I did have a look at these related issues: