provider/aws: Remove VPC Endpoint from state if it's not found

This commit is contained in:
clint shryock 2016-10-24 14:17:58 -05:00
parent 8552546132
commit 85dd379974
2 changed files with 36 additions and 0 deletions

View File

@ -106,6 +106,8 @@ func resourceAwsVPCEndpointRead(d *schema.ResourceData, meta interface{}) error
}
if ec2err.Code() == "InvalidVpcEndpointId.NotFound" {
log.Printf("[WARN] VPC Endpoint (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

View File

@ -81,6 +81,40 @@ func TestAccAWSVpcEndpoint_WithoutRouteTableOrPolicyConfig(t *testing.T) {
})
}
func TestAccAWSVpcEndpoint_removed(t *testing.T) {
var endpoint ec2.VpcEndpoint
// reach out and DELETE the VPC Endpoint outside of Terraform
testDestroy := func(*terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
input := &ec2.DeleteVpcEndpointsInput{
VpcEndpointIds: []*string{endpoint.VpcEndpointId},
}
_, err := conn.DeleteVpcEndpoints(input)
if err != nil {
return err
}
return nil
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcEndpointDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccVpcEndpointWithoutRouteTableOrPolicyConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcEndpointExists("aws_vpc_endpoint.second-private-s3", &endpoint),
testDestroy,
),
ExpectNonEmptyPlan: true,
},
},
})
}
func testAccCheckVpcEndpointDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn