Terraform init commands for new state - UI Enhancement
Proposal
This issue provided the commands to access a terraform state file from your local computer, but ONLY for existing state files. Meaning the first push would need to be setup manually following the documentation as described and clarified by this MR.
The challenge is the initial setup requires pulling together multiple pieces of information GitLab can determine easily, based on context.
In addition to the links to documentation, display a code suggestion box exactly as if the state file already exists.
If this option is used; the state name would need to be suggested (i.e. production, terraform, gitlab, etc).
export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
echo "terraform {
backend "http" {
}
}" > backend.tf
terraform init \
-backend-config="address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-STATE-NAME>" \
-backend-config="lock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-STATE-NAME>/lock" \
-backend-config="unlock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-STATE-NAME>/lock" \
-backend-config="username=<YOUR-USERNAME>" \
-backend-config="password=$GITLAB_ACCESS_TOKEN" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
Implementation guide
Update the Terraform empty state in app/assets/javascripts/terraform/components/empty_state.vue
:
- Remove the
#description
slot in favor of#actions
- Use the primary button for the documentation link "Explore documentation"
- Use
<clipboard-button/>
for the command - You can see an example of generated Terraform init command in
app/assets/javascripts/terraform/components/init_command_modal.vue
- Update specs at
spec/frontend/terraform/components/empty_state_spec.js
/cc @nagyv-gitlab
Edited by Anna Vovchenko