Skip to content

Commit

Permalink
r/aws_route_table: Add 'd.IsNewResource()' check to resource read (#1…
Browse files Browse the repository at this point in the history
…6796).

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRouteTable_' ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 2 -run=TestAccAWSRouteTable_ -timeout 180m
=== RUN   TestAccAWSRouteTable_basic
=== PAUSE TestAccAWSRouteTable_basic
=== RUN   TestAccAWSRouteTable_disappears
=== PAUSE TestAccAWSRouteTable_disappears
=== RUN   TestAccAWSRouteTable_disappears_SubnetAssociation
=== PAUSE TestAccAWSRouteTable_disappears_SubnetAssociation
=== RUN   TestAccAWSRouteTable_IPv4_To_InternetGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_InternetGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_Instance
=== PAUSE TestAccAWSRouteTable_IPv4_To_Instance
=== RUN   TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== PAUSE TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
=== RUN   TestAccAWSRouteTable_tags
=== PAUSE TestAccAWSRouteTable_tags
=== RUN   TestAccAWSRouteTable_RequireRouteDestination
=== PAUSE TestAccAWSRouteTable_RequireRouteDestination
=== RUN   TestAccAWSRouteTable_RequireRouteTarget
=== PAUSE TestAccAWSRouteTable_RequireRouteTarget
=== RUN   TestAccAWSRouteTable_Route_ConfigMode
=== PAUSE TestAccAWSRouteTable_Route_ConfigMode
=== RUN   TestAccAWSRouteTable_IPv4_To_TransitGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_TransitGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_VpcEndpoint
=== PAUSE TestAccAWSRouteTable_IPv4_To_VpcEndpoint
=== RUN   TestAccAWSRouteTable_IPv4_To_CarrierGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_CarrierGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_LocalGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_LocalGateway
=== RUN   TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== PAUSE TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
=== RUN   TestAccAWSRouteTable_vgwRoutePropagation
=== PAUSE TestAccAWSRouteTable_vgwRoutePropagation
=== RUN   TestAccAWSRouteTable_ConditionalCidrBlock
=== PAUSE TestAccAWSRouteTable_ConditionalCidrBlock
=== RUN   TestAccAWSRouteTable_IPv4_To_NatGateway
=== PAUSE TestAccAWSRouteTable_IPv4_To_NatGateway
=== RUN   TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
=== PAUSE TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
=== RUN   TestAccAWSRouteTable_VpcMultipleCidrs
=== PAUSE TestAccAWSRouteTable_VpcMultipleCidrs
=== RUN   TestAccAWSRouteTable_VpcClassicLink
=== PAUSE TestAccAWSRouteTable_VpcClassicLink
=== RUN   TestAccAWSRouteTable_GatewayVpcEndpoint
=== PAUSE TestAccAWSRouteTable_GatewayVpcEndpoint
=== RUN   TestAccAWSRouteTable_MultipleRoutes
=== PAUSE TestAccAWSRouteTable_MultipleRoutes
=== RUN   TestAccAWSRouteTable_PrefixList_To_InternetGateway
=== PAUSE TestAccAWSRouteTable_PrefixList_To_InternetGateway
=== CONT  TestAccAWSRouteTable_basic
=== CONT  TestAccAWSRouteTable_IPv4_To_LocalGateway
    data_source_aws_outposts_outposts_test.go:67: skipping since no Outposts found
--- SKIP: TestAccAWSRouteTable_IPv4_To_LocalGateway (1.40s)
=== CONT  TestAccAWSRouteTable_PrefixList_To_InternetGateway
--- PASS: TestAccAWSRouteTable_basic (22.84s)
=== CONT  TestAccAWSRouteTable_MultipleRoutes
--- PASS: TestAccAWSRouteTable_PrefixList_To_InternetGateway (42.61s)
=== CONT  TestAccAWSRouteTable_GatewayVpcEndpoint
--- PASS: TestAccAWSRouteTable_GatewayVpcEndpoint (65.20s)
=== CONT  TestAccAWSRouteTable_VpcClassicLink
--- PASS: TestAccAWSRouteTable_VpcClassicLink (23.99s)
=== CONT  TestAccAWSRouteTable_VpcMultipleCidrs
--- PASS: TestAccAWSRouteTable_VpcMultipleCidrs (44.49s)
=== CONT  TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
--- PASS: TestAccAWSRouteTable_MultipleRoutes (174.34s)
=== CONT  TestAccAWSRouteTable_IPv4_To_NatGateway
--- PASS: TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached (64.12s)
=== CONT  TestAccAWSRouteTable_ConditionalCidrBlock
--- PASS: TestAccAWSRouteTable_ConditionalCidrBlock (54.20s)
=== CONT  TestAccAWSRouteTable_vgwRoutePropagation
--- PASS: TestAccAWSRouteTable_vgwRoutePropagation (86.26s)
=== CONT  TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection
--- PASS: TestAccAWSRouteTable_IPv4_To_VpcPeeringConnection (26.81s)
=== CONT  TestAccAWSRouteTable_RequireRouteDestination
--- PASS: TestAccAWSRouteTable_IPv4_To_NatGateway (246.64s)
=== CONT  TestAccAWSRouteTable_IPv4_To_CarrierGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_CarrierGateway (26.55s)
=== CONT  TestAccAWSRouteTable_IPv4_To_VpcEndpoint
--- PASS: TestAccAWSRouteTable_RequireRouteDestination (324.00s)
=== CONT  TestAccAWSRouteTable_IPv4_To_TransitGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_VpcEndpoint (263.18s)
=== CONT  TestAccAWSRouteTable_Route_ConfigMode
--- PASS: TestAccAWSRouteTable_Route_ConfigMode (70.84s)
=== CONT  TestAccAWSRouteTable_RequireRouteTarget
--- PASS: TestAccAWSRouteTable_RequireRouteTarget (11.86s)
=== CONT  TestAccAWSRouteTable_IPv4_To_Instance
--- PASS: TestAccAWSRouteTable_IPv4_To_Instance (113.23s)
=== CONT  TestAccAWSRouteTable_tags
--- PASS: TestAccAWSRouteTable_tags (68.59s)
=== CONT  TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
--- PASS: TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway (47.38s)
=== CONT  TestAccAWSRouteTable_disappears_SubnetAssociation
--- PASS: TestAccAWSRouteTable_disappears_SubnetAssociation (24.28s)
=== CONT  TestAccAWSRouteTable_IPv4_To_InternetGateway
--- PASS: TestAccAWSRouteTable_IPv4_To_TransitGateway (339.66s)
=== CONT  TestAccAWSRouteTable_disappears
--- PASS: TestAccAWSRouteTable_disappears (20.05s)
--- PASS: TestAccAWSRouteTable_IPv4_To_InternetGateway (64.71s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1134.554s
  • Loading branch information
ewbankkit authored and YakDriver committed Mar 29, 2021
1 parent 6c2cc1f commit 2fef042
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/hashcode"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ec2/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

var routeTableValidDestinations = []string{
Expand Down Expand Up @@ -203,35 +205,29 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
d.Id(), err)
}

if err := resourceAwsRouteTableUpdate(d, meta); err != nil {
return fmt.Errorf("Error updating route table after creating it: %s", err)
}

if d.Id() == "" {
return fmt.Errorf("Route table not found after creating it: %s", err)
}

return nil
return resourceAwsRouteTableUpdate(d, meta)
}

func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
if err != nil {
return err
}
if rtRaw == nil {
routeTable, err := finder.RouteTableByID(conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Route table (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

rt := rtRaw.(*ec2.RouteTable)
d.Set("vpc_id", rt.VpcId)
if err != nil {
return fmt.Errorf("error reading route table (%s): %w", d.Id(), err)
}

d.Set("vpc_id", routeTable.VpcId)

propagatingVGWs := make([]string, 0, len(rt.PropagatingVgws))
for _, vgw := range rt.PropagatingVgws {
propagatingVGWs := make([]string, 0, len(routeTable.PropagatingVgws))
for _, vgw := range routeTable.PropagatingVgws {
propagatingVGWs = append(propagatingVGWs, aws.StringValue(vgw.GatewayId))
}
d.Set("propagating_vgws", propagatingVGWs)
Expand All @@ -240,7 +236,7 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
route := &schema.Set{F: resourceAwsRouteTableHash}

// Loop through the routes and add them to the set
for _, r := range rt.Routes {
for _, r := range routeTable.Routes {
if aws.StringValue(r.GatewayId) == "local" {
continue
}
Expand Down Expand Up @@ -303,11 +299,11 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
d.Set("route", route)

// Tags
if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(rt.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(routeTable.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

ownerID := aws.StringValue(rt.OwnerId)
ownerID := aws.StringValue(routeTable.OwnerId)
arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: ec2.ServiceName,
Expand Down

0 comments on commit 2fef042

Please sign in to comment.