简体   繁体   English

在 Terraform 中使用变量作为标记时出错

[英]Error Using Variable as a Tag in Terraform

I have a question about tags in Terrafrom.我对 Terrafrom 中的标签有疑问。 I have this variables, and I'd like to use the Transit variable description name as a tag in my main.tf file.我有这个变量,我想在我的 main.tf 文件中使用 Transit 变量描述名称作为标记。 How do I go about it?我怎么go一下呢?

#VPC CIDRs
variable "All_VPCs" {
  type = map(any)
  default = {
    Dev_VPC = {
      ip = "10.0.3.0/24"
      instance_tenancy = "default"
    }
    Transit_VPC = {
      ip = "10.0.4.0/23"
      instance_tenancy = "default"
      description = "Transit_VPC"
    }
  }
}

I used this, but it didn't work.我用过这个,但没有用。

resource "aws_internet_gateway" "Transit_Internet_Gateway" {
  vpc_id = var.All_VPCs.Transit_VPC

tags = {
    Name = "${var.All_VPCs.Transit_VPC.description}" + " Internet_Gateway"
  }

You can't concatenate strings in Terraform with a + operator.您不能使用+运算符连接 Terraform 中的字符串。 The correct method of doing this is to use string interpolation (which you are already partially doing):这样做的正确方法是使用字符串插值(您已经部分这样做):

tags = {
    Name = "${var.All_VPCs.Transit_VPC.description} Internet_Gateway"
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM