Terraform Combine Variable and String

You can’t use interpolation in a tfvars file.

Instead you could either join it directly in your Terraform like this:

terraform.tfvars

hosted_zone = "example.com"
domain      = "my"

main.tf

resource "aws_route53_record" "regional" {
  zone_id = data.aws_route53_zone.selected.zone_id
  name    = "${var.domain}.${var.hosted_zone}"
  type    = "A"
  ttl     = "300"
  records = ["4.4.4.4"]
}

Or, if you always need to compose these things together you could use a local:

locals {
  domain = "${var.domain}.${var.hosted_zone}"
}

resource "aws_route53_record" "regional" {
  zone_id = data.aws_route53_zone.selected.zone_id
  name    = local.domain
  type    = "A"
  ttl     = "300"
  records = ["4.4.4.4"]
}

Leave a Comment