Skip to content

Commit d8d452d

Browse files
committed
Make userdata gzipped in case the user provided userdata is long
1 parent 3658d6a commit d8d452d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

modules/runners/main.tf

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ locals {
3939
enable_job_queued_check = var.enable_job_queued_check == null ? !var.enable_ephemeral_runners : var.enable_job_queued_check
4040
}
4141

42+
data "template_cloudinit_config" "userdata" {
43+
gzip = true
44+
base64_encode = true
45+
part {
46+
filename = "00-init"
47+
content_type = "text/x-shellscript"
48+
content = templatefile(local.userdata_template, {
49+
pre_install = var.userdata_pre_install
50+
install_runner = templatefile(local.userdata_install_runner[var.runner_os], {
51+
S3_LOCATION_RUNNER_DISTRIBUTION = var.s3_location_runner_binaries
52+
RUNNER_ARCHITECTURE = var.runner_architecture
53+
})
54+
post_install = var.userdata_post_install
55+
start_runner = templatefile(local.userdata_start_runner[var.runner_os], {})
56+
ghes_url = var.ghes_url
57+
ghes_ssl_verify = var.ghes_ssl_verify
58+
## retain these for backwards compatibility
59+
environment = var.environment
60+
enable_cloudwatch_agent = var.enable_cloudwatch_agent
61+
ssm_key_cloudwatch_agent_config = var.enable_cloudwatch_agent ? aws_ssm_parameter.cloudwatch_agent_config_runner[0].name : ""
62+
})
63+
}
64+
}
65+
4266
data "aws_ami" "runner" {
4367
most_recent = "true"
4468

@@ -116,21 +140,7 @@ resource "aws_launch_template" "runner" {
116140
}
117141

118142

119-
user_data = var.enabled_userdata ? base64encode(templatefile(local.userdata_template, {
120-
pre_install = var.userdata_pre_install
121-
install_runner = templatefile(local.userdata_install_runner[var.runner_os], {
122-
S3_LOCATION_RUNNER_DISTRIBUTION = var.s3_location_runner_binaries
123-
RUNNER_ARCHITECTURE = var.runner_architecture
124-
})
125-
post_install = var.userdata_post_install
126-
start_runner = templatefile(local.userdata_start_runner[var.runner_os], {})
127-
ghes_url = var.ghes_url
128-
ghes_ssl_verify = var.ghes_ssl_verify
129-
## retain these for backwards compatibility
130-
environment = var.environment
131-
enable_cloudwatch_agent = var.enable_cloudwatch_agent
132-
ssm_key_cloudwatch_agent_config = var.enable_cloudwatch_agent ? aws_ssm_parameter.cloudwatch_agent_config_runner[0].name : ""
133-
})) : ""
143+
user_data = var.enabled_userdata ? data.template_cloudinit_config.userdata.rendered : ""
134144

135145
tags = local.tags
136146

0 commit comments

Comments
 (0)