Skip to content

Commit

Permalink
provider/aws: Guard against panic in aws_vpc_endpoint_association (ha…
Browse files Browse the repository at this point in the history
…shicorp#11613)

I believe that if no VPC Endpoints were returned from the AWS API, we
were not guarding against a panic. We were strill trying to inspect the
RouteTableIds. This commit will ensure that no errors are thrown before
trying to use the RouteTableIds

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpcEndpointRouteTableAssociation_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/01 18:06:29 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpcEndpointRouteTableAssociation_ -timeout 120m
=== RUN   TestAccAWSVpcEndpointRouteTableAssociation_basic
--- PASS: TestAccAWSVpcEndpointRouteTableAssociation_basic (42.83s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	42.859s
```
  • Loading branch information
stack72 authored and arcadiatea committed Feb 7, 2017
1 parent 2db3a10 commit 6c2e1ec
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ func resourceAwsVPCEndpointRouteTableAssociationRead(d *schema.ResourceData, met
rtId := d.Get("route_table_id").(string)

vpce, err := findResourceVPCEndpoint(conn, endpointId)
if err, ok := err.(awserr.Error); ok && err.Code() == "InvalidVpcEndpointId.NotFound" {
d.SetId("")
return nil
if err != nil {
if err, ok := err.(awserr.Error); ok && err.Code() == "InvalidVpcEndpointId.NotFound" {
d.SetId("")
return nil
}

return err
}

found := false
Expand Down Expand Up @@ -143,6 +147,10 @@ func findResourceVPCEndpoint(conn *ec2.EC2, id string) (*ec2.VpcEndpoint, error)
return nil, err
}

if output.VpcEndpoints == nil {
return nil, fmt.Errorf("No VPC Endpoints were found for %q", id)
}

return output.VpcEndpoints[0], nil
}

Expand Down

0 comments on commit 6c2e1ec

Please sign in to comment.