Terraform - Concatonate / Join Variables (dynamic interpolation)

Viewed 2977

Is it possible to concatonate / join variables in terraform? I am struggling to find a reference to correct syntax.

I would like to do something like this:

variable "env" {
  default = "production"
}

variable "vpc_name" {
  default = "cloudy"
}

resource "aws_subnet" "${var.env}_${var.vpc_name}_pub1" {  
  vpc_id = "${aws_vpc.${var.vpc_name}.id}"  
  cidr_block = "10.0.1.0/24"  
  availability_zone = "us-east-1a"  
}

Which would effectively achieve something like this:

resource "aws_subnet" "production_cloudy_pub1" {  
  vpc_id = "${aws_vpc.cloudy.id}"  
  cidr_block = "10.0.1.0/24"  
  availability_zone = "us-east-1a"  
}
1 Answers
Related