Skip to content

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

main.tf

Lines changed: 5 additions & 0 deletions
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

modules/ami-housekeeper/main.tf

Lines changed: 1 addition & 1 deletion
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] : []

modules/ami-housekeeper/variables.tf

Lines changed: 6 additions & 0 deletions
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+
}

modules/lambda/main.tf

Lines changed: 1 addition & 1 deletion
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] : []

modules/lambda/variables.tf

Lines changed: 5 additions & 3 deletions
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)

modules/multi-runner/ami-housekeeper.tf

Lines changed: 1 addition & 0 deletions
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

modules/multi-runner/runner-binaries.tf

Lines changed: 1 addition & 0 deletions
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

modules/multi-runner/runners.tf

Lines changed: 1 addition & 0 deletions
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

modules/multi-runner/termination-watcher.tf

Lines changed: 1 addition & 0 deletions
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

modules/multi-runner/variables.tf

Lines changed: 6 additions & 0 deletions
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

0 commit comments

Comments
 (0)