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

howto: find nat gateway for a given subnet? #1665

Closed
hashibot opened this issue Sep 15, 2017 · 2 comments
Closed

howto: find nat gateway for a given subnet? #1665

hashibot opened this issue Sep 15, 2017 · 2 comments
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@hashibot
Copy link

This issue was originally opened by @larsrnielsen as hashicorp/terraform#14888. It was migrated here as a result of the provider split. The original body of the issue is below.


Hi,

I am creating subnets and nat gateways with EIPs as per defined by list variables. But how do I find the aws_nat_gateway for a given subnet? I couldn't find a data provider for it and the one for subnet didn't provide an access to this information.

Lars

resource "aws_nat_gateway" "nat" {
  allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
  subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
  count = "${var.nat_gateway_count}"
  depends_on = [
    "aws_internet_gateway.igw"]
}

resource "aws_route" "private_nat_route" {
  route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
  count = "${(var.nat_gateway_count > 0 ? 1 : 0) * length(compact(split(",", var.private_subnets)))}"
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id = "?????"
}
@hashibot hashibot added the question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. label Sep 15, 2017
@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 28, 2018
@ewbankkit
Copy link
Contributor

aws_nat_gateway data source added via #1294 has a filter on subnet_id.

@bflad bflad closed this as completed Jul 2, 2018
@ghost
Copy link

ghost commented Apr 4, 2020

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 and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

4 participants