当我尝试为AMI使用数据块时,我遇到了以下错误:-
错误:module.ec2-wf.var.instance_type:模块ec2-wf中的变量instance_type应该是字符串类型,得到了映射 错误:module.ec2-wf.var.ami:模块ec2-wf中的变量ami应该是字符串类型,得到了映射 制作:*** [验证]错误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
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)}"
}
}
project / modules / 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 = ""
}
答案 0 :(得分:0)
对我来说很好。可能出于某种原因看起来正在注视注释行?由于未注释的版本看起来不错。
# ami = "${lookup(var.ami, terraform.workspace)}"
# instance_type = "${lookup(var.instance_type, terraform.workspace)}"
为确保这一点,您始终可以指定类型(如下所示)。如果那不起作用,请删除注释行,看看是否仍然存在。
variable "ami" {
type = string
}