Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_emr_instance_fleet: Prevent error on deletion when EMR Cluster is no longer running #15548

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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