Azure Terraform配置ignore_changes避免删除策略部署的private dns zone group
解决方法
你现有的配置思路是正确的,仅需补充provider端的规则即可避免Terraform删除策略创建的private_dns_zone_group资源,具体操作如下:
- 调整azurerm provider的配置,关闭私有端点DNS区域组的默认清理逻辑:
provider "azurerm" { features { private_endpoint { # 禁止Terraform清理未在配置中声明的私有端点DNS区域组 manage_private_dns_zone_group_records = false # 可选:销毁私有端点时不删除关联的DNS区域组 remove_private_dns_zone_group_on_destroy = false } } }
- 保留你原有私有端点资源中的
lifecycle配置即可,不需要做额外调整:
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"] } lifecycle { ignore_changes = [ private_dns_zone_group ] } }
- 配置完成后先执行
terraform plan验证执行计划,确认没有删除private_dns_zone_group的操作后,即可正常执行部署。
注意事项
- 不要在私有端点资源中显式声明
private_dns_zone_group块,否则DeployIfNotExists策略会检测到该资源已存在,不会自动创建DNS条目。 - 如果执行plan时仍出现删除DNS区域组的提示,先执行
terraform refresh同步云端资源状态后再验证即可。
内容的提问来源于stack exchange,提问作者Cloudkollektiv
相关产品推荐
相关产品推荐

