Terraform从v0.11迁移到v0.12时出现标签问题。

huangapple go评论66阅读模式
英文:

Terraform migration from v0.11 to v0.12 problem with tags

问题

我正在尝试将我的 Terraform 计划从 v0.11 迁移到 v0.12 版本的 Terraform,并且在执行验证时,我遇到了相同错误的一些错误:“不受支持的块类型”,服务将问题标记在“TAGS”标记中,并附上了以下评论:

> 不应在此处使用类型为“tags”的块。您是不是想定义参数“tags”?如果是,请使用等号为其分配一个值。

一个示例就是这个有问题的资源:

resource "aws_vpc" "VPC" {
  cidr_block           = "10.0.0.0/24"
  enable_dns_hostnames = "true"
  enable_dns_support   = "true"

  tags {
    Name        = "${var.name}-VPC-Default"
    Environment = var.env
    Region      = var.region
  }
}

我在文档中阅读了关于这个资源的信息,它支持标记类型“TAGS”,并且在 v0.11 版本中可以正常工作。

关于我的问题,有什么建议吗?

英文:

I'm trying migrate my terraform plan from v0.11 to v0.12 terraform version and when I execute the validation I have some error with the same error : "Unsupported block type" and the service mark the trouble into the "TAGS" tag with that comment:

>Blocks of type "tags" are not expected here. Did you mean to define argument "tags"? If so, use the equals sign to assign it a value.

One example it's this troubling resource:

resource "aws_vpc" "VPC" {
  cidr_block           = "10.0.0.0/24"
  enable_dns_hostnames = "true"
  enable_dns_support   = "true"

  tags {
    Name        = "${var.name}-VPC-Default"
    Environment = var.env
    Region      = var.region
  }
}

I read into the documentation about this resource that support tag type "TAGS" and into the v0.11 version it's working fine.

Any suggestion about what it's my problem?

答案1

得分: 3

错误说明在Terraform 0.12中,tags不再是一个块,而是一个参数。Terraform中的块看起来像:

block { ... }

这就是你当前的tags看起来的方式。参数看起来像:

argument = value

因此,你需要将你的tags从块转换为参数。可以像下面这样完成:

tags = {
  Name        = "${var.name}-VPC-Default"
  Environment = var.env
  Region      = var.region
}

其中,tags现在被赋予了你以前在块内包含的map值。

英文:

The error is explaining that in Terraform 0.12 tags are no longer a block, but rather now an argument. A block in Terraform appears like:

block { ... }

which is how your tags currently appear. An argument appears like:

argument = value

Therefore, you need to convert your tags from a block to an argument. That can be done like the following:

tags = {
  Name        = "${var.name}-VPC-Default"
  Environment = var.env
  Region      = var.region
}

where tags is now being assigned the map value you formerly contained within your block.

huangapple
  • 本文由 发表于 2020年1月3日 20:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定