amazon-web-services - 使用带有多个资源的 tag_secifications 设置启动模板
问题描述
基于下面给出的文档示例,我看到了为实例类型设置的标签。但是,如果我希望将相同的标签应用于多个资源,那么我将如何设置它 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template
tag_specifications {
resource_type = "instance"
tags = {
Name = "test"
}
}
解决方案
您要么指定它两次,要么使用动态块。动态块的示例是:
variable "to_tag" {
default = ["instance", "volume"]
}
resource "aws_launch_template" "foo" {
name = "foo"
image_id = data.aws_ami.server.id
instance_type = "t2.micro"
dynamic "tag_specifications" {
for_each = toset(var.to_tag)
content {
resource_type = tag_specifications.key
tags = {
Name = "test"
}
}
}
}
或者简单地指定它两次:
resource "aws_launch_template" "foo" {
name = "foo"
image_id = data.aws_ami.server.id
instance_type = "t2.micro"
tag_specifications {
resource_type = "instance"
tags = {
Name = "test"
}
}
tag_specifications {
resource_type = "volume"
tags = {
Name = "test"
}
}
}
推荐阅读
- karate - 我可以在测试中更改身份验证令牌方面获得一些帮助吗?
- java - 如何在 com.sun.jdi.ObjectReference 上中止长时间运行的 invokeMethod?
- c++ - QTcpSocket 未接收到服务器发送的数据
- php - 使用phpSpreadSheet读写excel文件后,图形消失
- java - 带有 React 的 Struts Web 应用程序
- css - 当一个类已经存在时如何实现一个 sr-only 类
- json - 如何解析雪花中的json?
- javascript - 如何在没有未捕获类型错误的情况下访问此嵌套数组?
- reactjs - 使用 mongoDb 将 Next.js 应用程序部署到 Heroku 时出错
- node.js - TypeError: schema[parameter].validateAsync 运行 API 调用时?