Home > other >  How to download .tfvar files in to ADOagent machine directly before running Terraform plan?
How to download .tfvar files in to ADOagent machine directly before running Terraform plan?

Time:07-09

We are using Terraform Enterprise Cloud and Azure DevOps YML pipelines for Azure infra deployments.

Requirement: We want to separate .tfvar files completely from the main terraform folder and keep them in different Repo called config Repository.

Solution 1: We can refer tfvars from the config repository while running the below command, terraform plan --var-fil -We cannot implement

Note: Since we are using global templates, these terraform commands like fmt, validate, plan, and apply are managed by the template itself, we are not allowed to edit the template.

Here is the logic, template expects only .tfvars file in the current directory, then there are some bash commands to rename it to .auto.tfvars. We know that these auto.tfvars files will be automatically identified by Terraform.

Solution 2: We are expecting and struggling to implement and need some help

By default Template copies all terraform folders to ADO Agent Container. we want to make sure the .tfvar file from the Config repository is available in the agent container. Then this solution will be good.

May be,

We can achieve it by Copying the .tfvars file from the config repository to the agent container by writing some shell script. but it has to be inside the terraform folder. because only terraform folder will be copied to the agent container.

Or is there any way that we can integrate a shell script to terraform configuration which can download tfvars file from config repository to container in run time.

Any other solution or approach will be appreciated.

CodePudding user response:

To make sure the config repo files are available during runtime you can add a second artifact to the release pipeline. This will allow you to modify your var argument with the appropriate file.

https://docs.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops

CodePudding user response:

One approach is to have your tfvars file stored as a secure file, then just add a step in your pipeline to download it, however, if you're using Terraform Enterprise, is there any particular reason to not use Terraform workspace variables?

  • Related