azure-pipelines-tasks-terraform
azure-pipelines-tasks-terraform copied to clipboard
Set values for multiple variables when applying
With the 'apply' task, is there a way to set values for multiple variables without just using one very long comandOptions line?
Could you expand on what you mean? Are you talking about terraform variables?
sorry, it's been a while, but yes, I believe I was looking for a way to set multiple terraform variables.
I know you can do something like:
commandOptions: --var="foo=bar" --var="ipsum=lorem" --var="anothervar=anothervalue"
but I was looking at a scenario where I was wanting to set dozens of variables to values obtained from pipeline variables/parameters, and it was going to make for an unwieldy commandOptions string so I was hoping for something like a repeatable variables option:
tfvar: foo=bar
tfvar: ipsum=lorem
tfvar: anothervar=anothervalue
or something like that
Have you read from here down? Terraform supports various ways of setting these variables.
The simplest case would be to create a tfvar file which contains all these values and then you need only us something like -var-file="myvars.tfvars"
. You could use a substitution task to fill in the values of these variables before the terraform task runs.
What we actually do in my company is set all the variables in a variable group in Azure Devops. The variables need to have a name like "TF_VAR_foo". Then in your azure devops yaml pipeline you can reference the variable group with the job that contains the terraform tasks. This will inject them into the environment that terraform runs in so they don't need to be specified by anything else.
Not an issue with terraformCli