Inappropriate value for attribute "value": string required in terraform

I’m creating Elastic beanstalk with terraform inside a vpc and I need to have at least two subnets because when I try to apply with only one I get an error that demands at least two. So here I define two subnets.

resource "aws_elastic_beanstalk_application" "elasticapp" {
  name = var.elasticapp
}

resource "aws_elastic_beanstalk_environment" "beanstalkappenv" {
  name                = var.beanstalkappenv
  application         = aws_elastic_beanstalk_application.elasticapp.name
  solution_stack_name = var.solution_stack_name
  tier                = var.tier

  setting {
    namespace = "aws:ec2:vpc"
    name      = "VPCId"
    value     = "${aws_vpc.prod-vpc.id}"
  }
  setting {
    namespace = "aws:ec2:vpc"
    name      = "Subnets"
    value     = ["${aws_subnet.prod-subnet-public-1.id}", "${aws_subnet.prod-subnet-public-2.id}"]

After running terraform apply I get this error message.

Inappropriate value for attribute "value": string required.

I guess it’s a syntax thing but I can’t seem to figure it out.

>Solution :

According to the AWS documentation:

The IDs of the Auto Scaling group subnet or subnets. If you have multiple subnets, specify the value as a single comma-separated string of subnet IDs (for example, "subnet-11111111,subnet-22222222")..

You are specifying the subnets in an array. You would want to create a string instead:

resource "aws_elastic_beanstalk_environment" "beanstalkappenv" {
  name                = var.beanstalkappenv
  application         = aws_elastic_beanstalk_application.elasticapp.name
  solution_stack_name = var.solution_stack_name
  tier                = var.tier

  setting {
    namespace = "aws:ec2:vpc"
    name      = "VPCId"
    value     = aws_vpc.prod-vpc.id
  }
  setting {
    namespace = "aws:ec2:vpc"
    name      = "Subnets"
    value     = "${aws_subnet.prod-subnet-public-1.id},${aws_subnet.prod-subnet-public-2.id}"
  }
}

Leave a Reply