使用Terraform创建Azure Verizon CDN端点时如何禁用缓存?
在Terraform中配置Verizon CDN端点禁用缓存
针对Standard_Verizon SKU的Azure CDN端点,确实无法通过global_delivery_rule或delivery_rule块直接配置缓存规则——这些资源仅适用于Microsoft或Akamai SKU。不过你完全可以在Terraform中完成禁用缓存的配置,无需依赖后续GUI操作,具体有两种可行方案:
方法1:通过cache_behavior块全局禁用缓存
如果需要对所有路径禁用缓存,可以在azurerm_cdn_endpoint资源中定义cache_behavior块,设置cache_duration为0,这会强制CDN不缓存任何内容,和GUI中设置“缓存持续时间0秒”的效果完全一致:
resource "azurerm_cdn_endpoint" "verizon_cdn" { name = "example-verizon-cdn" profile_name = azurerm_cdn_profile.verizon_profile.name resource_group_name = azurerm_resource_group.example.name location = "Global" origin { name = "example-origin" host_name = "example.azurewebsites.net" } # 全局禁用缓存的行为配置 cache_behavior { path_pattern = "/*" cache_duration = "0" cache_query_string_behavior = "IgnoreQueryString" dynamic_compression_enabled = true } }
如果只需要对特定路径禁用缓存,修改path_pattern为目标路径即可(比如/api/*)。
方法2:导入已配置的GUI规则到Terraform
如果你已经在GUI中完成了禁用缓存的配置,可以通过Terraform的导入功能将现有端点纳入代码管理:
- 执行导入命令(替换占位符为你的资源信息):
terraform import azurerm_cdn_endpoint.verizon_cdn /subscriptions/<你的订阅ID>/resourceGroups/<资源组名称>/providers/Microsoft.Cdn/profiles/<CDN配置文件名称>/endpoints/<端点名称>
- 运行
terraform show查看导出的完整配置,提取其中缓存相关的参数,整合到你的Terraform代码中。
需要注意的是,Verizon SKU的部分高级缓存策略可能仍需通过Azure Portal或Verizon专属管理界面调整,但基础的禁用缓存需求完全可以通过上述Terraform配置实现。
内容的提问来源于stack exchange,提问作者user098213
相关产品推荐
相关产品推荐

