-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
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.
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. |
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:
As its possible this may change at some point and a new default would be introduced with a later version. |
cc4244f
to
f4435b2
Compare
f4435b2
to
d0a8bc9
Compare
There was a problem hiding this 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.
aws/resource_aws_emr_cluster.go
Outdated
@@ -475,6 +485,11 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error { | |||
} | |||
|
|||
d.Set("name", cluster.Name) | |||
|
|||
if d.Get("scale_down_behavior").(string) != "" { |
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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)
d0a8bc9
to
48ac8b3
Compare
@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? |
There was a problem hiding this 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) | |||
|
There was a problem hiding this comment.
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! 😄
aws/resource_aws_emr_cluster_test.go
Outdated
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"), |
There was a problem hiding this comment.
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"),
…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
…ale_down_behavior is set.
b752894
to
dac38a9
Compare
@bflad I've made the modifications as requested 😃 I've reran the tests, seems to run ok. |
There was a problem hiding this 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)
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. |
@bflad Thanks! 😄 |
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! |
This provides the ability to configure the scale down behavior of a cluster. From the docs:
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.