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

fix issue-10446, add test case for ebs_config.volumes_per_instance check #14858

Merged
merged 3 commits into from
Aug 28, 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
7 changes: 5 additions & 2 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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)
}

Expand Down
76 changes: 76 additions & 0 deletions aws/resource_aws_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
)
}