diff --git a/aws/resource_aws_emr_cluster.go b/aws/resource_aws_emr_cluster.go index 2cec704bee29..f5048e71ef70 100644 --- a/aws/resource_aws_emr_cluster.go +++ b/aws/resource_aws_emr_cluster.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/structure" + "github.com/hashicorp/terraform/helper/validation" ) func resourceAwsEMRCluster() *schema.Resource { @@ -236,6 +237,16 @@ func resourceAwsEMRCluster() *schema.Resource { ForceNew: true, Required: true, }, + "scale_down_behavior": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + emr.ScaleDownBehaviorTerminateAtInstanceHour, + emr.ScaleDownBehaviorTerminateAtTaskCompletion, + }, false), + }, "security_configuration": { Type: schema.TypeString, ForceNew: true, @@ -363,10 +374,15 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("log_uri"); ok { params.LogUri = aws.String(v.(string)) } + if v, ok := d.GetOk("autoscaling_role"); ok { params.AutoScalingRole = aws.String(v.(string)) } + if v, ok := d.GetOk("scale_down_behavior"); ok { + params.ScaleDownBehavior = aws.String(v.(string)) + } + if v, ok := d.GetOk("security_configuration"); ok { params.SecurityConfiguration = aws.String(v.(string)) } @@ -486,6 +502,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error { } d.Set("name", cluster.Name) + d.Set("service_role", cluster.ServiceRole) d.Set("security_configuration", cluster.SecurityConfiguration) d.Set("autoscaling_role", cluster.AutoScalingRole) @@ -495,6 +512,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("visible_to_all_users", cluster.VisibleToAllUsers) d.Set("tags", tagsToMapEMR(cluster.Tags)) d.Set("ebs_root_volume_size", cluster.EbsRootVolumeSize) + d.Set("scale_down_behavior", cluster.ScaleDownBehavior) if cluster.CustomAmiId != nil { d.Set("custom_ami_id", cluster.CustomAmiId) diff --git a/aws/resource_aws_emr_cluster_test.go b/aws/resource_aws_emr_cluster_test.go index 96fcc31f881a..17cacac70342 100644 --- a/aws/resource_aws_emr_cluster_test.go +++ b/aws/resource_aws_emr_cluster_test.go @@ -24,7 +24,10 @@ func TestAccAWSEMRCluster_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAWSEmrClusterConfig(r), - Check: testAccCheckAWSEmrClusterExists("aws_emr_cluster.tf-test-cluster", &cluster), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEmrClusterExists("aws_emr_cluster.tf-test-cluster", &cluster), + resource.TestCheckResourceAttr("aws_emr_cluster.tf-test-cluster", "scale_down_behavior", "TERMINATE_AT_TASK_COMPLETION"), + ), }, }, }) @@ -707,6 +710,8 @@ resource "aws_emr_cluster" "tf-test-cluster" { keep_job_flow_alive_when_no_steps = true termination_protection = false + scale_down_behavior = "TERMINATE_AT_TASK_COMPLETION" + bootstrap_action { path = "s3://elasticmapreduce/bootstrap-actions/run-if" name = "runif" diff --git a/website/docs/r/emr_cluster.html.markdown b/website/docs/r/emr_cluster.html.markdown index 146464e4b515..1da1ee8f1949 100644 --- a/website/docs/r/emr_cluster.html.markdown +++ b/website/docs/r/emr_cluster.html.markdown @@ -112,6 +112,7 @@ The following arguments are supported: * `name` - (Required) The name of the job flow * `release_label` - (Required) The release label for the Amazon EMR release * `master_instance_type` - (Optional) The EC2 instance type of the master node. Exactly one of `master_instance_type` and `instance_group` must be specified. +* `scale_down_behavior` - (Optional) The way that individual Amazon EC2 instances terminate when an automatic scale-in activity occurs or an `instance group` is resized. * `service_role` - (Required) IAM role that will be assumed by the Amazon EMR service to access AWS resources * `security_configuration` - (Optional) The security configuration name to attach to the EMR cluster. Only valid for EMR clusters with `release_label` 4.8.0 or greater * `core_instance_type` - (Optional) The EC2 instance type of the slave nodes. Cannot be specified if `instance_groups` is set