[英]How can I attach a persistent EBS volume to an EC2 Linux launch template that is used in an autoscaling group?
[英]Add tag to launch template for ec2 nodes
我正在尝试将标签添加到启动模板,以便标记和命名 ec2 节点。
当我在模块中添加硬编码标签时它可以工作,但我的想法是拥有动态标签并能够与本地标签合并。
module
resource "aws_autoscaling_group" "ecs_asg" {
name = var.name_asg
max_size = var.max_size
min_size = var.min_size
.
.
.
service_linked_role_arn = var.service_linked_role_arn
tags = var.asg_tags
launch_template {
id = aws_launch_template.launch_template.id
version = "$Latest"
}
}
variables.tf
variable "asg_tags" {
type = map(string)
default = {}
}
main.tf
name_asg = "leo-nombre-asg"
max_size = var.max_size
min_size = var.min_size
.
.
.
asg_tags = merge(
local.tags,
{
propagate_at_launch=true,
},
)
locals.tf
locals {
tags = {
"Accountable" = "business"
"Deploy" = "terraform"
"Role" = "services"
}
}
terraform validate
│ Error: Incorrect attribute value type
│
│ on modules\ecs\main.tf line 38, in resource "aws_autoscaling_group" "ecs_asg":
│ 38: tags = var.asg_tags
│ ├────────────────
│ │ var.asg_tags is a map of string
│
│ Inappropriate value for attribute "tags": set of map of string required.
这里需要的两个修复都是针对asg_tags
参数参数值中的类型:
asg_tags = [merge(local.tags, { "propagate_at_launch" = "true" })]
这里我们使用list/set
构造函数来转换类型set(map(string))
。 Terraform 将强制使用构造函数set
而不是list
,只要指定要set
的类型即可。 由于无论如何我们都需要修复类型声明以与资源属性模式兼容,因此这样做很方便:
variable "asg_tags" {
type = set(map(string))
default = {}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.