I am running below code , getting argument not expected here ,but the arguments are there in the terraform document . Please advise. variables.tf file
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"
}
}
Error
"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",
Provider version: version = "2.98.0"
terraform version : "~> 1.1.7"
CodePudding user response:
You forgot about content
. it should be:
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"
}
}