'Terraform: Module's output variable to azure-pipelines.yml file

I am using Terraform Modules for storage account and once storage account is created I want to use output variable for the access key

 output "storage_account_primary_access_key" {
  value = data.azurerm_storage_account.storage.primary_access_key
}

Further in my azure-pipelines.yml, I am using "az command" as below

 az storage blob upload-batch -s drop -d \$web --account-name "" --account-key ""

How can I use Module's output variable in the YML file?



Solution 1:[1]

You can use the output command. For example:

terraform output storage_account_primary_access_key

So you may do something like this:

az storage blob upload-batch -s drop -d $web \
 --account-name "" \
 --account-key "$(terraform output -raw storage_account_primary_access_key)"

You could also assign it to variable, that you can use throughout your popeline. Something along these lines.

- script: echo "##vso[task.setvariable variable=ACCESS_KEY]$(terraform output -raw storage_account_primary_access_key)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1