我尝试在我的azure功能上添加我的apim公共ip白名单:
apim.tf
data "azurerm_api_management" "main" {
name = "my-apim"
resource_group_name = "my-rg"
}
output "apim_ip" {
value = data.azurerm_api_management.main.public_ip_addresses
}
起程拓殖输出
apim_ip = tolist([
"1.2.3.4",
])
func.tf
resource "azurerm_linux_function_app" "az_func" {
name = var.my_func_name
resource_group_name = azurerm_resource_group.main.name
location = var.location
storage_account_name = azurerm_storage_account.main.name
storage_account_access_key = azurerm_storage_account.main.primary_access_key
service_plan_id = azurerm_service_plan.azfunc.id
site_config {
dynamic "ip_restriction" {
for_each = data.azurerm_api_management.main.public_ip_addresses
content {
ip_address = data.azurerm_api_management.main.public_ip_address_id.value
}
}
}
}
在terraform apply
上,我一直有错误信息:
不能访问基本类型值(字符串)上的属性。
我做错了什么?
data.azurerm_api_management.main.public_ip_address_id
是一个字符串,因此您不能像访问map
或object
类型那样访问它的值。我相信你想访问从data.azurerm_api_management.main.public_ip_addresses
分配的临时lambda迭代器变量上的值。在这种情况下,用法和语法是:
ip_address = site_config.value.id
从当前的data.azurerm_api_management.main.public_ip_addresses
属性访问id
的值。