Skip to content

Commit

Permalink
Merge pull request #15548 from terraform-providers/t-aws_emr_instance…
Browse files Browse the repository at this point in the history
…_fleet-disappears

resource/aws_emr_instance_fleet: Prevent error on deletion when EMR Cluster is no longer running
  • Loading branch information
gdavison authored Oct 8, 2020
2 parents 306185b + 5048c0d commit b3016f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions aws/resource_aws_emr_instance_fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/emr"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -356,6 +357,11 @@ func resourceAwsEMRInstanceFleetDelete(d *schema.ResourceData, meta interface{})
}

_, err := conn.ModifyInstanceFleet(modifyInstanceFleetInput)

if tfawserr.ErrMessageContains(err, emr.ErrCodeInvalidRequestException, "instance fleet may only be modified when the cluster is running or waiting") {
return nil
}

if err != nil {
return fmt.Errorf("error deleting/modifying EMR Instance Fleet (%s): %w", d.Id(), err)
}
Expand Down
9 changes: 7 additions & 2 deletions aws/resource_aws_emr_instance_fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,20 @@ func TestAccAWSEMRInstanceFleet_disappears(t *testing.T) {
var fleet emr.InstanceFleet
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_emr_instance_fleet.task"
emrClusterResourceName := "aws_emr_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEmrInstanceFleetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEmrInstanceFleetConfig(rName),
Check: resource.ComposeTestCheckFunc(testAccCheckAWSEmrInstanceFleetExists(resourceName, &fleet),
resource.TestCheckResourceAttr(resourceName, "instance_type_configs.#", "1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrInstanceFleetExists(resourceName, &fleet),
// EMR Instance Fleet can only be scaled down and are not removed until the
// Cluster is removed. Verify EMR Cluster disappearance handling.
testAccCheckResourceDisappears(testAccProvider, resourceAwsEMRCluster(), emrClusterResourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down

0 comments on commit b3016f2

Please sign in to comment.