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

Conversation

csghuser
Copy link
Contributor

@csghuser csghuser commented Jan 19, 2018

This provides the ability to configure the scale down behavior of a cluster. From the docs:

ScaleDownBehavior
The way that individual Amazon EC2 instances terminate when an automatic scale-in activity occurs or an instance group is resized. TERMINATE_AT_INSTANCE_HOUR indicates that Amazon EMR terminates nodes at the instance-hour boundary, regardless of when the request to terminate the instance was submitted. This option is only available with Amazon EMR 5.1.0 and later and is the default for clusters created using that version. TERMINATE_AT_TASK_COMPLETION indicates that Amazon EMR blacklists and drains tasks from nodes before terminating the Amazon EC2 instances, regardless of the instance-hour boundary. With either behavior, Amazon EMR removes the least active nodes first and blocks instance termination if it could lead to HDFS corruption. TERMINATE_AT_TASK_COMPLETION available only in Amazon EMR version 4.1.0 and later, and is the default for versions of Amazon EMR earlier than 5.1.0.

Type: String

Valid Values: TERMINATE_AT_INSTANCE_HOUR | TERMINATE_AT_TASK_COMPLETION

Required: No

Source: https://docs.aws.amazon.com/emr/latest/APIReference/API_JobFlowDetail.html

I've added a test which attempts to set the value to TERMINATE_AT_INSTANCE_HOUR for a cluster version of 5.5.0. This is the default for this version, but I didn't want to interfere with the tests as it may prevent the cluster from shutting down should any tasks be running.

I've not yet been able to run this against AWS to test.

@radeksimko radeksimko changed the title Adding scale_down_behavior resource/aws_emr_cluster: Add scale_down_behavior Jan 19, 2018
@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. service/emr Issues and PRs that pertain to the emr service. labels Jan 19, 2018
@csghuser
Copy link
Contributor Author

I've been able to test this. The tests are failing however. If scale_down_behavior is not set (as it is optional), after cluster creation, when reading the state, it wants to set this value back to an empty string.

 scale_down_behavior: "TERMINATE_AT_TASK_COMPLETION" => "" (forces new resource)

So whilst we are not setting this, it gets defined at cluster creation by AWS. I'm just looking through the code to see how this can be avoided.

@csghuser
Copy link
Contributor Author

I've added some logic to check whether or not the user has defined this new variable. If not then we rely on the default for the EMR version. This seems like a better approach, as opposed to hard coding the following logic into the code:

if release_label >=  5.1.0 
  default = TERMINATE_AT_INSTANCE_HOUR
else if (release_label >= 4.1.0 AND release_label < 5.1.0)
  default = TERMINATE_AT_TASK_COMPLETION
end

As its possible this may change at some point and a new default would be introduced with a later version.

@ghost ghost added the size/XXL Managed by automation to categorize the size of a PR. label Feb 5, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/XXL Managed by automation to categorize the size of a PR. labels Feb 5, 2018
@ghost ghost added size/S Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels Feb 5, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Hi @csghuser thanks for contributing this! Check out my comments below and let me know if you have any questions or don't have time to finish this up. 😄

We should also add a new acceptance test to cover this new attribute. At least something like on the _basic test:

resource.TestCheckResourceAttrSet("aws_emr_cluster.tf-test-cluster", "scale_down_behavior")

And more preferably a new test that actually tries setting it and confirming its correct.

@@ -475,6 +485,11 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
}

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

if d.Get("scale_down_behavior").(string) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this check by setting Computed: true on the attribute 😄

@@ -225,6 +225,11 @@ 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)

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Feb 15, 2018
@ghost ghost added the size/S Managed by automation to categorize the size of a PR. label Feb 16, 2018
@csghuser
Copy link
Contributor Author

@bflad Many thanks for your pointers, very much appreciated. I've addressed each one and reran the basic test, which seems to pass fine. It also passes if no scale_down_behavior config option is set now that the "computed" attribute is set, as you suggested 😃

Would it be possible to check if everything looks ok?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Two little things then we can get this in, thanks so much!

@@ -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! 😄

Check: testAccCheckAWSEmrClusterExists("aws_emr_cluster.tf-test-cluster", &cluster),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists("aws_emr_cluster.tf-test-cluster", &cluster),
resource.TestCheckResourceAttrSet("aws_emr_cluster.tf-test-cluster", "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.

Since we know the value (hardcoded in the config below), lets actually check it. 😄

resource.TestCheckResourceAttr("aws_emr_cluster.tf-test-cluster", "scale_down_behavior", "TERMINATE_AT_TASK_COMPLETION"),

csghuser and others added 4 commits February 17, 2018 08:49
…means the AWS default for the release_label will be used, unless the user wants to override this
…idation function, added test to basic cluster
@ghost ghost added the size/S Managed by automation to categorize the size of a PR. label Feb 17, 2018
@csghuser
Copy link
Contributor Author

@bflad I've made the modifications as requested 😃 I've reran the tests, seems to run ok.

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Feb 19, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks so much! 🚀

=== RUN   TestAccAWSEMRCluster_security_config
--- PASS: TestAccAWSEMRCluster_security_config (403.06s)
=== RUN   TestAccAWSEMRCluster_terminationProtected
--- PASS: TestAccAWSEMRCluster_terminationProtected (432.92s)
=== RUN   TestAccAWSEMRCluster_basic
--- PASS: TestAccAWSEMRCluster_basic (509.79s)
=== RUN   TestAccAWSEMRCluster_bootstrap_ordering
--- PASS: TestAccAWSEMRCluster_bootstrap_ordering (525.05s)
=== RUN   TestAccAWSEMRCluster_instance_group
--- PASS: TestAccAWSEMRCluster_instance_group (537.89s)
=== RUN   TestAccAWSEMRCluster_custom_ami_id
--- PASS: TestAccAWSEMRCluster_custom_ami_id (579.84s)
=== RUN   TestAccAWSEMRCluster_s3Logging
--- PASS: TestAccAWSEMRCluster_s3Logging (639.13s)
=== RUN   TestAccAWSEMRCluster_visibleToAllUsers
--- PASS: TestAccAWSEMRCluster_visibleToAllUsers (978.19s)
=== RUN   TestAccAWSEMRCluster_root_volume_size
--- PASS: TestAccAWSEMRCluster_root_volume_size (1022.69s)
=== RUN   TestAccAWSEMRCluster_tags
--- PASS: TestAccAWSEMRCluster_tags (1076.23s)

@bflad bflad added this to the v1.10.0 milestone Feb 19, 2018
@bflad bflad merged commit 973c4ad into hashicorp:master Feb 19, 2018
bflad added a commit that referenced this pull request Feb 19, 2018
@bflad
Copy link
Contributor

bflad commented Feb 27, 2018

This has been released in version 1.10.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@csghuser
Copy link
Contributor Author

@bflad Thanks! 😄

@ghost
Copy link

ghost commented Apr 7, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/emr Issues and PRs that pertain to the emr service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants