Skip to content

Commit 5c05476

Browse files
committed
feat: Add ASG lifecycle management Lambda function (#392)
This introduces an Auto Scaling Group instance termination lifecycle hook using Lambda and related resources. The Lambda function is a Python script that is triggered when the persistent runner instance in the ASG is terminated. The function receives the instance ID of the "parent" runner and queries for spawned instances that it launched to terminate. Additionally, it will check for other "orphaned" instances that have a `gitlab-runner-parent-id` tag that doesn't match an existing instance. This resolves the issue where spawned instances could be orphaned when their parent runner is terminated. This feature is disabled by default. The user data script is updated to provide the 'parent' instance ID as a tag named 'gitlab-runner-parent-id' on spawned instances. A new sub-module is provided called "terminate-workers". It is optional to use this feature, and the input variable `asg_terminate_lifecycle_hook_create` can be toggled `true` or `false` for this behavior.
1 parent dd3e065 commit 5c05476

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
- [Prerequisites](#prerequisites)
77
- [Usage](#usage)
88
- [Examples](#examples)
9+
- [Requirements](#requirements)
10+
- [Providers](#providers)
11+
- [Modules](#modules)
12+
- [Resources](#resources)
13+
- [Inputs](#inputs)
14+
- [Outputs](#outputs)
915

1016
## The module
1117

modules/terminate-instances/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ data "archive_file" "terminate_runner_instances_lambda" {
1717
}
1818

1919
resource "aws_lambda_function" "terminate_runner_instances" {
20+
architectures = ["x86_64"]
2021
description = "Lifecycle hook for terminating GitLab runner instances"
2122
filename = data.archive_file.terminate_runner_instances_lambda.output_path
2223
source_code_hash = data.archive_file.terminate_runner_instances_lambda.output_base64sha256

0 commit comments

Comments
 (0)