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 1 commit
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
3 changes: 1 addition & 2 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,7 @@ func flattenEBSConfig(ebsBlockDevices []*emr.EbsBlockDevice) *schema.Set {
if ebs.VolumeSpecification.VolumeType != nil {
ebsAttrs["type"] = *ebs.VolumeSpecification.VolumeType
}
ebsAttrs["volumes_per_instance"] = 1

ebsAttrs["volumes_per_instance"] = len(ebsBlockDevices)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to specify multiple ebs_config (multiple configurations with 1 or more volumes per instance)? e.g.

  master_instance_group {
    instance_type = "m4.large"

    ebs_config {
      size                 = 32
      type                 = "gp2"
      volumes_per_instance = 2
    }

    ebs_config {
      size                 = 50
      type                 = "gp2"
      volumes_per_instance = 2
    }
  }

If so, the volumes_per_instance needs to be calculated per configurations type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an issue here. The volumes_per_instance is an attribute of ebs_config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I get what you're saying.
I updated the PR and test case
but we can not dealing with 2 same ebs_config config like this

  master_instance_group {
    instance_type = "m4.large"

    ebs_config {
      size                 = 32
      type                 = "gp2"
      volumes_per_instance = 2
    }

    ebs_config {
      size                 = 32
      type                 = "gp2"
      volumes_per_instance = 1
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not being able to handle that last configuration there is okay -- seems reasonable to say that should have one ebs_config with volumes_per_instance = 3 👍 Also thank you for adding the additional configuration to the test case!

ebsConfig = append(ebsConfig, ebsAttrs)
}

Expand Down
72 changes: 72 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,44 @@ 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
}
}

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),
)
}