Gva*_*ana 4 ip-restrictions terraform azure-web-app-service
我正在尝试在我的 Azure 应用服务应用程序中设置 IP 限制块
执行 Terraform 计划或应用时,我收到以下错误: 错误:azurerm_app_service.app-service-1:: 无效或未知密钥:ip_restriction
我根据应用服务(Web 应用程序)资源的 Terraform 文档使用了ip_restriction
这是我正在使用的 AppService 部署代码:
resource "azurerm_app_service" "app-service-1" {
name = "${var.app_service_1}"
location = "${data.azurerm_resource_group.core-rg.location}"
resource_group_name = "${data.azurerm_resource_group.core-rg.name}"
app_service_plan_id = "${data.azurerm_app_service_plan.app-service-plan-1.id}"
https_only = "True"
enabled = "True"
client_affinity_enabled = "True"
site_config {
always_on = "True"
#default_documents = ""
dotnet_framework_version = "v4.0"
#http2_enabled = ""
#ip_restriction = ""
#java_version = ""
#java_container = ""
#java_container_version = ""
managed_pipeline_mode = "Integrated"
min_tls_version = "1.2"
#php_version = ""
#python_version = ""
remote_debugging_enabled = "False"
#remote_debugging_version = ""
scm_type = "None"
use_32_bit_worker_process = "False"
websockets_enabled = "True"
#ftps_state = ""
}
app_settings {
"KeyVaultURI" = ""
"WEBSITE_NODE_DEFAULT_VERSION" = "6.9.1"
}
ip_restriction {
"ip_address" = ""
}
Run Code Online (Sandbox Code Playgroud)
谢谢
对于那些感兴趣的人,这里是在 Terraform 中使用 ipRestrictions 的方法
ip 限制是 Site_Config {} 的一部分
使用方法见下:
应用服务.tf:
resource "azurerm_app_service" "app-service-1" {
name = "${var.app_service_1}"
location = "${data.azurerm_resource_group.core-rg.location}"
resource_group_name = "${data.azurerm_resource_group.core-rg.name}"
app_service_plan_id = "${data.azurerm_app_service_plan.app-service-plan-1.id}"
https_only = "True"
enabled = "True"
client_affinity_enabled = "True"
site_config {
always_on = "True"
#default_documents = ""
dotnet_framework_version = "v4.0"
#http2_enabled = ""
#ip_restriction = ""
#java_version = ""
#java_container = ""
#java_container_version = ""
managed_pipeline_mode = "Integrated"
min_tls_version = "1.2"
#php_version = ""
#python_version = ""
remote_debugging_enabled = "False"
#remote_debugging_version = ""
scm_type = "None"
use_32_bit_worker_process = "False"
websockets_enabled = "True"
#ftps_state = ""
ip_restriction {
ip_address = "${var.ip_address_1}"
}
ip_restriction {
ip_address = "${var.ip_address_2}"
}
ip_restriction {
ip_address = "${var.ip_address_3}"
}
}
app_settings {
"KeyVaultURI" = ""
"WEBSITE_NODE_DEFAULT_VERSION" = "6.9.1"
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,@jamies 的答案是不正确的 IP_restriction 不是一个包含一个或多个的列表,而是一个可重复的块。
@gvazzana 是正确的格式。但是,有一个陷阱.. 会导致您看到的错误。
在 Tf 中,我们习惯于以完整的 CIDR 格式输入 IP 地址,例如 10.23.97.201/23 或 192.68.50.0/24,本节的 azure 门户甚至会像这样显示它们。
但是对于这个特殊的街区,在 terraform 中,你必须把它们做旧学校。例如:
site_config {
# For a single IP address
ip_restriction {
ip_address = "81.145.174.78"
}
ip_restriction {
# For an address range
ip_address = "10.240.101.0"
subnet_mask = "255.255.255.0"
}
}
Run Code Online (Sandbox Code Playgroud)
如果您有很长的地址和范围列表,这当然会很痛苦。
现在 terraform 版本 0.12.0 已经发布,我们应该能够利用新的dynamic块样式cidrhost和cidrmask功能来简化事情。
例如:
dynamic "ip_restriction" {
for_each = var.ip_address_list
content {
ip_address = cidrhost(ip_restriction.value,0)
subnet_mask = cidrmask(ip_restriction.value)
}
}
Run Code Online (Sandbox Code Playgroud)
使用 Terraform v0.12.13 测试
| 归档时间: |
|
| 查看次数: |
5722 次 |
| 最近记录: |