mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Remove VPC Endpoint from state if it's not found
This commit is contained in:
parent
8552546132
commit
85dd379974
@ -106,6 +106,8 @@ func resourceAwsVPCEndpointRead(d *schema.ResourceData, meta interface{}) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ec2err.Code() == "InvalidVpcEndpointId.NotFound" {
|
if ec2err.Code() == "InvalidVpcEndpointId.NotFound" {
|
||||||
|
log.Printf("[WARN] VPC Endpoint (%s) not found, removing from state", d.Id())
|
||||||
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
func testAccCheckVpcEndpointDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user