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

Interpolated (count.index) route_table route re-create every run #3269

Closed
zantharax opened this issue Feb 6, 2018 · 2 comments
Closed

Interpolated (count.index) route_table route re-create every run #3269

zantharax opened this issue Feb 6, 2018 · 2 comments

Comments

@zantharax
Copy link

zantharax commented Feb 6, 2018

Hey there, I am seeing an issue while using an interpolated "gateway_id" for a route table route block. The configuration is below, but every time terraform runs a plan, it fails to recognize the existing route block, instead clearing the current route block and re-creating the route with the same information.

Terraform Version

v0.11.2

Affected Resource(s)

  • route_table

Terraform Configuration Files

resource "aws_route_table" "route_table" {
  count = "3"
  vpc_id = "${aws_vpc.default.id}"

  route = {
    cidr_block = "0.0.0.0/0"
    gateway_id = "${element(aws_nat_gateway.natgw.*.id,count.index)}"
  }
}

resource "aws_nat_gateway" "natgw" {
  count = "3"
  allocation_id = "${element(aws_eip.eip.*.id,count.index)}"
  subnet_id = "${element(aws_subnet.subnets.*.id,count.index)}"
}

resource "aws_eip" "eip" {
  count = "3"
  vpc = true
}

resource "aws_subnet" "subnets" {
  count      = "3"
  cidr_block = "10.0.${count.index+200}.0/24"
  vpc_id     = "${aws_vpc.default.id}"

  availability_zone = "${element(data.aws_availability_zones.available.names,count.index)}"

}

data "aws_availability_zones" "available" {
}

Expected Behavior

Terraform plan should have interpreted the interpolated route as identical and not changed the route table and associated routes

Actual Behavior

Terraform clears and re-creates the route with interpolated gateway data.
E.G.

      route.3532503076.cidr_block:                "0.0.0.0/0" => ""
      route.3532503076.egress_only_gateway_id:    "" => ""
      route.3532503076.gateway_id:                "" => ""
      route.3532503076.instance_id:               "" => ""
      route.3532503076.ipv6_cidr_block:           "" => ""
      route.3532503076.nat_gateway_id:            "nat-####" => ""
      route.3532503076.network_interface_id:      "" => ""
      route.3532503076.vpc_peering_connection_id: "" => ""
      route.3761834389.cidr_block:                "" => "0.0.0.0/0"
      route.3761834389.egress_only_gateway_id:    "" => ""
      route.3761834389.gateway_id:                "" => "nat-####"
      route.3761834389.instance_id:               "" => ""
      route.3761834389.ipv6_cidr_block:           "" => ""
      route.3761834389.nat_gateway_id:            "" => ""
      route.3761834389.network_interface_id:      "" => ""
      route.3761834389.vpc_peering_connection_id: "" => ""

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan/apply

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

@zantharax
Copy link
Author

zantharax commented Feb 6, 2018

Figured out the issue - AWS and the provider both allow for NAT gateways to be used in the gateway_id field. However, when aws provisions the resource, it is changed to the nat_gateway field, causing a diff in the state file.

Modifying the config to

resource "aws_route_table" "route_table" {
  count = "3"
  vpc_id = "${aws_vpc.default.id}"

  route = {
    cidr_block = "0.0.0.0/0"
    nat_gateway_id = "${element(aws_nat_gateway.natgw.*.id,count.index)}"
  }
}

Solved the issue

@ghost
Copy link

ghost commented Apr 8, 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 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant