我在 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/