From f040b653ad9753fc91ae8034d3d687d48cd58275 Mon Sep 17 00:00:00 2001 From: Artsiom <82237255+ArtsiomAntropau@users.noreply.github.com> Date: Tue, 8 Feb 2022 18:39:22 +0100 Subject: [PATCH 01/10] Fix EMR is not valid for managed_scaling_policy Fix aws_emr_managed_scaling_policy for compatibility with the behavior of emr_cluster that was fixed as a part of the next problem: https://github.com/hashicorp/terraform-provider-aws/pull/16924 https://github.com/hashicorp/terraform-provider-aws/issues/7783 --- internal/service/emr/managed_scaling_policy.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/service/emr/managed_scaling_policy.go b/internal/service/emr/managed_scaling_policy.go index 76c61fd6f60..2af73437861 100644 --- a/internal/service/emr/managed_scaling_policy.go +++ b/internal/service/emr/managed_scaling_policy.go @@ -115,6 +115,12 @@ func resourceManagedScalingPolicyRead(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } + + if tfawserr.ErrMessageContains(err, "ValidationException", "is not valid") { + log.Printf("[WARN] EMR Cluster (%s) not found", d.Id()) + d.SetId("") + return nil + } if tfawserr.ErrMessageContains(err, "InvalidRequestException", "does not exist") { log.Printf("[WARN] EMR Managed Scaling Policy (%s) not found, removing from state", d.Id()) @@ -152,7 +158,13 @@ func resourceManagedScalingPolicyDelete(d *schema.ResourceData, meta interface{} if tfawserr.ErrMessageContains(err, "ValidationException", "A job flow that is shutting down, terminated, or finished may not be modified") { return nil } - + + if tfawserr.ErrMessageContains(err, "ValidationException", "is not valid") { + log.Printf("[WARN] EMR Cluster (%s) not found", d.Id()) + d.SetId("") + return nil + } + if tfawserr.ErrMessageContains(err, "InvalidRequestException", "does not exist") { return nil } From 120e9507afec61b8b12cff1a645eef058708dd4a Mon Sep 17 00:00:00 2001 From: Aleksey Tsalolikhin Date: Tue, 28 May 2024 10:28:48 -0700 Subject: [PATCH 02/10] Add "io2" as a valid EBS volume type to emr validation routine Resolves https://github.com/hashicorp/terraform-provider-aws/issues/20248 --- internal/service/emr/validate.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/emr/validate.go b/internal/service/emr/validate.go index 8e0e4fd979a..150beb645bf 100644 --- a/internal/service/emr/validate.go +++ b/internal/service/emr/validate.go @@ -30,6 +30,7 @@ func validEBSVolumeType() schema.SchemaValidateFunc { "gp3", "gp2", "io1", + "io2", "standard", "st1", "sc1", From e1d34c6615612473661b697480417fb2e5c3edce Mon Sep 17 00:00:00 2001 From: Aleksey Tsalolikhin Date: Tue, 28 May 2024 13:24:43 -0700 Subject: [PATCH 03/10] Add changelog snippet --- .changelog/37740.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/37740.txt diff --git a/.changelog/37740.txt b/.changelog/37740.txt new file mode 100644 index 00000000000..2f122a6468b --- /dev/null +++ b/.changelog/37740.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_db_instance: Add `io2` as a valid value for EBS config storage `type` ([#20248](https://github.com/hashicorp/terraform-provider-aws/issues/20248)) +``` From f6f9b362aea48bc7b0aa6d2cd0050668aa59304e Mon Sep 17 00:00:00 2001 From: Aleksey Tsalolikhin Date: Tue, 28 May 2024 13:26:02 -0700 Subject: [PATCH 04/10] Fix changelog (fix copypasta error) --- .changelog/37740.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/37740.txt b/.changelog/37740.txt index 2f122a6468b..973b56d7e6b 100644 --- a/.changelog/37740.txt +++ b/.changelog/37740.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_db_instance: Add `io2` as a valid value for EBS config storage `type` ([#20248](https://github.com/hashicorp/terraform-provider-aws/issues/20248)) +resource/aws_emr_cluster: Add `io2` as a valid value for EBS config storage `type` ([#20248](https://github.com/hashicorp/terraform-provider-aws/issues/20248)) ``` From 2b3e85be860aba0756df501df520cc281c214e15 Mon Sep 17 00:00:00 2001 From: Aleksey Tsalolikhin Date: Tue, 28 May 2024 13:29:32 -0700 Subject: [PATCH 05/10] Add `io2` to documentation for aws_emr_cluster storage types --- website/docs/cdktf/python/r/emr_cluster.html.markdown | 2 +- website/docs/cdktf/typescript/r/emr_cluster.html.markdown | 2 +- website/docs/r/emr_cluster.html.markdown | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/cdktf/python/r/emr_cluster.html.markdown b/website/docs/cdktf/python/r/emr_cluster.html.markdown index dbf8376c5b8..18abeb355ea 100644 --- a/website/docs/cdktf/python/r/emr_cluster.html.markdown +++ b/website/docs/cdktf/python/r/emr_cluster.html.markdown @@ -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). diff --git a/website/docs/cdktf/typescript/r/emr_cluster.html.markdown b/website/docs/cdktf/typescript/r/emr_cluster.html.markdown index 19ddee30250..e8255616f62 100644 --- a/website/docs/cdktf/typescript/r/emr_cluster.html.markdown +++ b/website/docs/cdktf/typescript/r/emr_cluster.html.markdown @@ -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). diff --git a/website/docs/r/emr_cluster.html.markdown b/website/docs/r/emr_cluster.html.markdown index 6ad4ecead66..6ef7c984e88 100644 --- a/website/docs/r/emr_cluster.html.markdown +++ b/website/docs/r/emr_cluster.html.markdown @@ -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). From 5e80bed35b3322c212a10c6e110cf0b92d1ea56d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Aug 2024 13:43:18 -0400 Subject: [PATCH 06/10] Tweak CHANGELOG entries. --- .changelog/37740.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.changelog/37740.txt b/.changelog/37740.txt index 973b56d7e6b..3df42ec3fd1 100644 --- a/.changelog/37740.txt +++ b/.changelog/37740.txt @@ -1,3 +1,11 @@ ```release-note:enhancement -resource/aws_emr_cluster: Add `io2` as a valid value for EBS config storage `type` ([#20248](https://github.com/hashicorp/terraform-provider-aws/issues/20248)) +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` +``` \ No newline at end of file From f5fbdaf487147c28be5d9d90468c5160d9edeb63 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Aug 2024 13:48:54 -0400 Subject: [PATCH 07/10] Revert "Fix EMR is not valid for managed_scaling_policy" This reverts commit f040b653ad9753fc91ae8034d3d687d48cd58275. --- internal/service/emr/managed_scaling_policy.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/internal/service/emr/managed_scaling_policy.go b/internal/service/emr/managed_scaling_policy.go index 2af73437861..76c61fd6f60 100644 --- a/internal/service/emr/managed_scaling_policy.go +++ b/internal/service/emr/managed_scaling_policy.go @@ -115,12 +115,6 @@ func resourceManagedScalingPolicyRead(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - - if tfawserr.ErrMessageContains(err, "ValidationException", "is not valid") { - log.Printf("[WARN] EMR Cluster (%s) not found", d.Id()) - d.SetId("") - return nil - } if tfawserr.ErrMessageContains(err, "InvalidRequestException", "does not exist") { log.Printf("[WARN] EMR Managed Scaling Policy (%s) not found, removing from state", d.Id()) @@ -158,13 +152,7 @@ func resourceManagedScalingPolicyDelete(d *schema.ResourceData, meta interface{} if tfawserr.ErrMessageContains(err, "ValidationException", "A job flow that is shutting down, terminated, or finished may not be modified") { return nil } - - if tfawserr.ErrMessageContains(err, "ValidationException", "is not valid") { - log.Printf("[WARN] EMR Cluster (%s) not found", d.Id()) - d.SetId("") - return nil - } - + if tfawserr.ErrMessageContains(err, "InvalidRequestException", "does not exist") { return nil } From 1fc42bf38ce1f1004485c75a583d1138dadddb0d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Aug 2024 13:54:08 -0400 Subject: [PATCH 08/10] r/aws_emr_managed_scaling_policy: Handle "ValidationException: Cluster id '...' is not valid" on Read and Delete. --- internal/service/emr/managed_scaling_policy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/service/emr/managed_scaling_policy.go b/internal/service/emr/managed_scaling_policy.go index e7feb7710be..50874d65520 100644 --- a/internal/service/emr/managed_scaling_policy.go +++ b/internal/service/emr/managed_scaling_policy.go @@ -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 } @@ -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, From a562bc24b810569f2ac6bedaf30fe31e84708c37 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Aug 2024 15:36:41 -0400 Subject: [PATCH 09/10] Add 'TestAccEMRInstanceGroup_instanceCountCreateZero'. --- internal/service/emr/instance_group_test.go | 61 +++++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/internal/service/emr/instance_group_test.go b/internal/service/emr/instance_group_test.go index 2b96b3c2a0e..225619f25f8 100644 --- a/internal/service/emr/instance_group_test.go +++ b/internal/service/emr/instance_group_test.go @@ -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), ), }, { @@ -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) @@ -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, @@ -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}, }, }, }) @@ -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)) } From f3bc323f7d56d4a4c7e8ce0dcf4279dfb3fed40a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 27 Aug 2024 16:10:55 -0400 Subject: [PATCH 10/10] r/aws_emr_instance_group: Properly send an `instance_count` value of `0` on create when configured. --- .changelog/37740.txt | 4 ++++ internal/service/emr/instance_group.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.changelog/37740.txt b/.changelog/37740.txt index 3df42ec3fd1..021e9b4aba3 100644 --- a/.changelog/37740.txt +++ b/.changelog/37740.txt @@ -8,4 +8,8 @@ resource/aws_emr_instance_fleet: Support `io2` as a valid value for `instance_ty ```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 ``` \ No newline at end of file diff --git a/internal/service/emr/instance_group.go b/internal/service/emr/instance_group.go index 36c6b3cc5cb..216ef38ab30 100644 --- a/internal/service/emr/instance_group.go +++ b/internal/service/emr/instance_group.go @@ -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) }