From 92ad428e57560e580fa25ab0939cf1e3ef122e41 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 14:43:38 -0400 Subject: [PATCH 1/6] r/aws_route: Don't fail on Create if there's already a propagated route to the same destination. --- internal/service/ec2/vpc_route.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/service/ec2/vpc_route.go b/internal/service/ec2/vpc_route.go index 953be7565ca..c3c348a82d8 100644 --- a/internal/service/ec2/vpc_route.go +++ b/internal/service/ec2/vpc_route.go @@ -239,13 +239,14 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "creating Route: unexpected route target attribute: %q", targetAttributeKey) } - _, err = routeFinder(ctx, conn, routeTableID, destination) + route, err := routeFinder(ctx, conn, routeTableID, destination) switch { case err == nil: - return sdkdiag.AppendFromErr(diags, routeAlreadyExistsError(routeTableID, destination)) + if aws.StringValue(route.Origin) == ec2.RouteOriginCreateRoute { + return sdkdiag.AppendFromErr(diags, routeAlreadyExistsError(routeTableID, destination)) + } case tfresource.NotFound(err): - break default: return sdkdiag.AppendErrorf(diags, "reading Route: %s", err) } From 2d560833637e8e829e439886ca6f7b9173059f26 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 14:47:40 -0400 Subject: [PATCH 2/6] Add CHANGELOG entry. --- .changelog/#####.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..d9ba09b1c99 --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_route: Allow resource creation if a propagated route to the same destination exists +``` \ No newline at end of file From 2fe26b393ba05425ada1ef43c737729cef23b506 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 15:05:00 -0400 Subject: [PATCH 3/6] Add 'TestAccVPCRoute_localRouteError'. --- internal/service/ec2/vpc_route_test.go | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/service/ec2/vpc_route_test.go b/internal/service/ec2/vpc_route_test.go index e83e47acfb2..3e773dc9f7c 100644 --- a/internal/service/ec2/vpc_route_test.go +++ b/internal/service/ec2/vpc_route_test.go @@ -1676,6 +1676,36 @@ func TestAccVPCRoute_localRouteUpdate(t *testing.T) { }) } +func TestAccVPCRoute_localRouteError(t *testing.T) { + ctx := acctest.Context(t) + var routeTable ec2.RouteTable + var vpc ec2.Vpc + rtResourceName := "aws_route_table.test" + vpcResourceName := "aws_vpc.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRouteDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCRouteConfig_ipv4NoRoute(rName), + Check: resource.ComposeTestCheckFunc( + acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), + testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), + ), + }, + { + Config: testAccVPCRouteConfig_ipv4Local(rName), + ExpectError: regexache.MustCompile("cannot create local Route, use `terraform import` to manage existing local Routes"), + }, + }, + }) +} + func TestAccVPCRoute_prefixListToInternetGateway(t *testing.T) { ctx := acctest.Context(t) var route ec2.Route From db99c08a6f3693859623f68f43be3634cb8d0352 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 15:05:19 -0400 Subject: [PATCH 4/6] Acceptance test output: % make testacc TESTARGS='-run=TestAccVPCRoute_localRouteError' PKG=ec2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.21.8 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run=TestAccVPCRoute_localRouteError -timeout 360m === RUN TestAccVPCRoute_localRouteError === PAUSE TestAccVPCRoute_localRouteError === CONT TestAccVPCRoute_localRouteError vpc_route_test.go:1687: Step 2/2, expected an error with pattern, no match on: Error running apply: exit status 1 Error: RouteAlreadyExists: Route in Route Table (rtb-05af6f646b345080f) with destination (10.1.0.0/16) already exists with aws_route.test, on terraform_plugin_test.tf line 28, in resource "aws_route" "test": 28: resource "aws_route" "test" { --- FAIL: TestAccVPCRoute_localRouteError (28.74s) FAIL FAIL github.com/hashicorp/terraform-provider-aws/internal/service/ec2 40.395s FAIL make: *** [testacc] Error 1 From 21bfe74e8a689a35c636867b6d99c47e1b07c4f8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 15:07:33 -0400 Subject: [PATCH 5/6] Rename some test cases. --- internal/service/ec2/vpc_route_test.go | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/internal/service/ec2/vpc_route_test.go b/internal/service/ec2/vpc_route_test.go index 3e773dc9f7c..ab52c82e016 100644 --- a/internal/service/ec2/vpc_route_test.go +++ b/internal/service/ec2/vpc_route_test.go @@ -1573,8 +1573,38 @@ func TestAccVPCRoute_ipv6ToVPCEndpoint(t *testing.T) { }) } +func TestAccVPCRoute_localRouteCreateError(t *testing.T) { + ctx := acctest.Context(t) + var routeTable ec2.RouteTable + var vpc ec2.Vpc + rtResourceName := "aws_route_table.test" + vpcResourceName := "aws_vpc.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRouteDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCRouteConfig_ipv4NoRoute(rName), + Check: resource.ComposeTestCheckFunc( + acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), + testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), + ), + }, + { + Config: testAccVPCRouteConfig_ipv4Local(rName), + ExpectError: regexache.MustCompile("cannot create local Route, use `terraform import` to manage existing local Routes"), + }, + }, + }) +} + // https://github.com/hashicorp/terraform-provider-aws/issues/11455. -func TestAccVPCRoute_localRoute(t *testing.T) { +func TestAccVPCRoute_localRouteImport(t *testing.T) { ctx := acctest.Context(t) var routeTable ec2.RouteTable var vpc ec2.Vpc @@ -1615,7 +1645,7 @@ func TestAccVPCRoute_localRoute(t *testing.T) { } // https://github.com/hashicorp/terraform-provider-aws/issues/21350. -func TestAccVPCRoute_localRouteUpdate(t *testing.T) { +func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { ctx := acctest.Context(t) var routeTable ec2.RouteTable var vpc ec2.Vpc @@ -1676,36 +1706,6 @@ func TestAccVPCRoute_localRouteUpdate(t *testing.T) { }) } -func TestAccVPCRoute_localRouteError(t *testing.T) { - ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc - rtResourceName := "aws_route_table.test" - vpcResourceName := "aws_vpc.test" - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckRouteDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccVPCRouteConfig_ipv4NoRoute(rName), - Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), - testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), - testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), - ), - }, - { - Config: testAccVPCRouteConfig_ipv4Local(rName), - ExpectError: regexache.MustCompile("cannot create local Route, use `terraform import` to manage existing local Routes"), - }, - }, - }) -} - func TestAccVPCRoute_prefixListToInternetGateway(t *testing.T) { ctx := acctest.Context(t) var route ec2.Route From f3839bffa9db746bc090294f6da2b1651fd0b0b4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 21 Mar 2024 15:18:16 -0400 Subject: [PATCH 6/6] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 36512.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 36512.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/36512.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/36512.txt