Skip to content

Commit 4cb87ef

Browse files
committed
feat(control-plane): tag controll plane created SSM Parameters (#4833)
1 parent 2ebbfae commit 4cb87ef

File tree

16 files changed

+52
-3
lines changed

16 files changed

+52
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Join our discord community via [this invite link](https://discord.gg/bxgXW8jJGh)
165165
| <a name="input_matcher_config_parameter_store_tier"></a> [matcher\_config\_parameter\_store\_tier](#input\_matcher\_config\_parameter\_store\_tier) | The tier of the parameter store for the matcher configuration. Valid values are `Standard`, and `Advanced`. | `string` | `"Standard"` | no |
166166
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Configuration for metrics created by the module, by default disabled to avoid additional costs. When metrics are enable all metrics are created unless explicit configured otherwise. | <pre>object({<br/> enable = optional(bool, false)<br/> namespace = optional(string, "GitHub Runners")<br/> metric = optional(object({<br/> enable_github_app_rate_limit = optional(bool, true)<br/> enable_job_retry = optional(bool, true)<br/> enable_spot_termination_warning = optional(bool, true)<br/> }), {})<br/> })</pre> | `{}` | no |
167167
| <a name="input_minimum_running_time_in_minutes"></a> [minimum\_running\_time\_in\_minutes](#input\_minimum\_running\_time\_in\_minutes) | The time an ec2 action runner should be running at minimum before terminated, if not busy. | `number` | `null` | no |
168+
| <a name="input_parameter_store_tags"></a> [parameter\_store\_tags](#input\_parameter\_store\_tags) | Map of tags that will be added to all the SSM Parameter Store parameters created by the Lambda function. | `map(string)` | `{}` | no |
168169
| <a name="input_pool_config"></a> [pool\_config](#input\_pool\_config) | The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for weekdays to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1. Use `schedule_expression_timezone` to override the schedule time zone (defaults to UTC). | <pre>list(object({<br/> schedule_expression = string<br/> schedule_expression_timezone = optional(string)<br/> size = number<br/> }))</pre> | `[]` | no |
169170
| <a name="input_pool_lambda_memory_size"></a> [pool\_lambda\_memory\_size](#input\_pool\_lambda\_memory\_size) | Memory size limit for scale-up lambda. | `number` | `512` | no |
170171
| <a name="input_pool_lambda_reserved_concurrent_executions"></a> [pool\_lambda\_reserved\_concurrent\_executions](#input\_pool\_lambda\_reserved\_concurrent\_executions) | Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `number` | `1` | no |

lambdas/functions/control-plane/src/pool/pool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export async function adjust(event: PoolEvent): Promise<void> {
4141
const onDemandFailoverOnError = process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS
4242
? (JSON.parse(process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS) as [string])
4343
: [];
44+
const ssmParameterStoreTags = process.env.SSM_PARAMETER_STORE_TAGS
45+
? JSON.parse(process.env.SSM_PARAMETER_STORE_TAGS)
46+
: {};
4447

4548
const { ghesApiUrl, ghesBaseUrl } = getGitHubEnterpriseApiUrl();
4649

@@ -81,6 +84,7 @@ export async function adjust(event: PoolEvent): Promise<void> {
8184
disableAutoUpdate: disableAutoUpdate,
8285
ssmTokenPath,
8386
ssmConfigPath,
87+
ssmParameterStoreTags,
8488
},
8589
{
8690
ec2instanceCriteria: {

lambdas/functions/control-plane/src/scale-runners/scale-up.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface CreateGitHubRunnerConfig {
5151
disableAutoUpdate: boolean;
5252
ssmTokenPath: string;
5353
ssmConfigPath: string;
54+
ssmParameterStoreTags: { Key: string; Value: string }[];
5455
}
5556

5657
interface CreateEC2RunnerConfig {
@@ -182,6 +183,9 @@ async function getRunnerGroupId(githubRunnerConfig: CreateGitHubRunnerConfig, gh
182183
`${githubRunnerConfig.ssmConfigPath}/runner-group/${githubRunnerConfig.runnerGroup}`,
183184
runnerGroupId.toString(),
184185
false,
186+
{
187+
tags: githubRunnerConfig.ssmParameterStoreTags,
188+
},
185189
);
186190
} catch (err) {
187191
logger.debug('Error storing runner group id in SSM Parameter Store', err as Error);
@@ -255,6 +259,10 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
255259
const onDemandFailoverOnError = process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS
256260
? (JSON.parse(process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS) as [string])
257261
: [];
262+
const ssmParameterStoreTags: { Key: string; Value: string }[] =
263+
process.env.SSM_PARAMETER_STORE_TAGS && process.env.SSM_PARAMETER_STORE_TAGS.trim() !== ''
264+
? JSON.parse(process.env.SSM_PARAMETER_STORE_TAGS)
265+
: [];
258266

259267
const { ghesApiUrl, ghesBaseUrl } = getGitHubEnterpriseApiUrl();
260268

@@ -417,6 +425,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
417425
disableAutoUpdate,
418426
ssmTokenPath,
419427
ssmConfigPath,
428+
ssmParameterStoreTags,
420429
},
421430
{
422431
ec2instanceCriteria: {
@@ -510,7 +519,7 @@ async function createRegistrationTokenConfig(
510519

511520
for (const instance of instances) {
512521
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerServiceConfig.join(' '), true, {
513-
tags: [{ Key: 'InstanceId', Value: instance }],
522+
tags: [{ Key: 'InstanceId', Value: instance }, ...githubRunnerConfig.ssmParameterStoreTags],
514523
});
515524
if (isDelay) {
516525
// Delay to prevent AWS ssm rate limits by being within the max throughput limit
@@ -567,8 +576,9 @@ async function createJitConfig(githubRunnerConfig: CreateGitHubRunnerConfig, ins
567576
logger.debug('Runner JIT config for ephemeral runner generated.', {
568577
instance: instance,
569578
});
579+
const tags = [{ Key: 'InstanceId', Value: instance }];
570580
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerConfig.data.encoded_jit_config, true, {
571-
tags: [{ Key: 'InstanceId', Value: instance }],
581+
tags: [{ Key: 'InstanceId', Value: instance }, ...githubRunnerConfig.ssmParameterStoreTags],
572582
});
573583
if (isDelay) {
574584
// Delay to prevent AWS ssm rate limits by being within the max throughput limit

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ module "runners" {
231231
runner_log_files = var.runner_log_files
232232
runner_group_name = var.runner_group_name
233233
runner_name_prefix = var.runner_name_prefix
234+
parameter_store_tags = var.parameter_store_tags
234235

235236
scale_up_reserved_concurrent_executions = var.scale_up_reserved_concurrent_executions
236237

modules/multi-runner/README.md

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

modules/multi-runner/runners.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module "runners" {
8080
runner_log_files = each.value.runner_config.runner_log_files
8181
runner_group_name = each.value.runner_config.runner_group_name
8282
runner_name_prefix = each.value.runner_config.runner_name_prefix
83+
parameter_store_tags = var.parameter_store_tags
8384

8485
scale_up_reserved_concurrent_executions = each.value.runner_config.scale_up_reserved_concurrent_executions
8586

modules/multi-runner/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,9 @@ variable "lambda_event_source_mapping_maximum_batching_window_in_seconds" {
740740
type = number
741741
default = 0
742742
}
743+
744+
variable "parameter_store_tags" {
745+
description = "Map of tags that will be added to all the SSM Parameter Store parameters created by the Lambda function."
746+
type = map(string)
747+
default = {}
748+
}

modules/runners/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ yarn run dist
192192
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Configuration for metrics created by the module, by default metrics are disabled to avoid additional costs. When metrics are enable all metrics are created unless explicit configured otherwise. | <pre>object({<br/> enable = optional(bool, false)<br/> namespace = optional(string, "GitHub Runners")<br/> metric = optional(object({<br/> enable_github_app_rate_limit = optional(bool, true)<br/> enable_job_retry = optional(bool, true)<br/> enable_spot_termination_warning = optional(bool, true)<br/> }), {})<br/> })</pre> | `{}` | no |
193193
| <a name="input_minimum_running_time_in_minutes"></a> [minimum\_running\_time\_in\_minutes](#input\_minimum\_running\_time\_in\_minutes) | The time an ec2 action runner should be running at minimum before terminated if non busy. If not set the default is calculated based on the OS. | `number` | `null` | no |
194194
| <a name="input_overrides"></a> [overrides](#input\_overrides) | This map provides the possibility to override some defaults. The following attributes are supported: `name_sg` overrides the `Name` tag for all security groups created by this module. `name_runner_agent_instance` overrides the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` overrides the `Name` tag spot instances created by the runner agent. | `map(string)` | <pre>{<br/> "name_runner": "",<br/> "name_sg": ""<br/>}</pre> | no |
195+
| <a name="input_parameter_store_tags"></a> [parameter\_store\_tags](#input\_parameter\_store\_tags) | Map of tags that will be added to all the SSM Parameter Store parameters created by the Lambda function. | `map(string)` | `{}` | no |
195196
| <a name="input_placement"></a> [placement](#input\_placement) | The placement options for the instance. See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#placement for details. | <pre>object({<br/> affinity = optional(string)<br/> availability_zone = optional(string)<br/> group_id = optional(string)<br/> group_name = optional(string)<br/> host_id = optional(string)<br/> host_resource_group_arn = optional(number)<br/> spread_domain = optional(string)<br/> tenancy = optional(string)<br/> partition_number = optional(number)<br/> })</pre> | `null` | no |
196197
| <a name="input_pool_config"></a> [pool\_config](#input\_pool\_config) | The configuration for updating the pool. The `pool_size` to adjust to by the events triggered by the `schedule_expression`. For example you can configure a cron expression for week days to adjust the pool to 10 and another expression for the weekend to adjust the pool to 1. Use `schedule_expression_timezone ` to override the schedule time zone (defaults to UTC). | <pre>list(object({<br/> schedule_expression = string<br/> schedule_expression_timezone = optional(string)<br/> size = number<br/> }))</pre> | `[]` | no |
197198
| <a name="input_pool_lambda_memory_size"></a> [pool\_lambda\_memory\_size](#input\_pool\_lambda\_memory\_size) | Lambda Memory size limit in MB for pool lambda | `number` | `512` | no |

modules/runners/local.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
locals {
2+
parameter_store_tags = [
3+
for k, v in var.parameter_store_tags : {
4+
Key = k
5+
Value = v
6+
}
7+
]
8+
}

modules/runners/pool.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module "pool" {
3333
runtime = var.lambda_runtime
3434
timeout = var.pool_lambda_timeout
3535
zip = local.lambda_zip
36+
parameter_store_tags = local.parameter_store_tags
3637
}
3738
pool = var.pool_config
3839
role_path = local.role_path

0 commit comments

Comments
 (0)