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

Allow import of aws_route_table_association #561

Closed
hashibot opened this issue Jun 13, 2017 · 14 comments
Closed

Allow import of aws_route_table_association #561

hashibot opened this issue Jun 13, 2017 · 14 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@hashibot
Copy link

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


Terraform Version

v0.8.7

Affected Resource(s)

  • aws_route_table_association

Currently if you run terraform import on a aws_route_table_association you'll get an error:

* import module.X.aws_route_table_association.Y (id: rtbassoc-1234f171): resource aws_route_table_association doesn't support import

Allowing route table associations to be imported would be really useful. Right now, I can do it by manually editing the state file but it is an error prone process.

You can get the id of a route table association through

aws ec2 describe-route-tables --route-table-ids rtb-123436a4

They follow the format rtbassoc-XXXXX.

Thanks!

@hashibot hashibot added the enhancement Requests to existing resources that expand the functionality or scope. label Jun 13, 2017
@ozbillwang
Copy link

ozbillwang commented Jun 29, 2017

In fact, when you import route table, it will import all route table associations together, but the name of aws_route_table_association resource has an issue:

aws_route_table_association.db
aws_route_table_association.db-1

It should be:

aws_route_table_association.db.0
aws_route_table_association.db.1

@ozbillwang
Copy link

@GuiSim

@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2018
@apanagiotou
Copy link

Has anyone managed to bypass this even manually? I'm migrating CloudFormation to Terraform and I'm stuck at importing aws_route_table_association. Any guidance would be useful. Thanks

@pib
Copy link

pib commented Sep 11, 2018

@apanagiotou Yes, I have worked around it by using "terraform state mv".

For example, in the above post where it mentions that it automatically imports the wrong names, you can fix that by running:

$ terraform state mv aws_route_table_association.db aws_route_table_association.db.0
$ terraform state mv aws_route_table_association.db-1 aws_route_table_association.db.1

(or possibly [0] and [1], which is what I used)

@klloveall
Copy link

Just to clarify, the square brackets do work as mentioned at the end of @pib 's comment. Not sure if the dot notation he has works as well, but the following is (almost) exactly what I used:

terraform state mv [...].vpc.aws_route_table_association.external [...].vpc.aws_route_table_association.external[0]
terraform state mv [...].vpc.aws_route_table_association.external-1 [...].vpc.aws_route_table_association.external[1]
terraform state mv [...].vpc.aws_route_table_association.external-2 [...].vpc.aws_route_table_association.external[2]

@nunofernandes
Copy link

Also in need of this to migrate from cloudformation to terraform!

@pit
Copy link

pit commented Mar 12, 2019

This PRs probably will help solving this issue in a different way:
#6999
#5359
#7282

@Indigenuity
Copy link
Contributor

For route table associations that weren't automatically imported correctly or incorrectly, pull your state file for manual editing:

$ terraform state pull > mystate.tmp

Then edit mystate.tmp to include a resource like this:

"aws_route_table_association.private_app": {
    "type": "aws_route_table_association",
    "depends_on": [
        "aws_route_table.private_app",
        "aws_subnet.private_app"
    ],
    "primary": {
        "id": "rtbassoc-REDACTED",
        "attributes": {
            "id": "rtbassoc-REDACTED",
            "route_table_id": "rtb-REDACTED",
            "subnet_id": "subnet-REDACTED"
        },
        "meta": {},
        "tainted": false
    },
    "deposed": [],
    "provider": "provider.aws"
}

Make sure you've still got valid JSON with all the commas, then push the state file back:

$ terraform state push mystate.tmp
# Confirm the outputs of these all look right:
$ terraform state list
$ terraform apply
$ terraform state list

@dimisjim
Copy link
Contributor

dimisjim commented Apr 16, 2019

Best way is to define it in a resource block with the right arguments, plan it and then apply. If it already exists, you would basically only end up adding it to your state file. No reason to pull and edit the state file as @Indigenuity points to.

@Indigenuity
Copy link
Contributor

@dimisjim Yes I think that's the intended behavior, but I ended up with a brief outage when I tried that approach, since it removed the association and then re-created it. User error perhaps, but that's the behavior I get with that approach.

@tmccombs
Copy link
Contributor

If I attempt to apply my aws_route_table_association that I can't import, then I get the following error:

Error: Provider produced inconsistent final plan

When expanding the plan for
module.vpc.aws_route_table_association.public["dlb-c"] to include new values
learned so far during apply, provider "aws" produced an invalid new value for
.route_table_id: was known, but now unknown.

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


Error: Provider produced inconsistent final plan

When expanding the plan for
module.vpc.aws_route_table_association.public["dlb-c"] to include new values
learned so far during apply, provider "aws" produced an invalid new value for
.subnet_id: was known, but now unknown.

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

@bflad
Copy link
Contributor

bflad commented Jul 31, 2019

Support for importing aws_route_table_association resources has been merged and will release with version 2.22.0 of the Terraform AWS Provider, tomorrow. 👍 Thanks to @YakDriver for the implementation.

@bflad bflad closed this as completed Jul 31, 2019
@ghost
Copy link

ghost commented Aug 1, 2019

This has been released in version 2.22.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 Nov 2, 2019

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 Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet