Skip to content

Commit 377d2a2

Browse files
committed
feat(control-plane): [issue-4833] AWS SSM Parameter store tags
1 parent 67fadae commit 377d2a2

File tree

16 files changed

+58
-3
lines changed

16 files changed

+58
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Join our discord community via [this invite link](https://discord.gg/bxgXW8jJGh)
167167
| <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 |
168168
| <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 |
169169
| <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 |
170+
| <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 |
170171
| <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 |
171172
| <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 |
172173
| <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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ interface CreateGitHubRunnerConfig {
4949
disableAutoUpdate: boolean;
5050
ssmTokenPath: string;
5151
ssmConfigPath: string;
52+
ssmParameterStoreTags: { Key: string; Value: string }[];
5253
}
5354

5455
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);
@@ -251,6 +255,10 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
251255
const onDemandFailoverOnError = process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS
252256
? (JSON.parse(process.env.ENABLE_ON_DEMAND_FAILOVER_FOR_ERRORS) as [string])
253257
: [];
258+
const ssmParameterStoreTags: { Key: string; Value: string }[] =
259+
process.env.SSM_PARAMETER_STORE_TAGS && process.env.SSM_PARAMETER_STORE_TAGS.trim() !== ''
260+
? JSON.parse(process.env.SSM_PARAMETER_STORE_TAGS)
261+
: [];
254262

255263
if (ephemeralEnabled && payload.eventType !== 'workflow_job') {
256264
logger.warn(`${payload.eventType} event is not supported in combination with ephemeral runners.`);
@@ -321,6 +329,7 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
321329
disableAutoUpdate,
322330
ssmTokenPath,
323331
ssmConfigPath,
332+
ssmParameterStoreTags,
324333
},
325334
{
326335
ec2instanceCriteria: {
@@ -407,7 +416,10 @@ async function createRegistrationTokenConfig(
407416

408417
for (const instance of instances) {
409418
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerServiceConfig.join(' '), true, {
410-
tags: [{ Key: 'InstanceId', Value: instance }],
419+
tags: [
420+
{ Key: 'InstanceId', Value: instance },
421+
...githubRunnerConfig.ssmParameterStoreTags
422+
],
411423
});
412424
if (isDelay) {
413425
// Delay to prevent AWS ssm rate limits by being within the max throughput limit
@@ -464,8 +476,12 @@ async function createJitConfig(githubRunnerConfig: CreateGitHubRunnerConfig, ins
464476
logger.debug('Runner JIT config for ephemeral runner generated.', {
465477
instance: instance,
466478
});
479+
const tags = [{ Key: 'InstanceId', Value: instance }]
467480
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerConfig.data.encoded_jit_config, true, {
468-
tags: [{ Key: 'InstanceId', Value: instance }],
481+
tags: [
482+
{ Key: 'InstanceId', Value: instance },
483+
...githubRunnerConfig.ssmParameterStoreTags
484+
],
469485
});
470486
if (isDelay) {
471487
// 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
@@ -232,6 +232,7 @@ module "runners" {
232232
runner_log_files = var.runner_log_files
233233
runner_group_name = var.runner_group_name
234234
runner_name_prefix = var.runner_name_prefix
235+
parameter_store_tags = var.parameter_store_tags
235236

236237
scale_up_reserved_concurrent_executions = var.scale_up_reserved_concurrent_executions
237238

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
@@ -718,3 +718,9 @@ variable "user_agent" {
718718
type = string
719719
default = "github-aws-runners"
720720
}
721+
722+
variable "parameter_store_tags" {
723+
description = "Map of tags that will be added to all the SSM Parameter Store parameters created by the Lambda function."
724+
type = map(string)
725+
default = {}
726+
}

modules/runners/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ yarn run dist
194194
| <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 |
195195
| <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 |
196196
| <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 |
197+
| <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 |
197198
| <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 |
198199
| <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 |
199200
| <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 |

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)