【发布时间】:2021-11-16 15:23:16
【问题描述】:
到目前为止,在前面主题的帮助下,我能够使用以下代码部署具有 IP 限制的应用服务:
变量
locals {
ip_address_list2 = [ {
ip_add : "20.20.20.3/32",
subnet_id = null,
service_tag = null,
prior : "140",
name = "test1"
},
{
ip_add : "10.10.10.2/32",
subnet_id = null,
service_tag = null,
prior : "141",
name = "test2"
},
{
ip_add : "0.0.0.0/0",
subnet_id = null,
service_tag = "AppService"
prior : "142",
name = "Service_Tag"
}]}
应用服务:
site_config {
dynamic "ip_restriction" {
for_each = local.ip_address_list2
content {
ip_address = ip_restriction.value["ip_add"]
action = "Allow"
priority = ip_restriction.value["prior"]
virtual_network_subnet_id = ip_restriction.value["subnet_id"]
service_tag = ip_restriction.value["service_tag"]
name = ip_restriction.value["name"]
}}}
但如果我为子网添加以下变量,我会收到错误:
{
ip_add : "0.0.0.0/0",
subnet_id = azurerm_subnet.subnet.id,
service_tag = null
prior : "143",
name = "VirtualNetwork"
}
错误:创建应用服务“hook-service”(资源组 “RG-DEV-TEST”):web.AppsClient#CreateOrUpdate:发送失败 请求:StatusCode=0 -- 原始错误:Code="BadRequest" Message="IpSecurityRestriction 无效。只有 IpAddress 或 必须指定 VnetSubnetResourceId 属性。” Details=[{"Message":"IpSecurityRestriction 无效。只有 IpAddress 或 VnetSubnetResourceId 属性必须是 指定。"},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"51021","Message":"IpSecurityRestriction 是无效的。只有 IpAddress 或 VnetSubnetResourceId 属性必须是 指定。","MessageTemplate":"{0} 无效。 {1}","Parameters":["IpSecurityRestriction","仅 IpAddress 或 必须指定 VnetSubnetResourceId 属性。"]}}] │ │ 与 azurerm_app_service.hook-service,│在 main.tf 第 474 行,在资源中 “azurerm_app_service” “hook-service”:│ 474:资源 “azurerm_app_service” “钩子服务” {
注意:仅使用 terraform plan 即可完成验证而不会出错。只有在 terraform apply
之后才会观察到错误谢谢
【问题讨论】:
-
您好@Igor,根据错误消息,它清楚地表明您可以使用 ip_address 或虚拟网络,同时设置 ip_restrictions 不能同时使用。所以如果你添加 ip_address 那么 vnet,subnet 将默认为空,如果提供了虚拟网络,则 ip_address 将变为空。
-
感谢您回复我的问题。我怎样才能避免或结合这种配置?我知道它只在门户上点击几下就可以创建这个 ip_restriction 但我想让它自动创建
标签: azure-web-app-service terraform-provider-azure azure-rm