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

Commit 7e98943

Browse files
wadhervnpalm
andauthored
feat(lambda): add option to define explicit lambda tags (#3934)
Introduced a new variable, lambda_tags, to both the main and submodule. This variable will include any additional lambda function-specific tags, enhancing the governance part of resources. Co-authored-by: Niek Palm <[email protected]>
1 parent 1aef82b commit 7e98943

24 files changed

+67
-15
lines changed

Diff for: main.tf

+5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ module "webhook" {
158158
lambda_zip = var.webhook_lambda_zip
159159
lambda_memory_size = var.webhook_lambda_memory_size
160160
lambda_timeout = var.webhook_lambda_timeout
161+
lambda_tags = var.lambda_tags
161162
tracing_config = var.tracing_config
162163
logging_retention_in_days = var.logging_retention_in_days
163164
logging_kms_key_id = var.logging_kms_key_id
@@ -245,6 +246,7 @@ module "runners" {
245246
lambda_timeout_scale_down = var.runners_scale_down_lambda_timeout
246247
lambda_subnet_ids = var.lambda_subnet_ids
247248
lambda_security_group_ids = var.lambda_security_group_ids
249+
lambda_tags = var.lambda_tags
248250
tracing_config = var.tracing_config
249251
logging_retention_in_days = var.logging_retention_in_days
250252
logging_kms_key_id = var.logging_kms_key_id
@@ -315,6 +317,7 @@ module "runner_binaries" {
315317
lambda_zip = var.runner_binaries_syncer_lambda_zip
316318
lambda_memory_size = var.runner_binaries_syncer_lambda_memory_size
317319
lambda_timeout = var.runner_binaries_syncer_lambda_timeout
320+
lambda_tags = var.lambda_tags
318321
tracing_config = var.tracing_config
319322
logging_retention_in_days = var.logging_retention_in_days
320323
logging_kms_key_id = var.logging_kms_key_id
@@ -354,6 +357,7 @@ module "ami_housekeeper" {
354357
lambda_security_group_ids = var.lambda_security_group_ids
355358
lambda_subnet_ids = var.lambda_subnet_ids
356359
lambda_timeout = var.ami_housekeeper_lambda_timeout
360+
lambda_tags = var.lambda_tags
357361
tracing_config = var.tracing_config
358362

359363
logging_retention_in_days = var.logging_retention_in_days
@@ -377,6 +381,7 @@ locals {
377381
runtime = var.lambda_runtime
378382
security_group_ids = var.lambda_security_group_ids
379383
subnet_ids = var.lambda_subnet_ids
384+
lambda_tags = var.lambda_tags
380385
log_level = var.log_level
381386
logging_kms_key_id = var.logging_kms_key_id
382387
logging_retention_in_days = var.logging_retention_in_days

Diff for: modules/ami-housekeeper/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ resource "aws_lambda_function" "ami_housekeeper" {
3737
}
3838
}
3939

40-
tags = var.tags
40+
tags = merge(var.tags, var.lambda_tags)
4141

4242
dynamic "tracing_config" {
4343
for_each = var.tracing_config.mode != null ? [true] : []

Diff for: modules/ami-housekeeper/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,9 @@ variable "state_event_rule_ami_housekeeper" {
192192
error_message = "`state_event_rule_ami_housekeeper` value is not valid, valid values are: `ENABLED`, `DISABLED`, `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`."
193193
}
194194
}
195+
196+
variable "lambda_tags" {
197+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
198+
type = map(string)
199+
default = {}
200+
}

Diff for: modules/lambda/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resource "aws_lambda_function" "main" {
4242
}
4343
}
4444

45-
tags = var.lambda.tags
45+
tags = merge(var.lambda.tags, var.lambda.lambda_tags)
4646

4747
dynamic "tracing_config" {
4848
for_each = var.lambda.tracing_config.mode != null ? [true] : []

Diff for: modules/lambda/variables.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ variable "lambda" {
22
description = <<-EOF
33
Configuration for the lambda function.
44
5-
'aws_partition': Partition for the base arn if not 'aws'
5+
`aws_partition`: Partition for the base arn if not 'aws'
66
`architecture`: AWS Lambda architecture. Lambda functions using Graviton processors ('arm64') tend to have better price/performance than 'x86_64' functions.
77
`environment_variables`: Environment variables for the lambda.
88
`handler`: The entrypoint for the lambda.
99
`principals`: Add extra principals to the role created for execution of the lambda, e.g. for local testing.
10+
`lambda_tags`: Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
1011
`log_level`: Logging level for lambda logging. Valid values are 'silly', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'.
1112
`logging_kms_key_id`: Specifies the kms key id to encrypt the logs with
1213
`logging_retention_in_days`: Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653.
1314
`memory_size`: Memory size linit in MB of the lambda.
1415
`metrics_namespace`: Namespace for the metrics emitted by the lambda.
15-
'name': The name of the lambda function.
16+
`name`: The name of the lambda function.
1617
`prefix`: The prefix used for naming resources.
1718
`role_path`: The path that will be added to the role, if not set the environment name will be used.
1819
`role_permissions_boundary`: Permissions boundary that will be added to the created role for the lambda.
@@ -22,7 +23,7 @@ variable "lambda" {
2223
`s3_object_version`: S3 object version for syncer lambda function. Useful if S3 versioning is enabled on source bucket.
2324
`security_group_ids`: List of security group IDs associated with the Lambda function.
2425
`subnet_ids`: List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`.
25-
'tags': Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
26+
`tags`: Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
2627
`timeout`: Time out of the lambda in seconds.
2728
`tracing_config`: Configuration for lambda tracing.
2829
`zip`: File location of the lambda zip file.
@@ -32,6 +33,7 @@ variable "lambda" {
3233
architecture = optional(string, "arm64")
3334
environment_variables = optional(map(string), {})
3435
handler = string
36+
lambda_tags = optional(map(string), {})
3537
log_level = optional(string, "info")
3638
logging_kms_key_id = optional(string, null)
3739
logging_retention_in_days = optional(number, 180)

Diff for: modules/multi-runner/ami-housekeeper.tf

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module "ami_housekeeper" {
1919
lambda_subnet_ids = var.lambda_subnet_ids
2020
lambda_memory_size = var.ami_housekeeper_lambda_memory_size
2121
lambda_timeout = var.ami_housekeeper_lambda_timeout
22+
lambda_tags = var.lambda_tags
2223
tracing_config = var.tracing_config
2324

2425
logging_retention_in_days = var.logging_retention_in_days

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

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module "runner_binaries" {
1818
lambda_zip = var.runner_binaries_syncer_lambda_zip
1919
lambda_memory_size = var.runner_binaries_syncer_memory_size
2020
lambda_timeout = var.runner_binaries_syncer_lambda_timeout
21+
lambda_tags = var.lambda_tags
2122
tracing_config = var.tracing_config
2223
logging_retention_in_days = var.logging_retention_in_days
2324
logging_kms_key_id = var.logging_kms_key_id

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

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module "runners" {
6969
lambda_timeout_scale_down = var.runners_scale_down_lambda_timeout
7070
lambda_subnet_ids = var.lambda_subnet_ids
7171
lambda_security_group_ids = var.lambda_security_group_ids
72+
lambda_tags = var.lambda_tags
7273
tracing_config = var.tracing_config
7374
logging_retention_in_days = var.logging_retention_in_days
7475
logging_kms_key_id = var.logging_kms_key_id

Diff for: modules/multi-runner/termination-watcher.tf

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ locals {
1616
metrics_namespace = var.metrics_namespace
1717
s3_bucket = var.lambda_s3_bucket
1818
tracing_config = var.tracing_config
19+
lambda_tags = var.lambda_tags
1920
}
2021
}
2122

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

+6
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,12 @@ variable "instance_termination_watcher" {
645645
default = {}
646646
}
647647

648+
variable "lambda_tags" {
649+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
650+
type = map(string)
651+
default = {}
652+
}
653+
648654
variable "matcher_config_parameter_store_tier" {
649655
description = "The tier of the parameter store for the matcher configuration. Valid values are `Standard`, and `Advanced`."
650656
type = string

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

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module "webhook" {
2525
lambda_zip = var.webhook_lambda_zip
2626
lambda_timeout = var.webhook_lambda_timeout
2727
lambda_memory_size = var.webhook_lambda_memory_size
28+
lambda_tags = var.lambda_tags
2829
tracing_config = var.tracing_config
2930
logging_retention_in_days = var.logging_retention_in_days
3031
logging_kms_key_id = var.logging_kms_key_id

Diff for: modules/runner-binaries-syncer/runner-binaries-syncer.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "aws_lambda_function" "syncer" {
4646
}
4747
}
4848

49-
tags = var.tags
49+
tags = merge(var.tags, var.lambda_tags)
5050

5151
dynamic "tracing_config" {
5252
for_each = var.tracing_config.mode != null ? [true] : []

Diff for: modules/runner-binaries-syncer/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,9 @@ variable "tracing_config" {
236236
})
237237
default = {}
238238
}
239+
240+
variable "lambda_tags" {
241+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
242+
type = map(string)
243+
default = {}
244+
}

Diff for: modules/runners/pool.tf

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module "pool" {
5454
ami_id_ssm_parameter_name = var.ami_id_ssm_parameter_name
5555
ami_id_ssm_parameter_read_policy_arn = var.ami_id_ssm_parameter_name != null ? aws_iam_policy.ami_id_ssm_parameter_read[0].arn : null
5656
tags = local.tags
57+
lambda_tags = var.lambda_tags
5758
arn_ssm_parameters_path_config = local.arn_ssm_parameters_path_config
5859
}
5960

Diff for: modules/runners/pool/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resource "aws_lambda_function" "pool" {
1313
timeout = var.config.lambda.timeout
1414
reserved_concurrent_executions = var.config.lambda.reserved_concurrent_executions
1515
memory_size = var.config.lambda.memory_size
16-
tags = var.config.tags
16+
tags = merge(var.config.tags, var.config.lambda_tags)
1717

1818
environment {
1919
variables = {

Diff for: modules/runners/pool/variables.tf

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ variable "config" {
6262
ami_id_ssm_parameter_name = string
6363
ami_id_ssm_parameter_read_policy_arn = string
6464
arn_ssm_parameters_path_config = string
65+
lambda_tags = map(string)
6566
})
6667
}
6768

Diff for: modules/runners/scale-down.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "aws_lambda_function" "scale_down" {
1616
handler = "index.scaleDownHandler"
1717
runtime = var.lambda_runtime
1818
timeout = var.lambda_timeout_scale_down
19-
tags = local.tags
19+
tags = merge(local.tags, var.lambda_tags)
2020
memory_size = var.lambda_scale_down_memory_size
2121
architectures = [var.lambda_architecture]
2222

Diff for: modules/runners/scale-up.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resource "aws_lambda_function" "scale_up" {
1111
timeout = var.lambda_timeout_scale_up
1212
reserved_concurrent_executions = var.scale_up_reserved_concurrent_executions
1313
memory_size = var.lambda_scale_up_memory_size
14-
tags = local.tags
14+
tags = merge(local.tags, var.lambda_tags)
1515
architectures = [var.lambda_architecture]
1616
environment {
1717
variables = {

Diff for: modules/runners/ssm-housekeeper.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "aws_lambda_function" "ssm_housekeeper" {
2323
handler = "index.ssmHousekeeper"
2424
runtime = var.lambda_runtime
2525
timeout = local.ssm_housekeeper.lambda_timeout
26-
tags = local.tags
26+
tags = merge(local.tags, var.lambda_tags)
2727
memory_size = local.ssm_housekeeper.lambda_memory_size
2828
architectures = [var.lambda_architecture]
2929

Diff for: modules/runners/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,9 @@ variable "enable_on_demand_failover_for_errors" {
661661
type = list(string)
662662
default = []
663663
}
664+
665+
variable "lambda_tags" {
666+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
667+
type = map(string)
668+
default = {}
669+
}

Diff for: modules/termination-watcher/variables.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ variable "config" {
22
description = <<-EOF
33
Configuration for the spot termination watcher lambda function.
44
5-
'aws_partition': Partition for the base arn if not 'aws'
5+
`aws_partition`: Partition for the base arn if not 'aws'
66
`architecture`: AWS Lambda architecture. Lambda functions using Graviton processors ('arm64') tend to have better price/performance than 'x86_64' functions.
77
`environment_variables`: Environment variables for the lambda.
8-
'enable_metric': Enable metric for the lambda. If `spot_warning` is set to true, the lambda will emit a metric when it detects a spot termination warning.
8+
`enable_metric`: Enable metric for the lambda. If `spot_warning` is set to true, the lambda will emit a metric when it detects a spot termination warning.
99
`lambda_principals`: Add extra principals to the role created for execution of the lambda, e.g. for local testing.
10+
`lambda_tags`: Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
1011
`log_level`: Logging level for lambda logging. Valid values are 'silly', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'.
1112
`logging_kms_key_id`: Specifies the kms key id to encrypt the logs with
1213
`logging_retention_in_days`: Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653.
@@ -22,7 +23,7 @@ variable "config" {
2223
`security_group_ids`: List of security group IDs associated with the Lambda function.
2324
`subnet_ids`: List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`.
2425
`tag_filters`: Map of tags that will be used to filter the resources to be tracked. Only for which all tags are present and starting with the same value as the value in the map will be tracked.
25-
'tags': Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
26+
`tags`: Map of tags that will be added to created resources. By default resources will be tagged with name and environment.
2627
`timeout`: Time out of the lambda in seconds.
2728
`tracing_config`: Configuration for lambda tracing.
2829
`zip`: File location of the lambda zip file.
@@ -34,6 +35,7 @@ variable "config" {
3435
spot_warning = optional(bool, false)
3536
}))
3637
environment_variables = optional(map(string), {})
38+
lambda_tags = optional(map(string), {})
3739
log_level = optional(string, null)
3840
logging_kms_key_id = optional(string, null)
3941
logging_retention_in_days = optional(number, null)

Diff for: modules/webhook/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ variable "ssm_paths" {
195195
})
196196
}
197197

198+
variable "lambda_tags" {
199+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
200+
type = map(string)
201+
default = {}
202+
}
203+
198204
variable "matcher_config_parameter_store_tier" {
199205
description = "The tier of the parameter store for the matcher configuration. Valid values are `Standard`, and `Advanced`."
200206
type = string

Diff for: modules/webhook/webhook.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ resource "aws_lambda_function" "webhook" {
4545
}
4646
}
4747

48-
tags = var.tags
48+
tags = merge(var.tags, var.lambda_tags)
4949

5050
dynamic "tracing_config" {
5151
for_each = var.tracing_config.mode != null ? [true] : []

Diff for: variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ variable "instance_termination_watcher" {
872872
Configuration for the instance termination watcher. This feature is Beta, changes will not trigger a major release as long in beta.
873873
874874
`enable`: Enable or disable the spot termination watcher.
875-
'enable_metrics': Enable or disable the metrics for the spot termination watcher.
875+
`enable_metrics`: Enable or disable the metrics for the spot termination watcher.
876876
`memory_size`: Memory size linit in MB of the lambda.
877877
`s3_key`: S3 key for syncer lambda function. Required if using S3 bucket to specify lambdas.
878878
`s3_object_version`: S3 object version for syncer lambda function. Useful if S3 versioning is enabled on source bucket.
@@ -899,3 +899,9 @@ variable "runners_ebs_optimized" {
899899
type = bool
900900
default = false
901901
}
902+
903+
variable "lambda_tags" {
904+
description = "Map of tags that will be added to all the lambda function resources. Note these are additional tags to the default tags."
905+
type = map(string)
906+
default = {}
907+
}

0 commit comments

Comments
 (0)