Terraform:Merge/Re-push 标签进入源模块
Terraform: Merge/Re-push Tags into the Source Module
Terraform 新手::
我们有一个用于 SQS 的社区模块,大多数开发人员使用它来启动 SQS 队列,它带有很少 (4) 个标签(社区目前没有可重复使用的标签模块)。
对于我的项目,我的 SQS 队列需要比社区 SQS 有额外的标签,这里需要注意的是他们不允许我们在他们的模块中进行更改。
我有一个我编写的标签模块,我想将它与社区 SQS 模块一起使用。
长话短说,我想用我的标签模块
覆盖下面社区 SQS 模块中的整个标签块
- 按原样使用社区模块并将额外的地形添加到“重新推送”标签
社区 SQS 模块(命名为 main.tf):-
resource "aws_sqs_queue" "new_terraform_queue" {
name = var.name
delay_seconds = var.delay_seconds
max_message_size = var.max_message_size
message_retention_seconds = var.message_retention_seconds
visibility_timeout_seconds = var.visibility_timeout_seconds
policy = var.policy
receive_wait_time_seconds = var.receive_wait_time_seconds
redrive_policy = var.redrive_policy
fifo_queue = var.fifo_queue
content_based_deduplication = var.content_based_deduplication
tags = {
environment = var.environment
project = var.project
application_id = var.applicationId
purpose = var.purpose
}
}
将上述模块采购到我的项目中:
module "main" {
source = "git::https://git.url.here/aws/sqs.git?ref=feature/sqs_queue"
name = local.name
delay_seconds = var.delay_seconds
max_message_size = var.max_message_size
message_retention_seconds = var.message_retention_seconds
visibility_timeout_seconds = var.visibility_timeout_seconds
policy = var.policy
receive_wait_time_seconds = var.receive_wait_time_seconds
redrive_policy = var.attach_redrive_policy == true ? local.redrive_policy : ""
fifo_queue = var.fifo_queue
content_based_deduplication = var.content_based_deduplication
kms_master_key_id = data.aws_kms_alias.kms_sqs_key.target_key_arn
kms_data_key_reuse_period_seconds = var.kms_data_key_reuse_period_seconds
# I want to overwrite the Tags in comm module with the below tags
tags = merge(module.tags.base_tags, module.tags.data_tags, module.tags.extra_tags,
{
"Name" = "${local.name}_sqs_tags"
}
)
}
module "tags" {
source = "../../../module/tags"
environment = var.environment
purpose = var.description
assetName = local.name
backupOwner = "owner.email"
dataCustodian = "custodian.email"
}
当我这样做时 Terraform plan
除了标签之外,一切都计划得很好,我仍然只看到 comm 模块具有的 4 个标签,而不是将我的标签推到该模块的顶部
P.S。如果还有其他想法,比如在无法覆盖的情况下要求社区对他们的模块进行相关编辑。我会很高兴并且非常感激。谢谢
是的,我认为不可能覆盖模块端的标签,因为使用这 4 个标签是“硬编码”的。
您必须对社区模块进行修改:
在变量方面:
variable "tags" {
type = map(string)
default = null
description = "Override tags"}
在资源端(main.tf 模块)
tags = var.tags == null ? {
environment = var.environment
project = var.project
application_id = var.applicationId
purpose = var.purpose
} : var.tags
Terraform 新手:: 我们有一个用于 SQS 的社区模块,大多数开发人员使用它来启动 SQS 队列,它带有很少 (4) 个标签(社区目前没有可重复使用的标签模块)。 对于我的项目,我的 SQS 队列需要比社区 SQS 有额外的标签,这里需要注意的是他们不允许我们在他们的模块中进行更改。 我有一个我编写的标签模块,我想将它与社区 SQS 模块一起使用。 长话短说,我想用我的标签模块
覆盖下面社区 SQS 模块中的整个标签块- 按原样使用社区模块并将额外的地形添加到“重新推送”标签
社区 SQS 模块(命名为 main.tf):-
resource "aws_sqs_queue" "new_terraform_queue" {
name = var.name
delay_seconds = var.delay_seconds
max_message_size = var.max_message_size
message_retention_seconds = var.message_retention_seconds
visibility_timeout_seconds = var.visibility_timeout_seconds
policy = var.policy
receive_wait_time_seconds = var.receive_wait_time_seconds
redrive_policy = var.redrive_policy
fifo_queue = var.fifo_queue
content_based_deduplication = var.content_based_deduplication
tags = {
environment = var.environment
project = var.project
application_id = var.applicationId
purpose = var.purpose
}
}
将上述模块采购到我的项目中:
module "main" {
source = "git::https://git.url.here/aws/sqs.git?ref=feature/sqs_queue"
name = local.name
delay_seconds = var.delay_seconds
max_message_size = var.max_message_size
message_retention_seconds = var.message_retention_seconds
visibility_timeout_seconds = var.visibility_timeout_seconds
policy = var.policy
receive_wait_time_seconds = var.receive_wait_time_seconds
redrive_policy = var.attach_redrive_policy == true ? local.redrive_policy : ""
fifo_queue = var.fifo_queue
content_based_deduplication = var.content_based_deduplication
kms_master_key_id = data.aws_kms_alias.kms_sqs_key.target_key_arn
kms_data_key_reuse_period_seconds = var.kms_data_key_reuse_period_seconds
# I want to overwrite the Tags in comm module with the below tags
tags = merge(module.tags.base_tags, module.tags.data_tags, module.tags.extra_tags,
{
"Name" = "${local.name}_sqs_tags"
}
)
}
module "tags" {
source = "../../../module/tags"
environment = var.environment
purpose = var.description
assetName = local.name
backupOwner = "owner.email"
dataCustodian = "custodian.email"
}
当我这样做时 Terraform plan
除了标签之外,一切都计划得很好,我仍然只看到 comm 模块具有的 4 个标签,而不是将我的标签推到该模块的顶部
P.S。如果还有其他想法,比如在无法覆盖的情况下要求社区对他们的模块进行相关编辑。我会很高兴并且非常感激。谢谢
是的,我认为不可能覆盖模块端的标签,因为使用这 4 个标签是“硬编码”的。 您必须对社区模块进行修改:
在变量方面:
variable "tags" {
type = map(string)
default = null
description = "Override tags"}
在资源端(main.tf 模块)
tags = var.tags == null ? {
environment = var.environment
project = var.project
application_id = var.applicationId
purpose = var.purpose
} : var.tags