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

Feat : EC2 manage spot options for instance tagging #31495

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5f80695
Feat : EC2 manage spot options for instance tagging
sousmangoosta May 19, 2023
01f868d
Doc : Add EC2 instance spot options documentation
sousmangoosta May 30, 2023
8e296b9
Fix : Permit spot instances import
sousmangoosta May 31, 2023
1f5c27f
Test : Add basic test for instance with spot mode
sousmangoosta May 31, 2023
5b304c8
Merge branch 'main' into HEAD
ewbankkit Jun 5, 2023
42decdb
Add CHANGELOG entry.
ewbankkit Jun 5, 2023
f500091
Use constants from AWS Go SDK.
ewbankkit Jun 5, 2023
fb04bcc
Add 'WaitSpotInstanceRequestFulfilled' and friends.
ewbankkit Jun 5, 2023
26f306f
r/aws_spot_instance_request: Tidy up resource Create.
ewbankkit Jun 5, 2023
fd10764
r/aws_spot_instance_request: Tidy up resource Delete.
ewbankkit Jun 5, 2023
b96ad4c
Fix typo.
ewbankkit Jun 5, 2023
77fe8cb
r/aws_spot_instance_request: Alphabetize attributes.
ewbankkit Jun 5, 2023
21e0f04
r/aws_spot_instance_request: Remove instance attributes added for spo…
ewbankkit Jun 5, 2023
78d3ab1
r/aws_instance: Tidy up setting 'instance_market_options'.
ewbankkit Jun 5, 2023
fd2b5bb
r/aws_instance: 'instance_market_options' is ForceNew.
ewbankkit Jun 5, 2023
b1dc702
r/aws_instance: 'instance_market_options.max_price' is Computed.
ewbankkit Jun 5, 2023
c93e4d9
Tweak recommendation for replacing 'aws_spot_instance_request'.
ewbankkit Jun 5, 2023
e4893c6
r/aws_instance: Remove defaults for 'instance_market_options'.
ewbankkit Jun 6, 2023
f962712
r/aws_instance: 'instance_market_options' itself is Computed.
ewbankkit Jun 6, 2023
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
7 changes: 4 additions & 3 deletions internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ func ResourceInstance() *schema.Resource {
"market_type": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the market_type need to be Required here, and set as required with value spot in the documentation as we removed the Default value ?

Copy link
Contributor

@ewbankkit ewbankkit Jun 6, 2023

Choose a reason for hiding this comment

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

No it doesn't, but the fact that instance_market_options and all it's sub-attributes are Computed (so as to avoid diffs and resource replacement if the instance uses a launch template that specifies instance_market_options) means that instance_market_options {} in configuration is now ignored. That's why I had to change the new test case to add en explicit market_type = "spot".

Computed: true,
ForceNew: true,
Default: ec2.MarketTypeSpot,
ValidateFunc: validation.StringInSlice(ec2.MarketType_Values(), false),
},
"spot_options": {
Expand All @@ -410,8 +410,8 @@ func ResourceInstance() *schema.Resource {
"instance_interruption_behavior": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Default: ec2.InstanceInterruptionBehaviorTerminate,
ValidateFunc: validation.StringInSlice(ec2.InstanceInterruptionBehavior_Values(), false),
},
"max_price": {
Expand All @@ -429,13 +429,14 @@ func ResourceInstance() *schema.Resource {
"spot_instance_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Default: ec2.SpotInstanceTypeOneTime,
ValidateFunc: validation.StringInSlice(ec2.SpotInstanceType_Values(), false),
},
"valid_until": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: verify.ValidUTCTimestamp,
},
Expand Down
7 changes: 6 additions & 1 deletion internal/service/ec2/ec2_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8897,8 +8897,13 @@ func testAccInstanceConfig_basicWithSpot(rName string) string {
fmt.Sprintf(`
resource "aws_instance" "test" {
ami = data.aws_ami.amzn2-ami-minimal-hvm-ebs-arm64.id
instance_market_options {}

instance_market_options {
market_type = "spot"
}

instance_type = data.aws_ec2_instance_type_offering.available.instance_type

tags = {
Name = %[1]q
}
Expand Down