Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit ac49daf

Browse files
feat: allow caller to provide custom userdata (#3798)
Using a prebacked AMI we wish to provide a userdata script which requires information from terraform resources - e.g. endpoints for that environment. The existing `userdata_template` is not sufficient for this purpose as it requires a static file. It would be useful to be able to render the userdata script before providing it to the runner configuration. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1173830 commit ac49daf

File tree

9 files changed

+24
-7
lines changed

9 files changed

+24
-7
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ Talk to the forestkeepers in the `runners-channel` on Slack.
230230
| <a name="input_syncer_lambda_s3_object_version"></a> [syncer\_lambda\_s3\_object\_version](#input\_syncer\_lambda\_s3\_object\_version) | S3 object version for syncer lambda function. Useful if S3 versioning is enabled on source bucket. | `string` | `null` | no |
231231
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. | `map(string)` | `{}` | no |
232232
| <a name="input_tracing_config"></a> [tracing\_config](#input\_tracing\_config) | Configuration for lambda tracing. | <pre>object({<br> mode = optional(string, null)<br> capture_http_requests = optional(bool, false)<br> capture_error = optional(bool, false)<br> })</pre> | `{}` | no |
233+
| <a name="input_userdata_content"></a> [userdata\_content](#input\_userdata\_content) | Alternative user-data content, replacing the templated one. By providing your own user\_data you have to take care of installing all required software, including the action runner and registering the runner. Be-aware configuration paramaters in SSM as well as tags are treated as internals. Changes will not trigger a breaking release. | `string` | `null` | no |
233234
| <a name="input_userdata_post_install"></a> [userdata\_post\_install](#input\_userdata\_post\_install) | Script to be ran after the GitHub Actions runner is installed on the EC2 instances | `string` | `""` | no |
234235
| <a name="input_userdata_pre_install"></a> [userdata\_pre\_install](#input\_userdata\_pre\_install) | Script to be ran before the GitHub Actions runner is installed on the EC2 instances | `string` | `""` | no |
235-
| <a name="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template) | Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. | `string` | `null` | no |
236+
| <a name="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template) | Alternative user-data template file path, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. | `string` | `null` | no |
236237
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The VPC for security groups of the action runners. | `string` | n/a | yes |
237238
| <a name="input_webhook_lambda_apigateway_access_log_settings"></a> [webhook\_lambda\_apigateway\_access\_log\_settings](#input\_webhook\_lambda\_apigateway\_access\_log\_settings) | Access log settings for webhook API gateway. | <pre>object({<br> destination_arn = string<br> format = string<br> })</pre> | `null` | no |
238239
| <a name="input_webhook_lambda_memory_size"></a> [webhook\_lambda\_memory\_size](#input\_webhook\_lambda\_memory\_size) | Memory size limit in MB for webhook lambda in. | `number` | `256` | no |

Diff for: main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ module "runners" {
264264
enable_userdata = var.enable_userdata
265265
enable_user_data_debug_logging = var.enable_user_data_debug_logging_runner
266266
userdata_template = var.userdata_template
267+
userdata_content = var.userdata_content
267268
userdata_pre_install = var.userdata_pre_install
268269
userdata_post_install = var.userdata_post_install
269270
key_name = var.key_name

Diff for: modules/multi-runner/README.md

+1-1
Large diffs are not rendered by default.

Diff for: modules/multi-runner/runners.tf

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module "runners" {
8686

8787
enable_userdata = each.value.runner_config.enable_userdata
8888
userdata_template = each.value.runner_config.userdata_template
89+
userdata_content = each.value.runner_config.userdata_content
8990
userdata_pre_install = each.value.runner_config.userdata_pre_install
9091
userdata_post_install = each.value.runner_config.userdata_post_install
9192
key_name = var.key_name

Diff for: modules/multi-runner/variables.tf

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ variable "multi_runner_config" {
7070
scale_down_schedule_expression = optional(string, "cron(*/5 * * * ? *)")
7171
scale_up_reserved_concurrent_executions = optional(number, 1)
7272
userdata_template = optional(string, null)
73+
userdata_content = optional(string, null)
7374
enable_jit_config = optional(bool, null)
7475
enable_runner_detailed_monitoring = optional(bool, false)
7576
enable_cloudwatch_agent = optional(bool, true)

Diff for: modules/runners/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ yarn run dist
214214
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. | `list(string)` | n/a | yes |
215215
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags that will be added to created resources. By default resources will be tagged with name. | `map(string)` | `{}` | no |
216216
| <a name="input_tracing_config"></a> [tracing\_config](#input\_tracing\_config) | Configuration for lambda tracing. | <pre>object({<br> mode = optional(string, null)<br> capture_http_requests = optional(bool, false)<br> capture_error = optional(bool, false)<br> })</pre> | `{}` | no |
217+
| <a name="input_userdata_content"></a> [userdata\_content](#input\_userdata\_content) | Alternative user-data content, replacing the templated one. By providing your own user\_data you have to take care of installing all required software, including the action runner and registering the runner. Be-aware configuration paramaters in SSM as well as tags are treated as internals. Changes will not trigger a breaking release. | `string` | `null` | no |
217218
| <a name="input_userdata_post_install"></a> [userdata\_post\_install](#input\_userdata\_post\_install) | User-data script snippet to insert after GitHub action runner install | `string` | `""` | no |
218219
| <a name="input_userdata_pre_install"></a> [userdata\_pre\_install](#input\_userdata\_pre\_install) | User-data script snippet to insert before GitHub action runner install | `string` | `""` | no |
219-
| <a name="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template) | Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. | `string` | `null` | no |
220+
| <a name="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template) | Alternative user-data template file path, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. | `string` | `null` | no |
220221
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The VPC for the security groups. | `string` | n/a | yes |
221222

222223
## Outputs

Diff for: modules/runners/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ locals {
4646

4747
token_path = "${var.ssm_paths.root}/${var.ssm_paths.tokens}"
4848

49-
user_data = var.enable_userdata ? templatefile(local.userdata_template, {
49+
user_data = var.enable_userdata ? (var.userdata_content == null ? templatefile(local.userdata_template, {
5050
enable_debug_logging = var.enable_user_data_debug_logging
5151
s3_location_runner_distribution = local.s3_location_runner_distribution
5252
pre_install = var.userdata_pre_install
@@ -65,7 +65,7 @@ locals {
6565
environment = var.prefix
6666
enable_cloudwatch_agent = var.enable_cloudwatch_agent
6767
ssm_key_cloudwatch_agent_config = var.enable_cloudwatch_agent ? aws_ssm_parameter.cloudwatch_agent_config_runner[0].name : ""
68-
}) : ""
68+
}) : var.userdata_content) : ""
6969
}
7070

7171
data "aws_ami" "runner" {

Diff for: modules/runners/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ variable "enable_userdata" {
149149
}
150150

151151
variable "userdata_template" {
152-
description = "Alternative user-data template, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."
152+
description = "Alternative user-data template file path, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."
153+
type = string
154+
default = null
155+
}
156+
157+
variable "userdata_content" {
158+
description = "Alternative user-data content, replacing the templated one. By providing your own user_data you have to take care of installing all required software, including the action runner and registering the runner. Be-aware configuration paramaters in SSM as well as tags are treated as internals. Changes will not trigger a breaking release."
153159
type = string
154160
default = null
155161
}

Diff for: variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ variable "enable_userdata" {
246246
}
247247

248248
variable "userdata_template" {
249-
description = "Alternative user-data template, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."
249+
description = "Alternative user-data template file path, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."
250+
type = string
251+
default = null
252+
}
253+
254+
variable "userdata_content" {
255+
description = "Alternative user-data content, replacing the templated one. By providing your own user_data you have to take care of installing all required software, including the action runner and registering the runner. Be-aware configuration paramaters in SSM as well as tags are treated as internals. Changes will not trigger a breaking release."
250256
type = string
251257
default = null
252258
}

0 commit comments

Comments
 (0)