如何忽略块中属性的更改

时间:2019-07-11 14:53:38

标签: terraform terraform-provider-azure terraform0.12+

我正在Azure中部署Web应用程序,但我想忽略对 site_config 块中的 scm_type 属性的更改。

在部署过程中,将 scm_type 属性设置为 None ,稍后我们将其更改为Azure Portal中的其他内容。

我当前的TF代码如下:

resource "azurerm_app_service" "web_app" {
  count               = length(var.app_names)
  name                = var.app_names[count.index]
  location            = data.azurerm_resource_group.app_resource_group.location
  resource_group_name = data.azurerm_resource_group.app_resource_group.name
  app_service_plan_id = azurerm_app_service_plan.app_plan.id
  tags                = var.tags
  app_settings        = var.app_settings[count.index]

  site_config {
    always_on                 = true
    websockets_enabled        = var.websockets_enabled[count.index]
    use_32_bit_worker_process = var.use_32_bit_worker_process
    scm_type                  = "None"
  }

  lifecycle {
    ignore_changes = [
      site_config.0.scm_type
    ]
  }
}

我希望terraform计划在基础架构更新期间忽略 scm_type 中的更改,但是它正在尝试将其恢复为 None 地形计划输出中的行:

~ scm_type = "BitbucketGit" -> "None"

2 个答案:

答案 0 :(得分:1)

这是一个地形错误:https://github.com/hashicorp/terraform/issues/21433 我的语法是正确的,在0.12.4版中它又可以正常工作。

答案 1 :(得分:0)

我认为您需要在忽略更改中修复语法。看起来应该是这样,或者至少是从我已经能够上班的情况来看。

lifecycle {
    ignore_changes = [
        site_config["scm_type"],
    ]
}

这是具有语法的文档。

https://www.terraform.io/docs/configuration/resources.html#lifecycle-lifecycle-customizations