-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/aws_route_table: Fix route table import to avoid deleting routes #5657
Conversation
Marking as breaking change as this fundamentally changes the behavior of import for the resource. I personally do not know the historical context of why this resource is setup to perform the complex import, but if I had to guess off top of my head, its because there is currently no method to import the separate |
Add the ability to import routes. Here are the new acceptance tests directed specifically at aws_route import: $ make testacc TESTARGS='-run=TestAccAWSRoute_import'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run=TestAccAWSRoute_import -timeout 120m
? github.com/terraform-providers/terraform-provider-aws [no test files]
=== RUN TestAccAWSRoute_importBasic
--- PASS: TestAccAWSRoute_importBasic (51.14s)
=== RUN TestAccAWSRoute_importIPv6IGW
--- PASS: TestAccAWSRoute_importIPv6IGW (51.20s)
=== RUN TestAccAWSRoute_importIPv6NetworkInterface
--- PASS: TestAccAWSRoute_importIPv6NetworkInterface (177.98s)
=== RUN TestAccAWSRoute_importWithMultipleRTs
--- PASS: TestAccAWSRoute_importWithMultipleRTs (47.10s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 327.456s |
@bflad As you mentioned earlier, this change might be wise to consider at the same time as implementing importing This PR does fundamentally change the import of Currently, if you create an If down the road, you import that exact same This has production impact on us. When managing tenant infrastructures, when we import route tables as part of a larger import, make changes to unrelated resources, and then attempt to apply the changes, all the routes are deleted. That is the breaking issue. :) |
99d210b
to
5c0c3f1
Compare
5c0c3f1
to
2291aae
Compare
@YakDriver I do really want to emphasize that this change does seem like a good path forward, its just a matter of keeping our compatibility promises. The You have a few options for working with this today:
My recommendations for this pull request in its current state to move things forward (unless we want to do all this in 2.0.0):
|
@bflad The
|
2291aae
to
ffdfce7
Compare
3f3cca9
to
1ec393a
Compare
Test on master: If you run the new acceptance that checks to see if the route is deleted after import/apply on $ make testacc TESTARGS='-run=TestAccAWSRouteTable_importWithCreate'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run=TestAccAWSRouteTable_importWithCreate -timeout 120m
? github.com/terraform-providers/terraform-provider-aws [no test files]
=== RUN TestAccAWSRouteTable_importWithCreate
--- FAIL: TestAccAWSRouteTable_importWithCreate (51.20s)
testing.go:527: Step 1 error: Failed state verification, resource with ID r-rtb-0dd113e4fe3107bdd1218385255 not found
FAIL
FAIL github.com/terraform-providers/terraform-provider-aws/aws 51.232s
make: *** [testacc] Error 1 Test on this branch: Acceptance tests after adjusting, rebasing. $ make testacc TESTARGS='-run=TestAccAWSRouteTable_import'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run=TestAccAWSRouteTable_import -timeout 120m
? github.com/terraform-providers/terraform-provider-aws [no test files]
=== RUN TestAccAWSRouteTable_importBasic
--- PASS: TestAccAWSRouteTable_importBasic (53.04s)
=== RUN TestAccAWSRouteTable_importWithCreate
--- PASS: TestAccAWSRouteTable_importWithCreate (68.20s)
=== RUN TestAccAWSRouteTable_importComplex
--- PASS: TestAccAWSRouteTable_importComplex (186.16s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 307.443s |
@bflad Everything you suggested for implementation is ready for review, adjust, merge. Please see earlier comment for PR #s. |
1ec393a
to
6085ca8
Compare
This PR needs some work. Currently, with this PR:
Here are configs based on these scenarios that, in my opinion, should work:
resource "aws_route_table" "test" {
vpc_id = "${aws_vpc.test.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.test.id}"
}
tags {
Name = "bflad-testing"
}
}
resource "aws_route_table" "test" {
vpc_id = "${aws_vpc.test.id}"
tags {
Name = "bflad-testing"
}
}
resource "aws_route" "test" {
route_table_id = "${aws_route_table.test.id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.test.id}"
}
resource "aws_route_table" "test" {
vpc_id = "${aws_vpc.test.id}"
tags {
Name = "bflad-testing"
}
}
resource "aws_route" "randomname" {
route_table_id = "${aws_route_table.test.id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.test.id}"
} |
#5715 has been merged so this is ready for rebase 👍 This pull request should not worry about handling scenarios with separate |
6085ca8
to
5e31151
Compare
That's by design, not a problem. The This is what allows there to be a separate As an aside: the import process for a resource is an implicit call to the read function of a resource after the In practice, this is why we generally only care about setting the ID or required attributes for reading in the While we currently support this "complex" import, where the import of one resource creates other resources in the Terraform state, its usage is very limited and often more confusing. At some point we may remove support for these "complex" imports or support better import models in coordination with upstream changes in Terraform core. There have been design sketches where Terraform automatically creates the configuration. The implementation of a feature like that may influence how import works in the future. We'll see. 😄 |
@bflad I guess I'll stop complaining about my PR then! Thanks |
1e03a89
to
f03ef7b
Compare
f03ef7b
to
183ce10
Compare
183ce10
to
15c4ae5
Compare
15c4ae5
to
25dcef4
Compare
25dcef4
to
b768f5d
Compare
ea0f3f4
to
7ee437f
Compare
7ee437f
to
b6a8107
Compare
b6a8107
to
f3b68fd
Compare
f3b68fd
to
c02891f
Compare
Import route tables using inline routes in the resource data. This is the same way resource data is structured when routes tables are read (and created) which enables imports to line up properly with existing resources. Previously, if you applied a state that included the import of a route table, all routes in the route table would be deleted. This bug occurred because the import function (resourceAwsRouteTableImportState()) would return a target state including both a route table resource and separate route resources for each route. The route table read function (resourceAwsRouteTableRead()) returns a state with a route table resource having inline routes. Despite being equivalent, since the states did not match, Terraform would delete all routes in the route table when applying the change plan. Fixes hashicorp#5631 Update functions names to comply with convention This commit is planned to occur after PR hashicorp#5687 which changes the names of these functions. In order to avoid merge conflicts at that time, this pre-emptively renames the functions.
Use checks that align with inline routes in the state. Improve tests to avoid network values that will conflict with fewer AWS accounts. Previously, route table import acceptance tests only checked the length of the state (1 for route table, and 1 for each separate route resource). This simple test did not check much, especially when checking route tables with inline routes. Now, the state is checked to make sure it has routes and a route- count attribute that matches to expected value.
c02891f
to
68f28fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your dedication and patience here, @YakDriver! We're currently in the process of pulling version 2.0.0 related changes and this one is ready to go. 🚀
Output from acceptance testing:
--- PASS: TestAccAWSRouteTable_panicEmptyRoute (15.79s)
--- PASS: TestAccAWSRouteTable_ipv6 (25.46s)
--- PASS: TestAccAWSRouteTable_vpcPeering (36.18s)
--- PASS: TestAccAWSRouteTable_tags (36.75s)
--- PASS: TestAccAWSRouteTable_vgwRoutePropagation (37.36s)
--- PASS: TestAccAWSRouteTable_importBasic (37.53s)
--- PASS: TestAccAWSRouteTable_importWithCreate (48.96s)
--- PASS: TestAccAWSRouteTable_basic (50.77s)
--- PASS: TestAccAWSRouteTable_instance (150.77s)
--- PASS: TestAccAWSRouteTable_Route_TransitGatewayID (290.56s)
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! |
Fixes #5631, fixes #2270, fixes #5686
Changes proposed in this pull request:
Output from acceptance testing: