Radhika
Radhika

Reputation: 27

How to define variables in YAML to get the value from variable group in Azure DevOps

I have setup a map(string) variable in terraform. and defined them in Azure YAML pipeline. i want to get the value for those YAML variable from variable group in Azure DevOps. if i give the direct value for the key, it works as expected. but when trying to access the value from variable groups i receive errors.

Defined Variable in Terraform:

Variables.tf
variable "secrets" {
  type = map(string)
}

variables.tfvars
secrets  = $(secrets)

in YAML pipeline:

displayName: DEV
    variables: 
      - group: 'Environment - Dev' 
      - name: secrets
        value:  '{"testAPIKey1" = $(testAPIKey1) , "testAPIKey2" = $(testAPIKey2) }'

I was getting the error like below


Expected a closing parenthesis to terminate the expression. ##\[error\]Terraform command 'plan' failed with exit code '1'.: Unbalanced parentheses

\##\[error\]

Error: Unbalanced parentheses

Can some one suggest please how i can access the values from variable groups to YAML variables.

Upvotes: 0

Views: 746

Answers (1)

jessehouwing
jessehouwing

Reputation: 114957

The values of the variable group are not available yet when the 2nd variable is set. The yaml pipelines follow a pretty opaque multi-stage parsing, transformation and execution order.

You can use a script task or my set variable task to set the value of the 2nd variable at runtime in the job.

https://marketplace.visualstudio.com/items?itemName=jessehouwing.jessehouwing-vsts-variable-tasks

See also: https://stackoverflow.com/a/74788506/736079

Upvotes: 1

Related Questions