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:
James Nugent 2016-07-08 11:05:06 +01:00 committed by GitHub
commit 4c05fddd9b
2 changed files with 58 additions and 0 deletions

View File

@ -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
}

View File

@ -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]