Resolved: Encrypt Terraform values in Gitlab

In this post, we will see how to resolve Encrypt Terraform values in Gitlab


I have the following flow:
  1. You work on Terraform code locally
  2. You push the code to Gitlab
  3. Gitlab pipeline automatically run terraform init, terraform plan and terraform apply (manually)

The question is about secrets. I need to place them to Azure KeyVault, thus I have “value” field in Terraform code, which cannot be placed to Gitlab as plain text. If I place secrets to file and decrypt a file using “git-crypt” – it gets to Gitlab encrypted and Terraform sees it as encrypted already and creates an encrypted secret. Any ideas how to do it?
I’m creating the secret via Terraform this way:

Best Answer:

Can you pls provide TF code here. If you fetch keys from keyvault using ‘data’ block, then it should not be placed in plain text format in GitLab. Still would request you to put codes here, so that I can understand better.

If you have better answer, please add a comment about this, thank you!