[英]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.