diff --git a/aws/resource_aws_emr_cluster.go b/aws/resource_aws_emr_cluster.go index 2a1613da142..cfaf1485080 100644 --- a/aws/resource_aws_emr_cluster.go +++ b/aws/resource_aws_emr_cluster.go @@ -1411,7 +1411,7 @@ func flattenEmrStepSummary(stepSummary *emr.StepSummary) map[string]interface{} } func flattenEBSConfig(ebsBlockDevices []*emr.EbsBlockDevice) *schema.Set { - + uniqueEBS := make(map[int]int) ebsConfig := make([]interface{}, 0) for _, ebs := range ebsBlockDevices { ebsAttrs := make(map[string]interface{}) @@ -1425,10 +1425,13 @@ func flattenEBSConfig(ebsBlockDevices []*emr.EbsBlockDevice) *schema.Set { ebsAttrs["type"] = *ebs.VolumeSpecification.VolumeType } ebsAttrs["volumes_per_instance"] = 1 - + uniqueEBS[resourceAwsEMRClusterEBSConfigHash(ebsAttrs)] += 1 ebsConfig = append(ebsConfig, ebsAttrs) } + for _, ebs := range ebsConfig { + ebs.(map[string]interface{})["volumes_per_instance"] = uniqueEBS[resourceAwsEMRClusterEBSConfigHash(ebs)] + } return schema.NewSet(resourceAwsEMRClusterEBSConfigHash, ebsConfig) } diff --git a/aws/resource_aws_emr_cluster_test.go b/aws/resource_aws_emr_cluster_test.go index b276318284e..d849595be07 100644 --- a/aws/resource_aws_emr_cluster_test.go +++ b/aws/resource_aws_emr_cluster_test.go @@ -1296,6 +1296,37 @@ func TestAccAWSEMRCluster_step_concurrency_level(t *testing.T) { }) } +func TestAccAWSEMRCluster_ebs_config(t *testing.T) { + var cluster emr.Cluster + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_emr_cluster.tf-test-cluster" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEmrDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEmrEbsConfig(rName, 2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEmrClusterExists(resourceName, &cluster), + resource.TestCheckResourceAttr(resourceName, "master_instance_group.0.ebs_config.0.volumes_per_instance", "2"), + resource.TestCheckResourceAttr(resourceName, "core_instance_group.0.ebs_config.0.volumes_per_instance", "2"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "cluster_state", // Ignore RUNNING versus WAITING changes + "configurations", + "keep_job_flow_alive_when_no_steps", + }, + }, + }, + }) +} + func TestAccAWSEMRCluster_custom_ami_id(t *testing.T) { var cluster emr.Cluster @@ -3397,3 +3428,48 @@ EOF } `, r) } + +func testAccAWSEmrEbsConfig(rName string, volumesPerInstance int) string { + return testAccAWSEmrComposeConfig(false, fmt.Sprintf(` +resource "aws_emr_cluster" "tf-test-cluster" { + applications = ["Spark"] + keep_job_flow_alive_when_no_steps = true + name = "%[1]s" + release_label = "emr-5.28.0" + service_role = "EMR_DefaultRole" + + ec2_attributes { + emr_managed_master_security_group = aws_security_group.test.id + emr_managed_slave_security_group = aws_security_group.test.id + instance_profile = "EMR_EC2_DefaultRole" + subnet_id = aws_subnet.test.id + } + + master_instance_group { + instance_type = "m4.large" + ebs_config { + size = 32 + type = "gp2" + volumes_per_instance = %[2]d + } + ebs_config { + size = 50 + type = "gp2" + volumes_per_instance = %[2]d + } + } + core_instance_group { + instance_count = 1 + instance_type = "m4.large" + ebs_config { + size = 32 + type = "gp2" + volumes_per_instance = %[2]d + } + } + + depends_on = [aws_route_table_association.test] +} +`, rName, volumesPerInstance), + ) +}