0

so I am trying to do interpolation i-e with public scheme and terraform.workspace so subnets will dynamically get selected. For that tried merging terraform.workspace with elb_subnets but its throwing error that only supported key for 'terraform.X' interpolations is 'workspace'

variable "elb_scheme" {
  default = "public"
}

variable "prod_elb_subnets" {
  type = "map"

  default = {
    public  = "subnet-23ywe324, subnet-234hj34, subnet-cdh7868"
    private = "subnet-hj3h2323, subnet-jihi782, subnet-237dew"
  }
}

variable "qa_elb_subnets" {
  type = "map"

  default = {
    public  = "subnet-234ee234, subnet-da238sdf, subnet-sd2233"
    private = "subnet-09jsdf23, subnet-hi232rf, subnet-89832w32"
  }
}

  setting {
    namespace = "aws:ec2:vpc"
    name      = "ELBSubnets"

    value = "${var.(terraform.workspace_elb_subnets["${var.elb_scheme}"])}"
  }

output:

Error: module.ebs.aws_elastic_beanstalk_environment.beanstalk: 1 error(s) occurred:

* module.ebs.aws_elastic_beanstalk_environment.beanstalk: terraform.workspace_elb_subnets: only supported key for 'terraform.X' interpolations is 'workspace'

Terraform workspace

terraform workspace list
  default
* qa
0

Can you tag your subnets? Its easier to use a datasource lookup based off environment then to hard code them in a variable.

Something like this if you just need the ids

data "aws_subnet_ids" "subnets" {

  tags {
    Env = "${terraform.workspace}"
  }
}

If your subnets are tagged with the workspace then you can use them like

TO get a single subnet based on count

"${element(data.aws_subnet_ids.subnets.ids, count.index)}" 

To get them all in a list

"${data.aws_subnet_ids.subnets.ids}"

See the following for more info

https://www.terraform.io/docs/providers/aws/d/subnet_ids.html

Datasources are very usefull and you should look into using them and not hard code anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.