Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vpc_zone_identifier should be a list

Tags:

terraform

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.

like image 416
Evert Avatar asked Aug 29 '17 14:08

Evert


People also ask

How do you set the Auto Scaling group in terraform?

Click on the AWS Auto Scaling group menu item in the EC2 dashboard to manage your Auto Scaling groups. The Desired number of AWS EC2 instances will be launched in the AWS Cloud in the EC2 dashboard with the below Autoscaling. 3. Lastly, click on AWS Auto Scaling Launch Configuration in the EC2 dashboard.

What is terraform ASG?

Resource: aws_autoscaling_group. Provides an Auto Scaling Group resource.


2 Answers

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)}"]
like image 106
Evert Avatar answered Sep 28 '22 04:09

Evert


For the following helps:

vpc_zone_identifier  = ["${data.aws_subnet_ids.all.ids}"]
like image 38
b boy Avatar answered Sep 28 '22 02:09

b boy