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

fix: adding support for opt-in regions and arm architecture #106

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .spacelift/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1
module_version: 2.6.4
module_version: 2.6.5
tests:
- name: AMD64-based workerpool
project_root: examples/amd64
Expand Down
27 changes: 21 additions & 6 deletions ami.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
data "aws_ami" "this" {
most_recent = true
name_regex = "^spacelift-\\d{10}-x86_64$"
owners = ["643313122712"]
# get info about selected instance type
data "aws_ec2_instance_type" "spacelift" {
instance_type = var.ec2_instance_type
}

# get list of spacelift AMI ids starting with the newest
data "aws_ami_ids" "spacelift" {
sort_ascending = false
name_regex = "^spacelift-\\d{10}-(arm64|x86_64)$"
owners = ["643313122712"]

filter {
name = "root-device-type"
Expand All @@ -14,7 +20,16 @@ data "aws_ami" "this" {
}

filter {
name = "architecture"
values = ["x86_64"]
name = "architecture"
# get ami architecture based on selected instance type (arm64 or x86_64).
values = [for arch in data.aws_ec2_instance_type.spacelift.supported_architectures : arch if can(regex("(arm64|x86_64)$", arch))]
}

lifecycle {
# Check if Spacelift AMI exists in current region. Spacelift AMIs are not replicated for all regions.
postcondition {
condition = coalesce(var.ami_id, try(self.ids[0], "ami_not_found")) != "ami_not_found"
error_message = "No Spacelift AMI found in current region '${data.aws_region.this.name}'. Use 'var.ami_id' instead to provide an existing Spacelift AMI."
}
}
}
11 changes: 6 additions & 5 deletions asg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ module "asg" {
name = local.base_name

iam_instance_profile_arn = aws_iam_instance_profile.this.arn
image_id = var.ami_id != "" ? var.ami_id : data.aws_ami.this.id
instance_type = var.ec2_instance_type
security_groups = var.security_groups
enable_monitoring = var.enable_monitoring
instance_refresh = var.instance_refresh
# if 'var.ami_id' is empty, get AMI from data source. data source lifecycle postcondition fails if no ami exists.
image_id = coalesce(var.ami_id, try(data.aws_ami_ids.spacelift.ids[0], "ami_not_found"))
instance_type = var.ec2_instance_type
security_groups = var.security_groups
enable_monitoring = var.enable_monitoring
instance_refresh = var.instance_refresh

block_device_mappings = [
{
Expand Down