azure - Terraform 状态与外部更改同步

标签 azure terraform azure-aks terraform-provider-azure azure-application-gateway

我在 Azure 中使用 terraform 管理我的基础设施。但是,在某些情况下,当其他服务也在更改基础设施时,状态可能会不同步。

例如,我让 terraform 创建一个应用程序网关。但我还有一个启用了 AGIC 的 AKS 集群,它可以动态更新/更改应用程序网关内部的规则、监听器等。因此,如果 terraform 在 AGIC 进行一些更改后重新运行,terraform 不知道并希望重置为它知道的默认配置。

也许这是不可能的,但是有没有一种自动方法来同步两者?每次都必须进入 terraform 配置并手动添加 AGIC 所做的更改,这是不可行的。此时,是否值得使用 terraform 管理应用程序网关?

最佳答案

如果您确实想使用 Terraform 创建应用程序网关,您可能应该使用生命周期元参数 ignore_changes关于将由 AKS 修改的属性。虽然并不完美,但至少他们可以分担责任,而不会互相覆盖。

The ignore_changes feature is intended to be used when a resource is created with references to data that may change in the future, but should not affect said resource after its creation. In some rare cases, settings of a remote object are modified by processes outside of Terraform, which Terraform would then attempt to "fix" on the next run. In order to make Terraform share management responsibilities of a single object with a separate process, the ignore_changes meta-argument specifies resource attributes that Terraform should ignore when planning updates to the associated remote object.

例如:

resource "azurerm_application_gateway" "example" {
  ...

  lifecycle {
    ignore_changes = [
      http_listener,
      request_routing_rule,
      backend_http_settings
    ]
  }

  ...
}

关于azure - Terraform 状态与外部更改同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67426738/

相关文章:

linux - 如何从 Azure Bash for Kubernetes 更改、编辑、保存/etc/hosts 文件?

Azure函数: Deploying to Staging Slot Restarts Production Slot

azure - AppInsights - 监控挂起的进程

azure - 是否有 VSTS 构建任务可以从注册表中删除未使用的 Docker 容器?

terraform - 如何使用 terraform 中的动态键从 Set 中将数据提取为列表

azure - 使用 AKS 上的 api 服务器地址访问集群应用程序

Azure Functions-新-AzContainerGroup : Object reference not set to an instance of an object

terraform - terraforms null_resource 可以使用超时 block 吗?

amazon-web-services - 如何使用 local_file 资源将由 Terraform 中的 tls_private_key 资源创建的 pem 文件保存到磁盘?

kubernetes - 什么是 hcp-tunnelfront?