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_route import reports success even on fail #6404

Closed
YakDriver opened this issue Nov 8, 2018 · 5 comments
Closed

aws_route import reports success even on fail #6404

YakDriver opened this issue Nov 8, 2018 · 5 comments
Labels
upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@YakDriver
Copy link
Member

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 "me too" comments, 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

Terraform v0.11.10
AWS v1.43.0

Affected Resource(s)

  • aws_route

Terraform Configuration Files

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

  tags {
    Name = "yak-testing"
  }
}

resource "aws_internet_gateway" "test" {
  vpc_id = "${aws_vpc.test.id}"

  tags {
    Name = "yak-testing"
  }
}
resource "aws_route_table" "test" {
  vpc_id = "${aws_vpc.test.id}"

  tags {
    Name = "yak-testing"
  }
}

resource "aws_route" "test" {
  route_table_id = "${aws_route_table.test.id}"
  destination_cidr_block = "10.1.0.0/16"
  gateway_id = "${aws_internet_gateway.test.id}"
}

output "test_id" {
  value = "${aws_route_table.test.id}"
}

Expected Behavior

It should fail on import.

Actual Behavior

It displays Import complete! and then fails on refresh, which is confusing.

Steps to Reproduce

After creating the resources, remove the route and attempt to import a non-existent route:

$ terraform state rm aws_route.test
1 items removed.
Item removal successful.
$ terraform import -input=false aws_route.test "rtb-0b8835dc7eb1e3168_12.22.48.96/0"
aws_route.test: Importing from ID "rtb-0b8835dc7eb1e3168_12.22.48.96/0"...
aws_route.test: Import complete!
  Imported aws_route (ID: r-rtb-0b8835dc7eb1e3168715786107)
aws_route.test: Refreshing state... (ID: r-rtb-0b8835dc7eb1e3168715786107)

Error: aws_route.test (import id: rtb-0b8835dc7eb1e3168_12.22.48.96/0): 1 error(s) occurred:

* import aws_route.test result: r-rtb-0b8835dc7eb1e3168715786107: import aws_route.test (id: r-rtb-0b8835dc7eb1e3168715786107): Terraform detected a resource with this ID doesn't
exist. Please verify the ID is correct. You cannot import non-existent
resources using Terraform import.

Important Factoids

References

@YakDriver
Copy link
Member Author

This should be fairly easy to fix. I'll submit a PR to address it shortly.

@bflad bflad added the upstream-terraform Addresses functionality related to the Terraform core binary. label Nov 12, 2018
@bflad
Copy link
Contributor

bflad commented Nov 12, 2018

Hey @YakDriver 👋 This line:

aws_route.test: Import complete!

Is handed upstream in Terraform core after the Importer State function completes:

https://github.com/hashicorp/terraform/blob/f625fb5f6a31ac0df9ae326cdf01258badef415e/command/hook_ui.go#L319

Given we often use schema.ImportStatePassthrough or shorten the State function to only set enough information in the Terraform state so the Read function works (immediately called after State during import by default), maybe its best the verbiage is changed to highlight that only the initial import is complete. This change will need to be discussed upstream though and is unrelated to the AWS provider itself.

Given the above, I'm going to close this issue for now since there is nothing we can change in the provider itself for this behavior beyond calling Read during Importer State and I do not think we should perform two reads during import by default. Hope this makes sense and let me know if I missed anything here.

@bflad bflad closed this as completed Nov 12, 2018
@YakDriver
Copy link
Member Author

Hey @bflad,
On one side: it's confusing to have an import succeed but then fail on refresh.
On the other side: keeping import simple and avoiding two reads is customary.

I think we can find a middle path where we're not performing a full-on read but checking for the routes existence before calling the import a success.

@bflad
Copy link
Contributor

bflad commented Jul 1, 2019

This was fixed upstream (hashicorp/terraform#20018) and will be part of the next Terraform Core release (0.12.4). 😄

@ghost
Copy link

ghost commented Nov 3, 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 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants