azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

Set values for multiple variables when applying

Open timcrall opened this issue 2 years ago • 3 comments

With the 'apply' task, is there a way to set values for multiple variables without just using one very long comandOptions line?

timcrall avatar Mar 31 '22 21:03 timcrall

Could you expand on what you mean? Are you talking about terraform variables?

jason-johnson avatar Aug 10 '22 20:08 jason-johnson

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

timcrall avatar Aug 10 '22 21:08 timcrall

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.

jason-johnson avatar Aug 11 '22 07:08 jason-johnson

Not an issue with terraformCli

jason-johnson avatar Feb 02 '23 12:02 jason-johnson