-
Notifications
You must be signed in to change notification settings - Fork 45
Giving some love to Spot instances #178
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Spot Instances Example | ||
|
|
||
| This example demonstrates how to configure the Spacelift worker pool to use EC2 spot instances for cost optimization. | ||
|
|
||
| > ⚠️ Spot instances are **NOT recommended for critical workloads** as they can be interrupted with only 2 minutes notice, potentially causing: | ||
| > - Incomplete or corrupted Terraform state | ||
| > - Failed deployments leaving infrastructure in inconsistent state | ||
| > - Loss of work-in-progress for long-running operations | ||
|
|
||
| ## Spot Instance Configuration | ||
|
|
||
| The key configuration for spot instances is: | ||
|
|
||
| ```hcl | ||
| instance_market_options = { | ||
| market_type = "spot" | ||
| spot_options = { | ||
| max_price = "0.05" # Maximum price per hour in USD | ||
| spot_instance_type = "one-time" | ||
| instance_interruption_behavior = "terminate" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Configuration Options | ||
|
|
||
| - **max_price** (Optional): Maximum hourly price you're willing to pay. AWS recommends omitting this to use current Spot pricing, as setting a lower price can increase interruption frequency. | ||
| - **spot_instance_type**: Use `"one-time"` for Auto Scaling Groups (recommended) or `"persistent"` for individual instances. | ||
| - **instance_interruption_behavior**: How instances behave when interrupted - `"terminate"` (default), `"stop"`, or `"hibernate"`. For AutoScaling Groups, it's recommended to use `"terminate"`, as the ASG handles replacements automatically. | ||
|
|
||
| These options use sensible defaults when omitted, so **explicit configuration is typically unnecessary**. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| terraform { | ||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = ">= 6.0.0" | ||
| } | ||
|
|
||
| random = { source = "hashicorp/random" } | ||
| } | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = "eu-west-1" | ||
|
|
||
| default_tags { | ||
| tags = { | ||
| TfModule = "terraform-aws-spacelift-workerpool-on-ec2" | ||
| TestCase = "spot-instances" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| data "aws_vpc" "this" { | ||
| default = true | ||
| } | ||
|
|
||
| data "aws_security_group" "this" { | ||
| name = "default" | ||
| vpc_id = data.aws_vpc.this.id | ||
| } | ||
|
|
||
| data "aws_subnets" "this" { | ||
| filter { | ||
| name = "vpc-id" | ||
| values = [data.aws_vpc.this.id] | ||
| } | ||
| } | ||
|
|
||
| resource "random_string" "worker_pool_id" { | ||
| length = 26 | ||
| numeric = true | ||
| # Use special and override special to allow only uppercase letters and numbers | ||
| # but exclude I, L, O, and U as it does not conform to the regex used by Spacelift | ||
| special = true | ||
| override_special = "ABCDEFGHJKMNPQRSTVWXYZ" | ||
| lower = false | ||
| upper = false | ||
| } | ||
|
|
||
| #### Spacelift worker pool with spot instances #### | ||
|
|
||
| module "this" { | ||
| source = "../../" | ||
|
|
||
| secure_env_vars = { | ||
| SPACELIFT_TOKEN = "<token-here>" | ||
| SPACELIFT_POOL_PRIVATE_KEY = "<private-key-here>" | ||
| } | ||
| security_groups = [data.aws_security_group.this.id] | ||
| vpc_subnets = data.aws_subnets.this.ids | ||
| worker_pool_id = random_string.worker_pool_id.id | ||
|
|
||
| # Enable spot instances | ||
| instance_market_options = { | ||
| market_type = "spot" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is a recent development in the worker code that I did last night. I'm still testing it.
Uh oh!
There was an error while loading. Please reload this page.
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.
just tested it and it works :)