Skip to content

Commit

Permalink
Merge pull request #36512 from hashicorp/b-aws_route-duplicate-route-…
Browse files Browse the repository at this point in the history
…propagation

r/aws_route: Don't fail on Create if there's already a propagated (or local) route to the same destination
  • Loading branch information
ewbankkit committed Mar 21, 2024
2 parents 1f6bad1 + f3839bf commit fb68fa7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/36512.txt
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_route: Allow resource creation if a propagated route to the same destination exists
```
7 changes: 4 additions & 3 deletions internal/service/ec2/vpc_route.go
Expand Up @@ -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)
}
Expand Down
34 changes: 32 additions & 2 deletions internal/service/ec2/vpc_route_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb68fa7

Please sign in to comment.