Skip to content

Commit 0326c6d

Browse files
committed
fix(logging): preserve count-based log groups to avoid breaking change
BREAKING CHANGE AVOIDED: The previous implementation changed aws_cloudwatch_log_group.gh_runners from count to for_each, which would cause Terraform to destroy and recreate all existing CloudWatch log groups on upgrade. This could result in loss of log data. This commit reverts to the count-based approach using parallel loggroups_names and loggroups_classes lists, preserving the existing Terraform state addresses (e.g. aws_cloudwatch_log_group.gh_runners[0]) while still supporting the new log_class parameter. Changes: - logging.tf: Use loggroups_names + loggroups_classes parallel lists instead of a for_each on objects, keeping count-based resource indexing - logging.tf: Remove redundant try() around l.log_class since the variable type already defaults it to "STANDARD" - job-retry.tf: Add missing log_class propagation to job-retry config - variables.tf: Update runner_log_files description to document log_class - examples/multi-runner: Add log_class parameter to example Signed-off-by: Brend Smits <brend.smits@philips.com>
1 parent e622a04 commit 0326c6d

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

examples/multi-runner/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ module "runners" {
139139
# Enable debug logging for the lambda functions
140140
# log_level = "debug"
141141

142+
# Set log class to INFREQUENT_ACCESS for cost savings
143+
log_class = "STANDARD"
144+
142145
# Enable to track the spot instance termination warning
143146
# instance_termination_watcher = {
144147
# enable = true

modules/runners/job-retry.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ locals {
1313
kms_key_arn = var.kms_key_arn
1414
lambda_tags = var.lambda_tags
1515
log_level = var.log_level
16+
log_class = var.log_class
1617
logging_kms_key_id = var.logging_kms_key_id
1718
logging_retention_in_days = var.logging_retention_in_days
1819
metrics = var.metrics

modules/runners/logging.tf

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ locals {
3737
"log_group_name" : l.prefix_log_group ? "/github-self-hosted-runners/${var.prefix}/${l.log_group_name}" : "/${l.log_group_name}"
3838
"log_stream_name" : l.log_stream_name
3939
"file_path" : l.file_path
40-
"log_class" : try(l.log_class, "STANDARD")
40+
"log_class" : l.log_class
4141
}] : []
4242

43-
loggroups = distinct([for l in local.logfiles : { name = l.log_group_name, log_class = l.log_class }])
43+
loggroups_names = distinct([for l in local.logfiles : l.log_group_name])
44+
# Create a list of unique log classes corresponding to each log group name
45+
# This maintains the same order as loggroups_names for use with count
46+
loggroups_classes = [
47+
for name in local.loggroups_names : [
48+
for l in local.logfiles : l.log_class
49+
if l.log_group_name == name
50+
][0]
51+
]
4452

4553
}
4654

@@ -56,11 +64,11 @@ resource "aws_ssm_parameter" "cloudwatch_agent_config_runner" {
5664
}
5765

5866
resource "aws_cloudwatch_log_group" "gh_runners" {
59-
for_each = { for lg in local.loggroups : lg.name => lg }
60-
name = each.value.name
67+
count = length(local.loggroups_names)
68+
name = local.loggroups_names[count.index]
6169
retention_in_days = var.logging_retention_in_days
6270
kms_key_id = var.logging_kms_key_id
63-
log_group_class = each.value.log_class
71+
log_group_class = local.loggroups_classes[count.index]
6472
tags = local.tags
6573
}
6674

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ variable "cloudwatch_config" {
496496
}
497497

498498
variable "runner_log_files" {
499-
description = "(optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details."
499+
description = "(optional) List of logfiles to send to CloudWatch, will only be used if `enable_cloudwatch_agent` is set to true. Object description: `log_group_name`: Name of the log group, `prefix_log_group`: If true, the log group name will be prefixed with `/github-self-hosted-runners/<var.prefix>`, `file_path`: path to the log file, `log_stream_name`: name of the log stream, `log_class`: The log class of the log group. Valid values are `STANDARD` or `INFREQUENT_ACCESS`. Defaults to `STANDARD`."
500500
type = list(object({
501501
log_group_name = string
502502
prefix_log_group = bool

0 commit comments

Comments
 (0)