-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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_spot_instance_request: Fix being able to stop requests #1986
resource/aws_spot_instance_request: Fix being able to stop requests #1986
Conversation
40d6708
to
11584aa
Compare
I was considering adding a simple validate function on the instance interruption behaviours as well (because plan time failures are always nicer than apply time failures when you typo something) and then spotted that we have The British part of me wants to change the docs to |
US Spelling to match the AWS API and the docs. While this is technically a breaking change this didn't work anyway. See discussion at hashicorp#1986 (comment)
I decided to go ahead with the "breaking" change considering it didn't work anyway this seems like the best solution instead of leaving it as is and updating docs or adding the US spelling and deprecating |
It might be worth deprecating the Also if the validator is kept from here we need to add whatever the enum value is for |
I've migrated away from spot instance requests directly to only using spot instances in ASGs so have no real need for this anymore but it might still be useful for others if anyone is happy to review this pull request? I still feel like the |
I would like to see this fixed. Between the spelling mismatch in documentation and being consistent with the AWS API, I agree with removing the 'u'. I've merged this PR into my fork and have added a little code for the hibernate option. I tested the 'stop' support and it is working for my usage. I have not tested the 'hibernate' option. |
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.
Let's leave the attribute deprecation and renaming for another PR so we can get the actual fix in. 👍
@@ -78,11 +78,12 @@ func resourceAwsSpotInstanceRequest() *schema.Resource { | |||
Optional: true, | |||
ForceNew: true, | |||
} | |||
s["instance_interruption_behaviour"] = &schema.Schema{ |
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 we please save this breaking change for another PR? It'll need to be handled in the 2.0.0 upgrade when that occurs. In the meantime, we should deprecate the existing attribute (but that change can be made separately).
s["instance_interruption_behavior"] = &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "terminate", |
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.
Nitpick: SDK provided constant available: ec2.InstanceInterruptionBehaviorTerminate
Optional: true, | ||
Default: "terminate", | ||
ForceNew: true, | ||
ValidateFunc: validateInstanceInterruptionBehavior, |
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.
Nitpick: Custom function can be removed for:
ValidateFunc: validation.StringInSlice([]string{
ec2.InstanceInterruptionBehaviorStop,
ec2.InstanceInterruptionBehaviorTerminate,
}, false),
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.
There is also ec2.InstanceInterruptionBehaviorHibernate,
available.
Still want the change separating when it's currently broken anyway? I'd definitely agree if it was working but it has never worked so I don't think we have to worry about breaking changes here and it's then simpler to fix both things in one go. Or separate them and merge the "breaking" change first without incrementing the major version and then merge the fix. Agree with all the other changes requested, good spots so thanks for that. Happy to add the hibernate that was added since I raised this PR a while back too. |
@@ -132,6 +132,11 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface | |||
spotOpts.LaunchGroup = aws.String(v.(string)) | |||
} | |||
|
|||
// Placement GroupName can only be specified when instanceInterruptionBehavior is not set to 'stop' | |||
if v, exists := d.GetOkExists("instance_interruption_behavior"); v == "terminate" || !exists { |
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.
I think this needs to be v.(string) == ec2.InstanceInterruptionBehaviorTerminate
Sorry if I'm being dense, but I don't understand where this is coming from:
It looks like the attribute was passed in just fine before with the old (incorrectly documented) name. Plenty of people could have changed their configurations to use the different spelling and it should have worked just fine for them, unless I'm missing something. |
For reference, people could have found this issue and adjusted their configurations: #2670 |
PR to fix the documentation: #4195 |
@bflad it's been a long time since I checked but as mentioned in the comment at https://github.com/terraform-providers/terraform-provider-aws/pull/1986/files#diff-f369c2449430a1386c70cf98c181c5a3R135 and this comment on the initial PR that added it #1735 (comment) it doesn't work at all with setting the stop behaviour because the AWS API returns the following:
I can check again now though to see if the API has changed since but I'd be surprised if that is the case. |
I guess technically someone might be using it to directly specify they want it to |
b7f61f2
to
47c2b6d
Compare
47c2b6d
to
807f7fd
Compare
807f7fd
to
589c58d
Compare
HIbernating instances requires c3/c4/c5/m4/m5/r3/r4 instance types so we need to bump the instance size to a c5.large which is the cheapest instance out of those families.
@bflad I've removed the breaking change, rebased on master and squashed my commits. Thanks for the review and comments earlier, and sorry it's taken a while to find time to address the feedback. I've also added a test for hibernating instances and expanded the validation for that to work. If you'd rather I can split that commit out to a different PR to make the PR as small as possible. Did you also want me to raise a PR with the breaking change to move things over to |
Hi! |
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.
Thanks for the update @tomelliff! LGTM 🚀 We can add apply-time or plan-time validation of the termination case if necessary later.
9 tests passed (all tests)
=== RUN TestAccAWSSpotInstanceRequest_basic
--- PASS: TestAccAWSSpotInstanceRequest_basic (98.17s)
=== RUN TestAccAWSSpotInstanceRequest_withLaunchGroup
--- PASS: TestAccAWSSpotInstanceRequest_withLaunchGroup (110.07s)
=== RUN TestAccAWSSpotInstanceRequest_withBlockDuration
--- PASS: TestAccAWSSpotInstanceRequest_withBlockDuration (117.99s)
=== RUN TestAccAWSSpotInstanceRequest_SubnetAndSGAndPublicIpAddress
--- PASS: TestAccAWSSpotInstanceRequest_SubnetAndSGAndPublicIpAddress (199.24s)
=== RUN TestAccAWSSpotInstanceRequest_NetworkInterfaceAttributes
--- PASS: TestAccAWSSpotInstanceRequest_NetworkInterfaceAttributes (212.57s)
=== RUN TestAccAWSSpotInstanceRequest_vpc
--- PASS: TestAccAWSSpotInstanceRequest_vpc (213.23s)
=== RUN TestAccAWSSpotInstanceRequestInterruptHibernate
--- PASS: TestAccAWSSpotInstanceRequestInterruptHibernate (275.24s)
=== RUN TestAccAWSSpotInstanceRequestInterruptStop
--- PASS: TestAccAWSSpotInstanceRequestInterruptStop (277.36s)
=== RUN TestAccAWSSpotInstanceRequest_getPasswordData
--- PASS: TestAccAWSSpotInstanceRequest_getPasswordData (305.40s)
@bflad thanks again for the review and merge. I'm not sure I follow about the validation as there is validation for all 3 behaviours right now ( And did you want me to raise the breaking change PR to move things to use |
We can provide an error (and acceptance test that error) if there is an invalid configuration (defining
If you so desire. The first PR should support both the old and new attribute names (using |
This has been released in version 1.15.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
As mentioned in #1735 (comment) this was failing locally for me.
Fixes an issue when setting the instance interruption behaviour to anything other than terminate (hibernate has since been added but not included in this PR) and adds a test to cover it.