【问题标题】:Terraform | variable instance_type in module should be type string, got map地形 |模块中的变量 instance_type 应该是字符串类型,得到地图
【发布时间】:2019-10-22 20:32:57
【问题描述】:

当我尝试为 AMI 使用数据块时出现以下错误:-

错误:module.ec2-wf.var.instance_type:模块 ec2-wf 中的变量 instance_type 应该是字符串类型,得到地图 错误:module.ec2-wf.var.ami:模块 ec2-wf 中的变量 ami 应该是字符串类型,得到地图 make: *** [验证] 错误 1

下面是我的 terraform 结构:-

project
    modules
        app1
        app2
        app3
        common
            global-variables.tf
            main.tf
            makefile
            provider.tf
            vpc.tf
        global
            acm
            alb
            asg
            ec2
            efs
            lc
            rds
            redis
            subapp
                ec2
                    main.tf
                    makefile
                    provider.tf
                    variable.tf

project/modules/global/subapp/ec2/main.tf

module "ec2-wf" {
    source = "../../../global/ec2"

    name                    =   "${var.name}"
    db_remote_state_bucket  =   "s3-terraform-state"
    db_remote_state_key     =   "subapp/ec2/terraform.tfstate"
    key_name                =   "${lookup(var.key_name, terraform.workspace)}"
#    ami                     =   "${lookup(var.ami, terraform.workspace)}"
#    instance_type           =   "${lookup(var.instance_type, terraform.workspace)}"
    ami                     =    "${var.ami}"
    instance_type           =    "${var.instance_type}"

    tags = {
        Name        =   "${var.project}"
        Environment =   "${lookup(var.env, terraform.workspace)}"
    }
}

项目/模块/global/ec2/variables.tf

variable "instance_type" {
    description = "This describes the  Map the environment whether it is dev/test/prd etc"
}

variable "ami" {
    description = "This describes the  Map of Availability Zones to deploy"
    default     =   ""
}

【问题讨论】:

  • 为这些变量传递的值是什么?该错误与为其中一个提供的默认值不一致,并且缺少为另一个提供的默认值。

标签: terraform


【解决方案1】:

我觉得很好。可能看起来它出于某种原因正在查看注释行?因为未注释的版本看起来不错。

#    ami                     =   "${lookup(var.ami, terraform.workspace)}"
#    instance_type           =   "${lookup(var.instance_type, terraform.workspace)}"

为确保您始终可以指定类型(如下所示)。如果这不起作用,请删除注释行,看看它是否仍然发生。

variable "ami" {
  type = string
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 2016-05-31
    • 2021-06-19
    • 1970-01-01
    • 2023-02-04
    相关资源
    最近更新 更多