Evert
Evert

Reputation: 308

vpc_zone_identifier should be a list

I'm not getting my head around this. When doing a terraform plan it complains the value should be a list. Fair enough. Let's break this down in steps.

The error

1 error(s) occurred:

* module.instance-layer.aws_autoscaling_group.mariadb-asg: vpc_zone_identifier: should be a list

The setup

The VPC and subnets are created with terraform in another module. The outputs of that module give the following:

"subnets_private": {
                    "sensitive": false,
                    "type": "string",
                    "value": "subnet-1234aec7,subnet-1234c8a7"
                },

In my main.tf I use the output of said module to feed it into a variable for my module that takes care of the auto scaling groups:

  subnets_private                         = "${module.static-layer.subnets_private}"

This is used in the module to require the variable:

variable "subnets_private" {}

And this is the part where I configure the vpc_zone_identifier:

Attempt: split

resource "aws_autoscaling_group" "mariadb-asg" {
  vpc_zone_identifier  = "${split(",",var.subnets_private)}"

Attempt: list

resource "aws_autoscaling_group" "mariadb-asg" {
  vpc_zone_identifier  = "${list(split(",",var.subnets_private))}"

Question

The above attempt with the list(split( should in theory work. Since terraform complains but doesn't print the actual value it's quite hard to debug. Any suggestions are appreciated.

Filling in the value manually works.

Upvotes: 7

Views: 7032

Answers (2)

b boy
b boy

Reputation: 31

For the following helps:

vpc_zone_identifier  = ["${data.aws_subnet_ids.all.ids}"]

Upvotes: 3

Evert
Evert

Reputation: 308

When reading the documentation very carefully it appears the split is not spitting out clean elements that afterwards can be put into a list. They suggest to wrap brackets around the string ([" xxxxxxx "]) so terraform picks it up as a list.

If my logic is correct that means subnet-1234aec7,subnet-1234c8a7 is outputted as subnet-1234aec7","subnet-1234c8a7 (note the quotes), assuming the quotes around the delimiter of the split command have nothing to do with this.

Here is the working solution

vpc_zone_identifier  = ["${split(",",var.subnets_private)}"]

Upvotes: 4

Related Questions