Merge pull request #7530 from hashicorp/aws-codedeployment-manual
provider/aws: Remove `aws_codedeploy_deployment_group` from state on 404
This commit is contained in:
commit
4c05fddd9b
|
@ -238,6 +238,12 @@ func resourceAwsCodeDeployDeploymentGroupRead(d *schema.ResourceData, meta inter
|
|||
DeploymentGroupName: aws.String(d.Get("deployment_group_name").(string)),
|
||||
})
|
||||
if err != nil {
|
||||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "DeploymentGroupDoesNotExistException" {
|
||||
log.Printf("[INFO] CodeDeployment DeploymentGroup %s not found", d.Get("deployment_group_name").(string))
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"regexp"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
|
@ -107,6 +108,27 @@ func TestAccAWSCodeDeployDeploymentGroup_onPremiseTag(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccAWSCodeDeployDeploymentGroup_disappears(t *testing.T) {
|
||||
var group codedeploy.DeploymentGroupInfo
|
||||
rName := acctest.RandString(5)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSCodeDeployDeploymentGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCodeDeployDeploymentGroup(rName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo", &group),
|
||||
testAccAWSCodeDeployDeploymentGroupDisappears(&group),
|
||||
),
|
||||
ExpectNonEmptyPlan: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_basic(t *testing.T) {
|
||||
var group codedeploy.DeploymentGroupInfo
|
||||
|
||||
|
@ -407,6 +429,36 @@ func testAccCheckAWSCodeDeployDeploymentGroupDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func testAccAWSCodeDeployDeploymentGroupDisappears(group *codedeploy.DeploymentGroupInfo) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).codedeployconn
|
||||
opts := &codedeploy.DeleteDeploymentGroupInput{
|
||||
ApplicationName: group.ApplicationName,
|
||||
DeploymentGroupName: group.DeploymentGroupName,
|
||||
}
|
||||
if _, err := conn.DeleteDeploymentGroup(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
return resource.Retry(40*time.Minute, func() *resource.RetryError {
|
||||
opts := &codedeploy.GetDeploymentGroupInput{
|
||||
ApplicationName: group.ApplicationName,
|
||||
DeploymentGroupName: group.DeploymentGroupName,
|
||||
}
|
||||
_, err := conn.GetDeploymentGroup(opts)
|
||||
if err != nil {
|
||||
codedeploy, ok := err.(awserr.Error)
|
||||
if ok && codedeploy.Code() == "DeploymentGroupDoesNotExistException" {
|
||||
return nil
|
||||
}
|
||||
return resource.NonRetryableError(
|
||||
fmt.Errorf("Error retrieving CodeDeploy Deployment Group: %s", err))
|
||||
}
|
||||
return resource.RetryableError(fmt.Errorf(
|
||||
"Waiting for CodeDeploy Deployment Group: %v", group.DeploymentGroupName))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSCodeDeployDeploymentGroupExists(name string, group *codedeploy.DeploymentGroupInfo) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
|
|
Loading…
Reference in New Issue