Skip to content
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

[BUG] aws_route with conditional target to use nat_gateway_id or transit_gateway_id #13079

Closed
Bobonium opened this issue Apr 29, 2020 · 4 comments · Fixed by #16930
Closed

[BUG] aws_route with conditional target to use nat_gateway_id or transit_gateway_id #13079

Bobonium opened this issue Apr 29, 2020 · 4 comments · Fixed by #16930
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@Bobonium
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

0.12.24

Affected Resource(s)

  • aws_route

Terraform Configuration Files

resource "aws_route" "route" {
  count = length(var.private_subnets)

  route_table_id         = element(aws_route_table.private_rts.*.id, count.index)
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = var.enable_nat_gateway ? element(aws_nat_gateway.nat_gateways.*.id, count.index) : null
  transit_gateway_id     = var.enable_nat_gateway ? null : var.tgw_id
}

Expected Behavior

if enable_nat_gateway is true it should create the route for destination 0.0.0.0/0 with the nat_gateway_id. If it is false it should use the supplied tgw_id instead.

Actual Behavior

The plan output correctly shows the intended changes.
Running apply will fail because of

Error: Error: more than 1 target specified. Only 1 of gateway_id, egress_only_gateway_id, nat_gateway_id, instance_id, network_interface_id or vpc_peering_connection_id is

In our case we switched an existing system from enable_nat_gateways = true, to enable_nat_gateways = false. Plan output was correct, but above error happened. We were able to solve the problem by manually changing the route in the UI, the next terraform plan was then empty, because of the refresh.

Steps to Reproduce

  1. terraform apply

Important Factoids

none

References

none

@ghost ghost added the service/ec2 Issues and PRs that pertain to the ec2 service. label Apr 29, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 29, 2020
@ewbankkit
Copy link
Contributor

Verified that the same problem occurs with Terraform 0.11 (and "" instead of null for the missing gateway ID).

@ghost
Copy link

ghost commented Mar 26, 2021

This has been released in version 3.34.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Apr 25, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.