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

aws_default_route_table doesn't create entry on gateway_id, constantly recreates resource #398

Closed
hashibot opened this issue Jun 13, 2017 · 4 comments · Fixed by #10981
Closed
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @chrisburrus as hashicorp/terraform#10426. It was migrated here as part of the provider split. The original body of the issue is below.


This is an issue with assigning an entry in the aws_default_route_table on a VPC to point to an internet gateway. Surprised I could not find a bug report of it, it's very repeatable, and I was only on like, step 4 of terraforming my deployment.

Terraform Version

v0.7.13

Affected Resource(s)

  • aws_internet_gateway
  • aws_default_route_table

Terraform Configuration Files

resource "aws_vpc" "bosh_vpc" {
  cidr_block = "10.0.0.0/16"

  tags {
    Name = "bosh-default-vpc"
  }
}

resource "aws_internet_gateway" "bosh_default_internet_gateway" {
  vpc_id = "${aws_vpc.bosh_vpc.id}"

  tags {
    Name = "bosh-default-internet-gateway"
  }
}

resource "aws_default_route_table" "bosh_default_route_table" {
  default_route_table_id = "${aws_vpc.bosh_vpc.id}"

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = "${aws_internet_gateway.bosh_default_internet_gateway.id}"
  }

  tags {
    Name = "bosh-default-route-table"
  }
}

resource "aws_default_security_group" "bosh_default_security_group" {
  vpc_id = "${aws_vpc.bosh_vpc.id}"

  tags {
    Name = "bosh-default-security-group"
  }

  ingress {
    from_port = 0
    to_port   = 0
    protocol  = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Debug Output

https://gist.github.com/chrisburrus/2c798c49a73596a68f5611b06529f018

Panic Output

None

Expected Behavior

It should have put an entry in the route table, with destination: 0.0.0.0/0 and target: the internet gateway created. I have another VPC with an identical setup that works with no issues.

Actual Behavior

Not only did it not create the entry in the route table, but REALLY oddly, it just constantly recreates the resource entirely on every single terraform apply. I triple checked that I'm following the documentation right, it should be really simple - yet it constantly thinks the resource doesn't exist. terraform show also does not show the route table at all. Despite the entry and the attempted creation, it just does not exist in the tfstate file at all.

Steps to Reproduce

  1. terraform apply
  2. Observe the lack of entry in tfstate file as well as the route table entry
  3. Feel free to redo terraform apply and watch it chain-create the route table, thinking it doesn't exist each time. Really strange. Destroying and recreating, changing names etc, did not help.

Important Factoids

Very standard AWS account, less than 2 years old so don't think it's a weird EC2 classic issue or anything.

References

Could not find any references to this issue.

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2018
@ewbankkit
Copy link
Contributor

@chrisburrus

resource "aws_default_route_table" "bosh_default_route_table" {
  default_route_table_id = "${aws_vpc.bosh_vpc.id}"

}

should be

resource "aws_default_route_table" "bosh_default_route_table" {
  default_route_table_id = "${aws_vpc.bosh_vpc.default_route_table_id }"

}

You are passing the VPC's ID instead of its default route table ID.
No error is being reported because this code runs - A missing default route table is a valid scenario.

bflad added a commit that referenced this issue Nov 22, 2019
…ehavior when Default Route Table is missing

Reference: #398
Reference: #3551
Reference: #9009

Previously on creation, if the Default Route Table was incorrectly configured or non-existent, the resource would unexpectedly attempt to remove itself from the Terraform state and propose recreation immediately. Prior to Terraform 0.12, this behavior was errantly acceptable. In Terraform 0.12, resources are required to return Terraform state about themselves during creation or throw an error explaining why the creation failed.

Previously on read, if the Default Route Table was missing (e.g. due to the VPC being deleted outside Terraform), the resource would return an error and require operators to manually perform a `terraform state rm` command instead of proposing resource recreation.

Output from new acceptance testing before code updates:

```
--- FAIL: TestAccAWSDefaultRouteTable_basic (20.02s)
    testing.go:628: Step 0, expected error:

        errors during apply: Provider produced inconsistent result after apply: When applying changes to aws_default_route_table.foo, provider "aws" produced an unexpected new value for was present, but now absent.

        This is a bug in the provider, which should be reported in the provider's own issue tracker.

        To match:

        TBD

--- FAIL: TestAccAWSDefaultRouteTable_disappears_Vpc (20.27s)
    testing.go:635: Step 0 error: errors during follow-up refresh:

        Error: Default Route table not found

    testing.go:696: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: errors during refresh: Default Route table not found

        State: <nil>
```

Output from acceptance testing after code updates:

```
--- PASS: TestAccAWSDefaultRouteTable_disappears_Vpc (20.46s)
--- PASS: TestAccAWSDefaultRouteTable_basic (40.99s)
--- PASS: TestAccAWSDefaultRouteTable_vpc_endpoint (49.71s)
--- PASS: TestAccAWSDefaultRouteTable_swap (73.89s)
--- PASS: TestAccAWSDefaultRouteTable_Route (87.09s)
--- PASS: TestAccAWSDefaultRouteTable_Route_TransitGatewayID (374.87s)
```
@bflad bflad added this to the v2.40.0 milestone Nov 25, 2019
bflad added a commit that referenced this issue Nov 25, 2019
…ehavior when Default Route Table is missing (#10981)

Reference: #398
Reference: #3551
Reference: #9009

Previously on creation, if the Default Route Table was incorrectly configured or non-existent, the resource would unexpectedly attempt to remove itself from the Terraform state and propose recreation immediately. Prior to Terraform 0.12, this behavior was errantly acceptable. In Terraform 0.12, resources are required to return Terraform state about themselves during creation or throw an error explaining why the creation failed.

Previously on read, if the Default Route Table was missing (e.g. due to the VPC being deleted outside Terraform), the resource would return an error and require operators to manually perform a `terraform state rm` command instead of proposing resource recreation.

Output from new acceptance testing before code updates:

```
--- FAIL: TestAccAWSDefaultRouteTable_basic (20.02s)
    testing.go:628: Step 0, expected error:

        errors during apply: Provider produced inconsistent result after apply: When applying changes to aws_default_route_table.foo, provider "aws" produced an unexpected new value for was present, but now absent.

        This is a bug in the provider, which should be reported in the provider's own issue tracker.

        To match:

        TBD

--- FAIL: TestAccAWSDefaultRouteTable_disappears_Vpc (20.27s)
    testing.go:635: Step 0 error: errors during follow-up refresh:

        Error: Default Route table not found

    testing.go:696: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: errors during refresh: Default Route table not found

        State: <nil>
```

Output from acceptance testing after code updates:

```
--- PASS: TestAccAWSDefaultRouteTable_disappears_Vpc (20.46s)
--- PASS: TestAccAWSDefaultRouteTable_basic (40.99s)
--- PASS: TestAccAWSDefaultRouteTable_vpc_endpoint (49.71s)
--- PASS: TestAccAWSDefaultRouteTable_swap (73.89s)
--- PASS: TestAccAWSDefaultRouteTable_Route (87.09s)
--- PASS: TestAccAWSDefaultRouteTable_Route_TransitGatewayID (374.87s)
```
@bflad
Copy link
Contributor

bflad commented Nov 25, 2019

The adjustment of the resource to return a more helpful error in this scenario has been merged and will release with version 2.40.0 of the Terraform AWS Provider this week.

@ghost
Copy link

ghost commented Nov 27, 2019

This has been released in version 2.40.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 Mar 29, 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 Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
4 participants