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

resource/aws_emr_cluster: Implements step_concurrency_level #11196

Merged
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
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