fascynacja
fascynacja

Reputation: 2816

How to read output_content from azurerm_resource_group_template_deployment

I have defined an azurerm_resource_group_template_deployment my_rm which has ARM template source:

{
  ...
  "parameters": {...  }, 
  "resources": [ ...  ],
  "outputs": {
    "db_name": {
      "type": "string",
      "value": "test_value"
    } 
  }
}

I would like to use this output in terraform, like:

output "db_name" {
  value = azurerm_resource_group_template_deployment.my_rm.output_content["db_name"]
}

Unfortunately above definition returns empty value.

What is the correct way to define the output in terraform?

Upvotes: 3

Views: 1462

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28204

The output_content exports the JSON Content of the Outputs of the ARM Template Deployment.

After my validation, you could output the content with

output "db_name" {
  value = azurerm_resource_group_template_deployment.my_rm.output_content
}

Then run terraform apply, you will see the output result, then you can change to filter the result with

output "db_name" {
  value = jsondecode(azurerm_resource_group_template_deployment.my_rm.output_content).db_name.value
}

Please note that the db_name is not the same declaration db_name in your terraform code, it really should match the output JSON key in the first above step.

For example,

enter image description here

Upvotes: 4

Related Questions