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: Add scale_down_behavior #3063

Merged
merged 4 commits into from
Feb 19, 2018
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
18 changes: 18 additions & 0 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -236,6 +237,16 @@ func resourceAwsEMRCluster() *schema.Resource {
ForceNew: true,
Required: true,
},
"scale_down_behavior": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a validation function for this please? e.g.
ValidateFunc: validation.StringInSlice([]string{emr.ScaleDownBehaviorTerminateAtInstanceHour, emr.ScaleDownBehaviorTerminateAtTaskCompletion}, false)

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,
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -486,6 +502,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("name", cluster.Name)

Copy link
Contributor

Choose a reason for hiding this comment

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

We do still want the d.Set("scale_down_behavior", cluster.ScaleDownBehavior) here so Terraform is always updating its state correctly from the API each read as well as on import. We just didn't need the wrapping if d.Get() check that was previously in the PR. Sorry I wasn't more clear about what I meant earlier! 😄

d.Set("service_role", cluster.ServiceRole)
d.Set("security_configuration", cluster.SecurityConfiguration)
d.Set("autoscaling_role", cluster.AutoScalingRole)
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion aws/resource_aws_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
})
Expand Down Expand Up @@ -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"
Expand Down
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 @@ -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
Expand Down