-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding additional VPC into account breaking with: Call to function "element" failed: cannot use element function with an empty list. #734
Comments
Could you also include |
@antonbabenko thanks for the reply. Sure, the terraform plan is below. I also included it above though. Looks like the root problem is:
|
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1090, in resource "aws_nat_gateway" "this":
│ 1090: subnet_id = element(
│ 1091: aws_subnet.public.*.id,
│ 1092: var.single_nat_gateway ? 0 : count.index,
│ 1093: )
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 1
│ │ var.single_nat_gateway is false
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1090, in resource "aws_nat_gateway" "this":
│ 1090: subnet_id = element(
│ 1091: aws_subnet.public.*.id,
│ 1092: var.single_nat_gateway ? 0 : count.index,
│ 1093: )
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 2
│ │ var.single_nat_gateway is false
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1090, in resource "aws_nat_gateway" "this":
│ 1090: subnet_id = element(
│ 1091: aws_subnet.public.*.id,
│ 1092: var.single_nat_gateway ? 0 : count.index,
│ 1093: )
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 3
│ │ var.single_nat_gateway is false
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1090, in resource "aws_nat_gateway" "this":
│ 1090: subnet_id = element(
│ 1091: aws_subnet.public.*.id,
│ 1092: var.single_nat_gateway ? 0 : count.index,
│ 1093: )
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 0
│ │ var.single_nat_gateway is false
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1207, in resource "aws_route_table_association" "public":
│ 1207: subnet_id = element(aws_subnet.public.*.id, count.index)
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 2
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1207, in resource "aws_route_table_association" "public":
│ 1207: subnet_id = element(aws_subnet.public.*.id, count.index)
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 0
│
│ Call to function "element" failed: cannot use element function with an empty list.
╵
╷
│ Error: Error in function call
│
│ on .terraform/modules/vpc_nat/main.tf line 1207, in resource "aws_route_table_association" "public":
│ 1207: subnet_id = element(aws_subnet.public.*.id, count.index)
│ ├────────────────
│ │ aws_subnet.public is empty tuple
│ │ count.index is 1
│
│ Call to function "element" failed: cannot use element function with an empty list. |
@antonbabenko do you need anything else? Is creating multiple VPCs in the same terraform project supported? This seems like a potential bug. |
Yes, this looks like a bug related to incorrect tracking of |
Any news on this? At the moment the only working configuration when creating multiple VPCs in the same project seems to be the default one:
|
Please disregard my previous comment, the error in question springs up only when the subnet list is empty. |
It fails not because of a new VPC being added. You provided more availability zones then public subnets. https://github.com/terraform-aws-modules/terraform-aws-vpc#one-nat-gateway-per-availability-zone
|
may need to assign |
Hey did you get a fix ? Even i have faced a similar error . I am trying to create two vpcs . |
This problem occurs because (!var.one_nat_gateway_per_az || local.len_public_subnets >= length(var.azs)) Because it is Since the value of
This can be solved in one of two ways above. |
Description
Hello. I had a previous VPC defined using:
Trying to create a new VPC alongside the existing VPC using the following:
But it is erroring inside of the this module with:
Versions
v1.0.4
3.2.0
Reproduction
Steps to reproduce the behavior:
Not using workspaces. I tried
rm -rf .terraform && terraform init && terraform plan
but the error is consistent.Code Snippet to Reproduce
The text was updated successfully, but these errors were encountered: