provider/aws: Remove `aws_codedeploy_deployment_group` from state on 404
Fixes #4802 The manual removal will now force Terraform to remove the resource from state and then report it needs recreated
This commit is contained in:
parent
21e2173e0a
commit
53681390d4
|
@ -238,6 +238,12 @@ func resourceAwsCodeDeployDeploymentGroupRead(d *schema.ResourceData, meta inter
|
||||||
DeploymentGroupName: aws.String(d.Get("deployment_group_name").(string)),
|
DeploymentGroupName: aws.String(d.Get("deployment_group_name").(string)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"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) {
|
func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_basic(t *testing.T) {
|
||||||
var group codedeploy.DeploymentGroupInfo
|
var group codedeploy.DeploymentGroupInfo
|
||||||
|
|
||||||
|
@ -407,6 +429,36 @@ func testAccCheckAWSCodeDeployDeploymentGroupDestroy(s *terraform.State) error {
|
||||||
return nil
|
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 {
|
func testAccCheckAWSCodeDeployDeploymentGroupExists(name string, group *codedeploy.DeploymentGroupInfo) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[name]
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
|
Loading…
Reference in New Issue