Search code examples
azure-devopsterraformdevopsterraform-provider-azure

Terraform list as input variable in Azure DevOps


I am trying to pass list as variable to Azure DevOps release pipeline.

My variable declaration:

variable "allowed_audiences" {
  description = "Allowed audiences"
  type = list(string)
  default = ["xyz", "abc"]
}

Then, in azure devops i am trying to pass value that i am storing in variable group:

["\"test\""]

In task, i am passing that variable like that:

-var="allowed_audiences=$(allowed_audience)" -var="environment=$(Release.EnvironmentName)"

But it still failes whatever i tried.

2023-02-06T08:48:17.5412282Z [31m│[0m [0m[1m[31mError: [0m[0m[1mInvalid character[0m
2023-02-06T08:48:17.5412838Z [31m│[0m [0m
2023-02-06T08:48:17.5413184Z [31m│[0m [0m[0m  on <value for var.allowed_audiences> line 1:
2023-02-06T08:48:17.5413540Z [31m│[0m [0m  (source code not available)
2023-02-06T08:48:17.5413823Z [31m│[0m [0m
2023-02-06T08:48:17.5414269Z [31m│[0m [0mThis character is not used within the language.
2023-02-06T08:48:17.5414588Z [31m╵[0m[0m
2023-02-06T08:48:17.5414821Z [31m╷[0m[0m
2023-02-06T08:48:17.5415132Z [31m│[0m [0m[1m[31mError: [0m[0m[1mInvalid expression[0m
2023-02-06T08:48:17.5415438Z [31m│[0m [0m
2023-02-06T08:48:17.5415998Z [31m│[0m [0m[0m  on <value for var.allowed_audiences> line 1:
2023-02-06T08:48:17.5416559Z [31m│[0m [0m  (source code not available)
2023-02-06T08:48:17.5416989Z [31m│[0m [0m
2023-02-06T08:48:17.5417537Z [31m│[0m [0mExpected the start of an expression, but found an invalid expression token.
2023-02-06T08:48:17.5418082Z [31m╵[0m[0m

My question is, how to pass list of string as variable during Azure Devops release pipeline?

EDIT:

When i try this form:

-var='allowed_audiences=["\"$(allowed_audience)\""]' -var="environment=$(Release.EnvironmentName)"

I get this error:

2023-02-06T09:28:13.7759253Z [31m╷[0m[0m
2023-02-06T09:28:13.7760165Z [31m│[0m [0m[1m[31mError: [0m[0m[1mValue for undeclared variable[0m
2023-02-06T09:28:13.7760795Z [31m│[0m [0m
2023-02-06T09:28:13.7761315Z [31m│[0m [0m[0mA variable named "'allowed_audiences" was assigned on the command line, but
2023-02-06T09:28:13.7761949Z [31m│[0m [0mthe root module does not declare a variable of that name. To use this
2023-02-06T09:28:13.7762528Z [31m│[0m [0mvalue, add a "variable" block to the configuration.
2023-02-06T09:28:13.7762964Z [31m╵[0m[0m

Solution

  • I managed to do that. YOu need to delete quotes from var area and everything should be fine

    -var=allowed_audiences=["\"$(allowed_audience)\""] -var="environment=$(Release.EnvironmentName)"