Fabian
Fabian

Reputation: 785

How to maintain hundred different Terraform configs?

we created a Terraform template which we will deploy in future many dozen times in different workspaces. Each workspace will have a separate configuration file.

Now we would like to automate this procedure and think about keeping the configuration files in a Git Repo.

Has anyone a best practise how to store the configuration files in a Git Repo and trigger a CICD workflow (Azure DevOps)?

In general we only would like to apply changes for workspaces that have a changed configuration.

Upvotes: 0

Views: 101

Answers (1)

Jamie
Jamie

Reputation: 3372

The terraform plan and apply command have an option for you to pass in the tfvars file you want to use. So something like this:

terraform apply --var-file=workspace.tfvars

So in the pipeline you would grab your terrafom template artifacts and your config files. I would then set a TF_WORKSPACE variable to force your workspace and I would also make your tfvars files match the workspace name so you can re use the variable in your apply command. This would force your workspace and configuration file to match.

To trigger this when those files have changed would require a path trigger that would trigger on those changes.

I don't see any harm in running the Terraform every time regardless if changes occur. The worse possible outcome would be that someone made a change that isn't in Terraform and it gets undone.

Upvotes: 1

Related Questions