mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-10 23:55:34 -06:00
provider/aws: fix CheckDestroy on a bunch of resources
This commit is contained in:
parent
1d5c65fa86
commit
7d6b98060a
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/codecommit"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
@ -86,9 +87,24 @@ func testAccCheckCodeCommitRepositoryExists(name string) resource.TestCheckFunc
|
||||
}
|
||||
|
||||
func testAccCheckCodeCommitRepositoryDestroy(s *terraform.State) error {
|
||||
if len(s.RootModule().Resources) > 0 {
|
||||
return fmt.Errorf("Expected all resources to be gone, but found: %#v",
|
||||
s.RootModule().Resources)
|
||||
conn := testAccProvider.Meta().(*AWSClient).codecommitconn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_codecommit_repository" {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err := conn.GetRepository(&codecommit.GetRepositoryInput{
|
||||
RepositoryName: aws.String(rs.Primary.ID),
|
||||
})
|
||||
|
||||
if ae, ok := err.(awserr.Error); ok && ae.Code() == "RepositoryDoesNotExistException" {
|
||||
continue
|
||||
}
|
||||
if err == nil {
|
||||
return fmt.Errorf("Repository still exists: %s", rs.Primary.ID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -41,7 +41,7 @@ func testAccCheckAWSCodeDeployAppDestroy(s *terraform.State) error {
|
||||
}
|
||||
|
||||
resp, err := conn.GetApplication(&codedeploy.GetApplicationInput{
|
||||
ApplicationName: aws.String(rs.Primary.ID),
|
||||
ApplicationName: aws.String(rs.Primary.Attributes["name"]),
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/codedeploy"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
@ -45,6 +46,10 @@ func testAccCheckAWSCodeDeployDeploymentGroupDestroy(s *terraform.State) error {
|
||||
DeploymentGroupName: aws.String(rs.Primary.Attributes["deployment_group_name"]),
|
||||
})
|
||||
|
||||
if ae, ok := err.(awserr.Error); ok && ae.Code() == "ApplicationDoesNotExistException" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if resp.DeploymentGroupInfo.DeploymentGroupName != nil {
|
||||
return fmt.Errorf("CodeDeploy deployment group still exists:\n%#v", *resp.DeploymentGroupInfo.DeploymentGroupName)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
@ -46,8 +47,33 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAccCheckCustomerGatewayDestroy(s *terraform.State) error {
|
||||
if len(s.RootModule().Resources) > 0 {
|
||||
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_customer_gatewah" {
|
||||
continue
|
||||
}
|
||||
|
||||
gatewayFilter := &ec2.Filter{
|
||||
Name: aws.String("customer-gateway-id"),
|
||||
Values: []*string{aws.String(rs.Primary.ID)},
|
||||
}
|
||||
|
||||
resp, err := conn.DescribeCustomerGateways(&ec2.DescribeCustomerGatewaysInput{
|
||||
Filters: []*ec2.Filter{gatewayFilter},
|
||||
})
|
||||
|
||||
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidCustomerGatewayID.NotFound" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if len(resp.CustomerGateways) > 0 {
|
||||
return fmt.Errorf("Customer gateway still exists: %v", resp.CustomerGateways)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -120,6 +120,10 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
||||
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
||||
})
|
||||
|
||||
if ae, ok := err.(awserr.Error); ok && ae.Code() == "DBInstanceNotFound" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if len(resp.DBInstances) != 0 &&
|
||||
*resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID {
|
||||
|
@ -50,9 +50,12 @@ func testAccCheckDHCPOptionsDestroy(s *terraform.State) error {
|
||||
aws.String(rs.Primary.ID),
|
||||
},
|
||||
})
|
||||
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidDhcpOptionID.NotFound" {
|
||||
continue
|
||||
}
|
||||
if err == nil {
|
||||
if len(resp.DhcpOptions) > 0 {
|
||||
return fmt.Errorf("still exist.")
|
||||
return fmt.Errorf("still exists")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user