首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Terraform 0.12迁移-具有默认对象的变量

Terraform 0.12迁移-具有默认对象的变量
EN

Stack Overflow用户
提问于 2020-10-19 23:05:22
回答 1查看 427关注 0票数 2

我试图将我的TF 0.11代码升级到0.12,但我遇到了一个变量问题。

在TF 0.11中,此块在variables.tf文件中按预期工作

代码语言:javascript
复制
variable "postgres_dbs" {
  type = "map"

  default = {
    postgres1 = {
      name_postfix = "postgres",
      enable      = true,
      sku         = "MO_Gen5_16",
      capacity    = "16"
    }
    postgres2 = {
      name_postfix = "postgres-2",
      enable      = false,
      sku         = "MO_Gen5_16",
      capacity    = "16"
    }
    postgres3 = {
      name_postfix = "postgres-3",
      enable      = false,
      sku         = "MO_Gen5_16",
      capacity    = "16"
    }
    postgres4 = {
      name_postfix = "postgres-4",
      enable       = false,
      sku          = "MO_Gen5_16",
      capacity     = "16"
    }
    postgres5 = {
      name_postfix = "postgres-5",
      enable       = false,
      sku          = "MO_Gen5_16",
      capacity     = "16"
    }
    postgres6 = {
      name_postfix = "postgres-6",
      enable       = false,
      sku          = "MO_Gen5_16",
      capacity     = "16"
    }
    postgres7 = {
      name_postfix = "postgres-7",
      enable       = false,
      sku          = "MO_Gen5_16",
      capacity     = "16"
    }
    postgres8 = {
      name_postfix = "postgres-8",
      enable       = false,
      sku          = "MO_Gen5_16",
      capacity     = "16"
    }
  }
}

在运行terraform 012upgrade命令(它完成时没有错误)之后,TF将块更改为use

代码语言:javascript
复制
variable "postgres_dbs" {
  type = map(string)

但是运行terraform validate时的错误是:

代码语言:javascript
复制
This default value is not compatible with the variable's type constraint:
element "postgres6": string required.

有什么建议吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-20 03:04:57

您可以更新和微调您的类型规范,如下所示:

代码语言:javascript
复制
type = map(object({
  name_postfix = string
  enable       = bool
  sku          = string
  capacity     = string
}))

理想情况下,您可以将capacity对象参数指定为number,但是您将该参数的输入转换为string,因此这将导致不兼容,除非您将输入指定为其自然的number类型。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64430064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档