我遇到了一个问题,即 Terraform 尝试更改由 DeployIfNotExists 策略部署的资源。此策略会自动为私有端点 (source) 创建一个 DNS 条目。通常,我会使用 ignore_changes
,但这仅适用于首先由 Terraform 部署的资源,然后忽略 Terraform 之外的所有未来更改。
如何在没有 private_dns_zone_group
的情况下部署私有端点,以防止任何未来的部署删除由 Azure 策略部署的 private_dns_zone_group
?
resource "azurerm_private_endpoint" "private_endpoint" {
name = var.private_endpoint_name
location = var.location
resource_group_name = var.resource_group_name
subnet_id = var.private_subnet_id
private_service_connection {
name = var.private_service_connection_name
is_manual_connection = false
private_connection_resource_id = azurerm_app_service.app_service.id
subresource_names = ["sites"]
}
# This cannot be included, otherwise the DeployIfNotExists policy will not run
# private_dns_zone_group {
# name = "deployedByPolicy"
# private_dns_zone_ids = []
# }
lifecycle {
ignore_changes = [
private_dns_zone_group
]
}
}