jason-johnson / azure-pipelines-tasks-terraform

Azure Pipelines extension for Terraform
MIT License
124 stars 52 forks source link

Set values for multiple variables when applying #266

Closed timcrall closed 1 year ago

timcrall commented 2 years ago

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

jason-johnson commented 2 years ago

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

timcrall commented 2 years ago

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

jason-johnson commented 2 years ago

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 commented 1 year ago

Not an issue with terraformCli