Terraform try function


I have a python lambda function that have an environment variable that is different depending on the region and environment. in the terraform main file I have the following code to look up the a local variable below. but it is giving me the following error. can you advise how I can lookup the variable


 EP_URL: try(local.ep_urls[${var.region_short}][${var.env}], null)


  ep_urls = {
    "euw1" = {
	"dev"     = "https://es-dev-euw1-h5dfsdrsbij7tbjiehcwmcima.us-east-1.es.amazonaws.com:443",
	"qa"      = "https://es-qa-euw1-h5dfsdrsbij7tbjiehcwmcima.us-east-1.es.amazonaws.com:443",
    "use1" = {
	"dev"     = "https://es-dev-use1-h5dfsdrsbij7tbjiehcwmcima.us-east-1.es.amazonaws.com:443",
	"qa"      = "https://es-qa-use1-h5dfsdrsbij7tbjiehcwmcima.us-east-1.es.amazonaws.com:443",


On ../../../modules/lambda/main.tf line 36: Expected the start of an
│ expression, but found an invalid expression token.
│ Error: Invalid character
│ On ../../../modules/lambda/main.tf line 36: This character is not used
│ within the language.

Hi @paulixml,

{var.env} is not a valid expression in Terraform, that may be part of the problem, and may be as simple as removing the extra braces. It would be easier to diagnose with a correctly formatted example of the configuration, so that we can better see what you are trying to do.

hi, thanks

the webpage removed the $ symbol for some reason. I am trying to look up the correct url based on the region and env. the try function can’t use variables


(Markdown uses ``` to delimit preformatted text, or you could use the <> button to insert the text for you.)

If you have $ in the expression, that is also invalid. If you want to refer to a variable, you reference the variable directly, e.g. just use var.env on its own. The ${} syntax is only used within string templates.

ah, that’s the problem