azurerm_resource_group_template_deployment ignoring parameter file

和自甴很熟 提交于 2021-01-01 17:51:16

问题


I am attempting to use terraform and embedded ARM templates to permit creating a simple logic app in Azure. I have the resource block in terraform as:

resource "azurerm_resource_group_template_deployment" "templateTEST" {
  name                = "arm-Deployment"
  resource_group_name = azurerm_resource_group.rg.name
  deployment_mode     = "Incremental" 
  template_content    = file("${path.module}/arm/createLogicAppsTEST.json")
  parameters_content = jsonencode({ 
    logic_app_name = { value = "logic-${var.prefix}" }
  })

}

and the createLogicAppsTEST.json file is defined (just the top few lines as)

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logic_app_name": {
            "defaultValue": "tsa-logic-dgtlbi-stage-001",
            "type": "string"
        }
    },
    "variables": {},
    "resources": [
        {
....

When deploying and running the first time, ie. creating the logic app resource using terraform and the embedded ARM template, it will create passing the name correctly given the:

  parameters_content = jsonencode({ 
    logic_app_name = { value = "logic-${var.prefix}" }
  })

however, if I ever run again, terraform appears to ignore the parameters I am passing and goes with the default from the ARM template as:

    "logic_app_name": {
        "defaultValue": "tsa-logic-dgtlbi-stage-001",
        "type": "string"
    }

I have updated to the latest version of both terraform (0.14.2) and azurerm (2.40.0), yet the issue persists. At present, this kind of makes ARM in terraform problematic given different tiers, dev, test and prod at my company have different prefixes and names ie. prod-, dev-.

Is there a setting to make terraform actually use the parameters I am passing with azurerm_resource_group_template_deployment resource block?


回答1:


After my validation, you could use the ignore_changes field in the nested block lifecycle. It will tell terraform ignore when planning updates to the associated remote object.

For example,

resource "azurerm_resource_group_template_deployment" "templateTEST" {
  name                = "arm-Deployment"
  resource_group_name = azurerm_resource_group.rg.name
  deployment_mode     = "Incremental" 
  template_content    = file("${path.module}/arm/createLogicAppsTEST.json")
  parameters_content = jsonencode({ 
    logic_app_name = { value = "logic-${var.prefix}" }
  })

   lifecycle {
        
        ignore_changes = [template_content,]
    }

}

However, in this case, it would be better to declare empty parameters without default values in the embedded ARM templates instead you can pass the real parameters via the parameters_content.

For example, declare the parameter like this in the ARM template. This will always use the content of the external parameters.

"logic_app_name": {
    "type": "string"
}



回答2:


I elected to just use the old provider, there is actually an open bug report about this same issue on github



来源:https://stackoverflow.com/questions/65257838/azurerm-resource-group-template-deployment-ignoring-parameter-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!