模块中的变量instance_type应该是string类型,得到map

问题描述 投票:0回答:1

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

Error: module.ec2-wf.var.instance_type: variable instance_type in module ec2-wf should be type string, got map
Error: module.ec2-wf.var.ami: variable ami in module ec2-wf should be type string, got map
make: *** [validate] Error 1

下面是我的地形结构:-

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

项目/模块/全局/子应用/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)}"
    }
}

项目/模块/全局/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个回答
0
投票

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

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

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

variable "ami" {
  type = string
}
© www.soinside.com 2019 - 2024. All rights reserved.