Terraform string/list issue: variable in module should be type list, got string

1,820 views
Skip to first unread message

Traiano Welcome

unread,
Mar 2, 2017, 9:53:02 AM3/2/17
to Terraform
Hi List

I have a security group defined as a variable in a separate variables.tf file:


---


variable "security_group_id" {

  default = {

    sg_id = "sg-xzcdvfvf1"

  }

}


----


And I'm using it in a main file in a module as follows:



---

module "ec2-cluster-nodes" {

  source = "../modules/ec2"

  availability_zone           = "us-east-1a"

  associate_public_ip_address = true


  role       = "whatever"

  aws_region = "${var.region}"

  env        = "${var.environment}"

  vpc        = "${var.vpc_id}"


  security_group_ids = "${var.security_group_id["sg_id"]}"


  subnet_id  = "${var.default_subnet}"

  key_name                    = "${var.key_name}"

  ami_id              = "${var.cluster_edge["ami"]}"

  instance_type       = "${var.cluster_edge["instance_type"]}"

  number_of_instances = "${var.cluster_edge["count"]}"

}

----


However when I run terraform apply I get this:


---

bash-3.2$ 

(reverse-i-search)`te': terraform plan

bash-3.2$ terraform plan

var.environment

  Enter a value: dev


var.region

  Enter a value: us-east-1


Error configuring: 1 error(s) occurred:


* variable security_group_ids in module ec2-cluster-nodes should be type list, got string

---



However it looks very much to be defined as a list ... Is there something I'm missing here?

Thanks in advance for any help!
Traiano





Lowe Schmidt

unread,
Mar 2, 2017, 10:19:08 AM3/2/17
to terrafo...@googlegroups.com
Your variable is (implicitly) defined as a map. 

There three different types of variable

variable "strings" { default = "Is_this" }
variable "list" { default = [ "would", "be", this" ] }
variable "map" {  default = { "Key" = "Value", "Key2" = "Value2 } }

What you probably wanted was: 

variable "security_group_id" {

  default = [ "sg-xzcdvfvf1" ]

}

Reply all
Reply to author
Forward
0 new messages