azurerm_lb 此处不期望 Terraform 错误参数命名
Terraform error argument named is not expected here for azurerm_lb
我在 运行 下面的代码中,得到的参数不是预期的,但参数在 terraform 文档中。请指教。
variables.tf 文件
type = list(object(
{
lb_name = string
sku = string
location = string
lb_resource_group_name = string
vnet_name = string
vnet_resource_group_name = string
subnet_name = string
frontend_ip_config = list(object({
frontend_ip_name = string
private_ip_address = string
}))
}
))
description = "lb creation"
}
main.tf
resource "azurerm_lb" "lb" {
for_each = { for lb in var.load_balancer : lb.lb_name => lb }
name = each.value.lb_name
sku = each.value.sku
location = each.value.location
resource_group_name = each.value.lb_resource_group_name
dynamic "frontend_ip_configuration" {
for_each = { for fip in each.value.frontend_ip_config : fip.frontend_ip_name => fip }
name = frontend_ip_configuration.value.frontend_ip_name
subnet_id = data.azurerm_subnet.subnet[each.value.lb_name].id
private_ip_address = frontend_ip_configuration.value.private_ip_address
private_ip_address_allocation = frontend_ip_configuration.value.private_ip_address == null ? "Dynamic" : "Static"
}
}
错误
"msg": "Failed to validate Terraform configuration files:\r\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 17, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 17: \u001b[4mname\u001b[0m = frontend_ip_configuration.value.frontend_ip_name\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"name\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 18, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 18: \u001b[4msubnet_id\u001b[0m = data.azurerm_subnet.subnet[each.value.lb_name].id \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"subnet_id\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 19, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 19: \u001b[4mprivate_ip_address\u001b[0m = frontend_ip_configuration.value.private_ip_address\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"private_ip_address\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 20, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 20: \u001b[4mprivate_ip_address_allocation\u001b[0m = frontend_ip_configuration.value.private_ip_address == null ? \"Dynamic\" : \"Static\"\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"private_ip_address_allocation\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n",
提供商版本:
版本 =“2.98.0”
terraform 版本:“~> 1.1.7”
您忘记了 content
。应该是:
dynamic "frontend_ip_configuration" {
for_each = { for fip in each.value.frontend_ip_config : fip.frontend_ip_name => fip }
content {
name = frontend_ip_configuration.value.frontend_ip_name
subnet_id = data.azurerm_subnet.subnet[frontend_ip_configuration.value.lb_name].id
private_ip_address = frontend_ip_configuration.value.private_ip_address
private_ip_address_allocation = frontend_ip_configuration.value.private_ip_address == null ? "Dynamic" : "Static"
}
}
我在 运行 下面的代码中,得到的参数不是预期的,但参数在 terraform 文档中。请指教。 variables.tf 文件
type = list(object(
{
lb_name = string
sku = string
location = string
lb_resource_group_name = string
vnet_name = string
vnet_resource_group_name = string
subnet_name = string
frontend_ip_config = list(object({
frontend_ip_name = string
private_ip_address = string
}))
}
))
description = "lb creation"
}
main.tf
resource "azurerm_lb" "lb" {
for_each = { for lb in var.load_balancer : lb.lb_name => lb }
name = each.value.lb_name
sku = each.value.sku
location = each.value.location
resource_group_name = each.value.lb_resource_group_name
dynamic "frontend_ip_configuration" {
for_each = { for fip in each.value.frontend_ip_config : fip.frontend_ip_name => fip }
name = frontend_ip_configuration.value.frontend_ip_name
subnet_id = data.azurerm_subnet.subnet[each.value.lb_name].id
private_ip_address = frontend_ip_configuration.value.private_ip_address
private_ip_address_allocation = frontend_ip_configuration.value.private_ip_address == null ? "Dynamic" : "Static"
}
}
错误
"msg": "Failed to validate Terraform configuration files:\r\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 17, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 17: \u001b[4mname\u001b[0m = frontend_ip_configuration.value.frontend_ip_name\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"name\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 18, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 18: \u001b[4msubnet_id\u001b[0m = data.azurerm_subnet.subnet[each.value.lb_name].id \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"subnet_id\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 19, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 19: \u001b[4mprivate_ip_address\u001b[0m = frontend_ip_configuration.value.private_ip_address\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"private_ip_address\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n\u001b[31m╷\u001b[0m\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[1m\u001b[31mError: \u001b[0m\u001b[0m\u001b[1mUnsupported argument\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\u001b[0m on private-link-module/private-link-service.tf line 20, in resource \"azurerm_lb\" \"lb\":\n\u001b[31m│\u001b[0m \u001b[0m 20: \u001b[4mprivate_ip_address_allocation\u001b[0m = frontend_ip_configuration.value.private_ip_address == null ? \"Dynamic\" : \"Static\"\u001b[0m\n\u001b[31m│\u001b[0m \u001b[0m\n\u001b[31m│\u001b[0m \u001b[0mAn argument named \"private_ip_address_allocation\" is not expected here.\n\u001b[31m╵\u001b[0m\u001b[0m\n",
提供商版本: 版本 =“2.98.0”
terraform 版本:“~> 1.1.7”
您忘记了 content
。应该是:
dynamic "frontend_ip_configuration" {
for_each = { for fip in each.value.frontend_ip_config : fip.frontend_ip_name => fip }
content {
name = frontend_ip_configuration.value.frontend_ip_name
subnet_id = data.azurerm_subnet.subnet[frontend_ip_configuration.value.lb_name].id
private_ip_address = frontend_ip_configuration.value.private_ip_address
private_ip_address_allocation = frontend_ip_configuration.value.private_ip_address == null ? "Dynamic" : "Static"
}
}