Skip to content

Commit

Permalink
resource/aws_emr_cluster: Implements step_concurrency_level
Browse files Browse the repository at this point in the history
    * Please vote on this pull request by adding a +1 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original pull request comment to help the community and maintainers prioritize this request

    * Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Closes #11159

Release note for [CHANGELOG](https://github.com/terraform-providers/terraform-provider-aws/blob/master/CHANGELOG.md):

```md
* resource/aws_emr_cluster: Support step concurrency level
```

Output from acceptance testing:

```
--- PASS: TestAccAWSEMRCluster_step_concurrency_level (538.64s)
```
  • Loading branch information
artburkart committed Dec 8, 2019
1 parent 1835280 commit bfaf44f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ func resourceAwsEMRCluster() *schema.Resource {
Optional: true,
ValidateFunc: validateAwsEmrCustomAmiId,
},
"step_concurrency_level": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 256),
},
},
}
}
Expand Down Expand Up @@ -842,6 +847,10 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error
params.CustomAmiId = aws.String(v.(string))
}

if v, ok := d.GetOk("step_concurrency_level"); ok {
params.StepConcurrencyLevel = aws.Int64(int64(v.(int)))
}

if instanceProfile != "" {
params.JobFlowRole = aws.String(instanceProfile)
}
Expand Down Expand Up @@ -1040,6 +1049,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("ebs_root_volume_size", cluster.EbsRootVolumeSize)
d.Set("scale_down_behavior", cluster.ScaleDownBehavior)
d.Set("termination_protection", cluster.TerminationProtected)
d.Set("step_concurrency_level", cluster.StepConcurrencyLevel)

if cluster.CustomAmiId != nil {
d.Set("custom_ami_id", cluster.CustomAmiId)
Expand Down Expand Up @@ -1339,6 +1349,18 @@ func resourceAwsEMRClusterUpdate(d *schema.ResourceData, meta interface{}) error
}
}

if d.HasChange("step_concurrency_level") {
d.SetPartial("step_concurrency_level")
_, errModify := conn.ModifyCluster(&emr.ModifyClusterInput{
ClusterId: aws.String(d.Id()),
StepConcurrencyLevel: aws.Int64(int64(d.Get("step_concurrency_level").(int))),
})
if errModify != nil {
log.Printf("[ERROR] %s", errModify)
return errModify
}
}

d.Partial(false)

return resourceAwsEMRClusterRead(d, meta)
Expand Down
60 changes: 60 additions & 0 deletions aws/resource_aws_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,39 @@ func TestAccAWSEMRCluster_root_volume_size(t *testing.T) {
})
}

func TestAccAWSEMRCluster_step_concurrency_level(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: testAccAWSEmrClusterConfigStepConcurrencyLevel(rName, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists(resourceName, &cluster),
resource.TestCheckResourceAttr(resourceName, "step_concurrency_level", "2"),
),
},
{
Config: testAccAWSEmrClusterConfigStepConcurrencyLevel(rName, 1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists(resourceName, &cluster),
resource.TestCheckResourceAttr(resourceName, "step_concurrency_level", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"configurations", "keep_job_flow_alive_when_no_steps"},
},
},
})
}

func TestAccAWSEMRCluster_custom_ami_id(t *testing.T) {
var cluster emr.Cluster
r := acctest.RandInt()
Expand Down Expand Up @@ -7616,3 +7649,30 @@ data "aws_ami" "emr-custom-ami" {
}
`, r, r, r, r, r, r, r, r)
}

func testAccAWSEmrClusterConfigStepConcurrencyLevel(rName string, stepConcurrencyLevel int) string {
return testAccAWSEmrClusterConfigBaseVpc(false) + fmt.Sprintf(`
resource "aws_emr_cluster" "tf-test-cluster" {
applications = ["Spark"]
keep_job_flow_alive_when_no_steps = true
name = %[1]q
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"
}
step_concurrency_level = %[2]d
depends_on = ["aws_route_table_association.test"]
}
`, rName, stepConcurrencyLevel)
}
1 change: 1 addition & 0 deletions website/docs/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ EOF
* `visible_to_all_users` - (Optional) Whether the job flow is visible to all IAM users of the AWS account associated with the job flow. Default `true`
* `autoscaling_role` - (Optional) An IAM role for automatic scaling policies. The IAM role provides permissions that the automatic scaling feature requires to launch and terminate EC2 instances in an instance group.
* `step` - (Optional) List of steps to run when creating the cluster. Defined below. It is highly recommended to utilize the [lifecycle configuration block](/docs/configuration/resources.html) with `ignore_changes` if other steps are being managed outside of Terraform. This argument is processed in [attribute-as-blocks mode](/docs/configuration/attr-as-blocks.html).
* `step_concurrency_level` - (Optional) The number of steps that can be executed concurrently. You can specify a maximum of 256 steps. Only valid for EMR clusters with `release_label` 5.28.0 or greater. (default is 1)
* `tags` - (Optional) list of tags to apply to the EMR Cluster

## core_instance_group Configuration Block
Expand Down

0 comments on commit bfaf44f

Please sign in to comment.