Skip to content

Commit

Permalink
Merge pull request #37740 from atsalolikhin-spokeo/fix/20248
Browse files Browse the repository at this point in the history
Add "io2" as a valid EBS volume type to EMR validation routine
  • Loading branch information
ewbankkit authored Aug 27, 2024
2 parents a5ed8dc + f3bc323 commit 99ca8dd
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .changelog/37740.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:enhancement
resource/aws_emr_cluster: Support `io2` as a valid value for `ebs_config.type`
```

```release-note:enhancement
resource/aws_emr_instance_fleet: Support `io2` as a valid value for `instance_type_configs.ebs_config.type`
```

```release-note:enhancement
resource/aws_emr_instance_group: Support `io2` as a valid value for `instance_type_configs.ebs_config.type`
```

```release-note:bug
resource/aws_emr_instance_group: Properly send an `instance_count` value of `0` on create when configured
```
5 changes: 3 additions & 2 deletions internal/service/emr/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ func resourceInstanceGroupCreate(ctx context.Context, d *schema.ResourceData, me
}
}

if v, ok := d.GetOk(names.AttrInstanceCount); ok {
groupConfig.InstanceCount = aws.Int32(int32(v.(int)))
if v := d.GetRawConfig().GetAttr(names.AttrInstanceCount); v.IsKnown() && !v.IsNull() {
v, _ := v.AsBigFloat().Int64()
groupConfig.InstanceCount = aws.Int32(int32(v))
} else {
groupConfig.InstanceCount = aws.Int32(1)
}
Expand Down
61 changes: 50 additions & 11 deletions internal/service/emr/instance_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ func TestAccEMRInstanceGroup_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceGroupExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "autoscaling_policy", ""),
resource.TestCheckResourceAttr(resourceName, "bid_price", ""),
resource.TestCheckResourceAttr(resourceName, "ebs_optimized", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceCount, acctest.Ct1),
),
},
{
Expand Down Expand Up @@ -258,8 +259,8 @@ func TestAccEMRInstanceGroup_autoScalingPolicy(t *testing.T) {
}

// Confirm we can scale down the instance count.
// Regression test for https://github.com/hashicorp/terraform-provider-aws/issues/1264
func TestAccEMRInstanceGroup_instanceCount(t *testing.T) {
// See https://github.com/hashicorp/terraform-provider-aws/issues/1264.
func TestAccEMRInstanceGroup_instanceCountDecrease(t *testing.T) {
ctx := acctest.Context(t)
var v awstypes.InstanceGroup
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand All @@ -272,8 +273,11 @@ func TestAccEMRInstanceGroup_instanceCount(t *testing.T) {
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupConfig_basic(rName),
Check: testAccCheckInstanceGroupExists(ctx, resourceName, &v),
Config: testAccInstanceGroupConfig_instanceCount(rName, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceCount, acctest.Ct2),
),
},
{
ResourceName: resourceName,
Expand All @@ -283,8 +287,43 @@ func TestAccEMRInstanceGroup_instanceCount(t *testing.T) {
ImportStateVerifyIgnore: []string{names.AttrStatus},
},
{
Config: testAccInstanceGroupConfig_zeroCount(rName),
Check: testAccCheckInstanceGroupExists(ctx, resourceName, &v),
Config: testAccInstanceGroupConfig_instanceCount(rName, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceCount, acctest.Ct0),
),
},
},
})
}

// Confirm we can create with a 0 instance count.
// See https://github.com/hashicorp/terraform-provider-aws/issues/38837.
func TestAccEMRInstanceGroup_instanceCountCreateZero(t *testing.T) {
ctx := acctest.Context(t)
var v awstypes.InstanceGroup
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_emr_instance_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EMRServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupConfig_instanceCount(rName, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceGroupExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceCount, acctest.Ct0),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccInstanceGroupResourceImportStateIdFunc(resourceName),
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{names.AttrStatus},
},
},
})
Expand Down Expand Up @@ -518,12 +557,12 @@ resource "aws_emr_instance_group" "test" {
`, o))
}

func testAccInstanceGroupConfig_zeroCount(rName string) string {
return acctest.ConfigCompose(testAccInstanceGroupConfig_base(rName), `
func testAccInstanceGroupConfig_instanceCount(rName string, count int) string {
return acctest.ConfigCompose(testAccInstanceGroupConfig_base(rName), fmt.Sprintf(`
resource "aws_emr_instance_group" "test" {
cluster_id = aws_emr_cluster.test.id
instance_count = 0
instance_count = %[1]d
instance_type = "c4.large"
}
`)
`, count))
}
2 changes: 2 additions & 0 deletions internal/service/emr/managed_scaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func resourceManagedScalingPolicyDelete(ctx context.Context, d *schema.ResourceD
})

if tfawserr.ErrMessageContains(err, errCodeValidationException, "A job flow that is shutting down, terminated, or finished may not be modified") ||
tfawserr.ErrMessageContains(err, errCodeValidationException, "is not valid") ||
errs.IsAErrorMessageContains[*awstypes.InvalidRequestException](err, "does not exist") {
return diags
}
Expand All @@ -174,6 +175,7 @@ func findManagedScalingPolicy(ctx context.Context, conn *emr.Client, input *emr.
output, err := conn.GetManagedScalingPolicy(ctx, input)

if tfawserr.ErrMessageContains(err, errCodeValidationException, "A job flow that is shutting down, terminated, or finished may not be modified") ||
tfawserr.ErrMessageContains(err, errCodeValidationException, "is not valid") ||
errs.IsAErrorMessageContains[*awstypes.InvalidRequestException](err, "does not exist") {
return nil, &retry.NotFoundError{
LastError: err,
Expand Down
1 change: 1 addition & 0 deletions internal/service/emr/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func validEBSVolumeType() schema.SchemaValidateFunc {
"gp3",
"gp2",
"io1",
"io2",
"standard",
"st1",
"sc1",
Expand Down
2 changes: 1 addition & 1 deletion website/docs/cdktf/python/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ The launch specification for Spot instances in the fleet, which determines the d

* `iops` - (Optional) Number of I/O operations per second (IOPS) that the volume supports.
* `size` - (Required) Volume size, in gibibytes (GiB).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `io2`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `throughput` - (Optional) The throughput, in mebibyte per second (MiB/s).
* `volumes_per_instance` - (Optional) Number of EBS volumes with this configuration to attach to each EC2 instance in the instance group (default is 1).

Expand Down
2 changes: 1 addition & 1 deletion website/docs/cdktf/typescript/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ The launch specification for Spot instances in the fleet, which determines the d

* `iops` - (Optional) Number of I/O operations per second (IOPS) that the volume supports.
* `size` - (Required) Volume size, in gibibytes (GiB).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `io2`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `throughput` - (Optional) The throughput, in mebibyte per second (MiB/s).
* `volumesPerInstance` - (Optional) Number of EBS volumes with this configuration to attach to each EC2 instance in the instance group (default is 1).

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ The launch specification for Spot instances in the fleet, which determines the d

* `iops` - (Optional) Number of I/O operations per second (IOPS) that the volume supports.
* `size` - (Required) Volume size, in gibibytes (GiB).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `type` - (Required) Volume type. Valid options are `gp3`, `gp2`, `io1`, `io2`, `standard`, `st1` and `sc1`. See [EBS Volume Types](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html).
* `throughput` - (Optional) The throughput, in mebibyte per second (MiB/s).
* `volumes_per_instance` - (Optional) Number of EBS volumes with this configuration to attach to each EC2 instance in the instance group (default is 1).

Expand Down

0 comments on commit 99ca8dd

Please sign in to comment.