Skip to content

Commit 4f4b845

Browse files
committed
add example
1 parent 5b84e61 commit 4f4b845

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

examples/multi-runner/main.tf

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
data "aws_ssm_parameter" "al2023_arm" {
1+
# The module provides several ways to chose the AMI ID for the runners. The recommended way is to use the SSM parameter ARN.
2+
# The default is (still) a build in filter that creates internally an SSM parameter for the AMI ID.
3+
#
4+
# Here we show two other options
5+
# 1. Use the SSM parameter ARN directly via a public available SSM parameter
6+
# 2. Use the SSM parameter ARN via a private SSM parameter injected to the module
7+
# 3. Other runners like ubuntu, windows, etc. are using the build in one parameter.
8+
9+
data "aws_ssm_parameter" "al2023_x64" {
210
name = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64"
311
}
412

13+
data "aws_ssm_parameter" "al2023_arm64" {
14+
name = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-arm64"
15+
}
16+
17+
resource "aws_ssm_parameter" "al2023_arm64" {
18+
name = local.al2023_arm64_name
19+
type = "String"
20+
data_type = "aws:ec2:image"
21+
value = data.aws_ssm_parameter.al2023_arm64.value
22+
}
23+
24+
data "aws_caller_identity" "current" {}
25+
526
locals {
627
environment = var.environment != null ? var.environment : "multi-runner"
728
aws_region = var.aws_region
829

9-
# create map only with amazon linux 2023 x64 ami id
10-
ssm_ami_ids = {
11-
"linux-x64" = data.aws_ssm_parameter.al2023_arm.arn
30+
# create map only with amazon linux 2023 x64 and arm64 to overwrite the default
31+
al2023_arm64_name = "/examples/multi-runner/aws-github-runners/ami/amazon-linux-2023-arm64"
32+
ssm_ami_arns = {
33+
"linux-x64" = data.aws_ssm_parameter.al2023_x64.arn
34+
# construct the arn to avoid terraform count errors
35+
"linux-arm64" = "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter${local.al2023_arm64_name}"
1236
}
1337

1438
# Load runner configurations from Yaml files
@@ -17,6 +41,7 @@ locals {
1741

1842
trimsuffix(c, ".yaml") => yamldecode(file("${path.module}/templates/runner-configs/${c}"))
1943
}
44+
2045
multi_runner_config = {
2146
for k, v in local.multi_runner_config_files :
2247

@@ -28,7 +53,7 @@ locals {
2853
{
2954
subnet_ids = lookup(v.runner_config, "subnet_ids", null) != null ? [module.base.vpc.private_subnets[0]] : null
3055
vpc_id = lookup(v.runner_config, "vpc_id", null) != null ? module.base.vpc.vpc_id : null
31-
ami_id_ssm_parameter_arn = lookup(local.ssm_ami_ids, k, null) != null ? local.ssm_ami_ids[k] : null
56+
ami_id_ssm_parameter_arn = lookup(local.ssm_ami_arns, k, null) != null ? local.ssm_ami_arns[k] : null
3257
}
3358
)
3459
}

examples/multi-runner/templates/runner-configs/linux-arm64.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ runner_config:
1515
instance_types:
1616
- t4g.large
1717
- c6g.large
18+
ami_id_ssm_parameter_arn: ${ami_id_ssm_parameter_arn}
1819
runners_maximum_count: 1
1920
delay_webhook_event: 0
2021
scale_down_schedule_expression: cron(* * * * ? *)

0 commit comments

Comments
 (0)