(Ici, ce que vous voulez avant le lien) (Ici vous racontez votre vie)
terraform -> gitlab/script/etc.
src: https://stackoverflow.com/questions/75531444/how-to-use-terraform-variable-into-gitlab-ci-yml
- Terraform : use an "output"
locals {
toto = format ("${var.ressource_name_pattern}-something", "cloudfront-edge")
}
output "toto" {
value = local.toto
}
- Script: get output from terraform command
foobar = ${terraform output toto}
gitlab -> Terraform
Read environment variables in terraform variables, add
=> env / exported "
TF_VAR_
in front of the variable name,=> env / exported "
TF_VAR_toto" => variable.tf variable toto
terraform -> gitlab/script/etc. VARIABLE (in project settings)
src https://www.reddit.com/r/Terraform/comments/mwmq4e/comment/gvjo7g3/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
For example : create an EKS cluster & then create a variable with the KUBECONFIG data in another project which has the code for the apps & trigger the deployment of those apps into newly created cluster using that variable.
- terragrunt run-all apply --terragrunt-non-interactive -auto-approve tfplan-$CI_COMMIT_SHA
- terraform output kubectl_config > kubectl_config
- |
curl -s -XPUT -H "PRIVATE-TOKEN: $GITLAB_API_RW_PRIVATE_TOKEN" $CI_API_V4_URL/groups/$GROUP_ID/variables/KUBECONFIG \
--form "value=$(cat kubectl_config)" \
--form "variable_type=file" \
--form "protected=false" \
--form "masked=false" \
--form "environment_scope=*"