Terraform

How to reference variable from inside of string literal? (bonus question: how that type of expression is called?)

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Using the syntax: "${var.VAR_NAME}". It's called "interpolation".

Very common to see it used in user_data attribute related to instances.

user_data = <<-EOF
            This is some fabulos string
            It demonstrates how to use interpolation
            Yes, it's truly ${var.awesome_or_meh}
            EOF