1

Using terraform and Azure ARM template, in order to configre event grid with a particular azure function, I am trying to recover some values in a terraform output.

Indeed, I have this ARm template deployment to have the systems keys of a particular function:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionApp": {
            "type": "string",
            "defaultValue": ""
        }
    },
    "variables": {
        "functionAppId": "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
    },
    "resources": [],
    "outputs": {
        "systemKeys": {
            "type": "object",
            "value": "[listkeys(concat(variables('functionAppId'), '/host/default'), '2018-11-01').systemKeys]"
        }
    }
}

My deployment working well, because I can see in Azure Portal that there are in output a json objecy like this:

{
    "durabletask_extension": "ASensituveValueIDoNotShareForDurableTaskExtension==",
    "eventgrid_extension": "ASensituveValueIDoNotShareForEventGridExtension=="
}

Now the purpose is to get one of this value in a terraform output. I tried these but I have got some errors:

output "syst_key" {
    value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}

Error: on outputs.tf line 69, in output "syst_key":   
69:     value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
    |----------------
    | azurerm_template_deployment.function_keys.outputs is empty map of string

output "syst_keys" {
  value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
}

Error:  on outputs.tf line 77, in output "syst_key":   
77:     value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
    |---------------- 
    | azurerm_template_deployment.function_keys.outputs is empty map of string

Call to function "lookup" failed: lookup failed to find 'systemKeys'.

In order to trigger eventgrid on this function I have to recover the values in terraform output of systemKeys from my ARM deployment template. I know that the deployment is working well, I just don't know how to recover theses values with terraform.

french_dev
  • 2,117
  • 10
  • 44
  • 85

1 Answers1

1

For your issue, you need to take care that only the type String, Int and Bool are supported in Terraform. So you need to change the output type in the template, then you can output them in Terraform. For more details, see outputs. And the right output in Terraform is below:

output "syst_key" {
    value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}
Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • You save my life, and indeed it was a rookie mistake. Using this ARM template and terraform I need to set the value type as a string. Now I recover correcty my value. Thank you, you save my day – french_dev Aug 05 '19 at 09:49