Skip to content

Commit 1fa930c

Browse files
committed
refactor(ami-updater): standardize module structure and zip file handling
- update zip file location in package.json to match other modules - add ami-updater module configuration in root main.tf with consistent variable mapping - add ami_updater_lambda variables in root variables.tf for zip, memory and timeout - enable optional ami-updater functionality through enable_ami_updater variable
1 parent 41d3858 commit 1fa930c

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

lambdas/functions/ami-updater/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint src",
1212
"watch": "ts-node-dev --respawn --exit-child src/local.ts",
1313
"build": "ncc build src/lambda.ts -o dist",
14-
"dist": "yarn build && cp package.json dist/ && cd dist && zip ../dist/ami-updater.zip *",
14+
"dist": "yarn build && cp package.json dist/ && cd dist && zip ../ami-updater.zip *",
1515
"format": "prettier --write \"**/*.ts\"",
1616
"format-check": "prettier --check \"**/*.ts\"",
1717
"all": "yarn build && yarn format && yarn lint && yarn test"

main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,53 @@ module "ami_housekeeper" {
353353
lambda_schedule_expression = var.ami_housekeeper_lambda_schedule_expression
354354
}
355355

356+
module "ami_updater" {
357+
count = var.enable_ami_updater ? 1 : 0
358+
source = "./modules/ami-updater"
359+
360+
prefix = var.prefix
361+
tags = local.tags
362+
aws_partition = var.aws_partition
363+
364+
lambda_zip = var.ami_updater_lambda_zip
365+
lambda_memory_size = var.ami_updater_lambda_memory_size
366+
lambda_timeout = var.ami_updater_lambda_timeout
367+
lambda_s3_bucket = var.lambda_s3_bucket
368+
lambda_runtime = var.lambda_runtime
369+
lambda_architecture = var.lambda_architecture
370+
371+
lambda_subnet_ids = var.lambda_subnet_ids
372+
lambda_security_group_ids = var.lambda_security_group_ids
373+
lambda_tags = var.lambda_tags
374+
tracing_config = var.tracing_config
375+
376+
logging_retention_in_days = var.logging_retention_in_days
377+
logging_kms_key_id = var.logging_kms_key_id
378+
log_level = var.log_level
379+
380+
role_path = var.role_path
381+
role_permissions_boundary = var.role_permissions_boundary
382+
383+
ssm_parameter_name = var.ami_id_ssm_parameter_name
384+
385+
config = {
386+
dry_run = false
387+
ami_filter = {
388+
owners = var.ami_owners
389+
filters = [
390+
{
391+
name = "state"
392+
values = ["available"]
393+
},
394+
{
395+
name = "image-type"
396+
values = ["machine"]
397+
}
398+
]
399+
}
400+
}
401+
}
402+
356403
locals {
357404
lambda_instance_termination_watcher = {
358405
prefix = var.prefix

variables.tf

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ variable "enable_organization_runners" {
3333

3434
variable "github_app" {
3535
description = <<EOF
36-
GitHub app parameters, see your github app.
36+
GitHub app parameters, see your github app.
3737
You can optionally create the SSM parameters yourself and provide the ARN and name here, through the `*_ssm` attributes.
38-
If you chose to provide the configuration values directly here,
38+
If you chose to provide the configuration values directly here,
3939
please ensure the key is the base64-encoded `.pem` file (the output of `base64 app.private-key.pem`, not the content of `private-key.pem`).
4040
Note: the provided SSM parameters arn and name have a precedence over the actual value (i.e `key_base64_ssm` has a precedence over `key_base64` etc).
4141
EOF
@@ -773,6 +773,12 @@ variable "enable_runner_binaries_syncer" {
773773
default = true
774774
}
775775

776+
variable "enable_ami_updater" {
777+
description = "Option to enable the lambda to update the AMI, useful when using a pre-build AMI or an AMI that gets updated out of your control."
778+
type = bool
779+
default = false
780+
}
781+
776782
variable "state_event_rule_binaries_syncer" {
777783
type = string
778784
description = "Option to disable EventBridge Lambda trigger for the binary syncer, useful to stop automatic updates of binary distribution"
@@ -985,3 +991,21 @@ variable "user_agent" {
985991
type = string
986992
default = "github-aws-runners"
987993
}
994+
995+
variable "ami_updater_lambda_zip" {
996+
description = "File location of the ami-updater lambda zip file."
997+
type = string
998+
default = null
999+
}
1000+
1001+
variable "ami_updater_lambda_memory_size" {
1002+
description = "Memory size limit in MB for ami-updater lambda."
1003+
type = number
1004+
default = 256
1005+
}
1006+
1007+
variable "ami_updater_lambda_timeout" {
1008+
description = "Time out for the ami-updater lambda in seconds."
1009+
type = number
1010+
default = 300
1011+
}

0 commit comments

Comments
 (0)