0

I am improvising a terraform process for Fabric that has static hardcoded configurations on a config.yml. They have not used variable.tf for configurations. The variable.tf does include environment handle- dev, prod, that is being given by the ADO pipelines.

The config.yml is being parsed into locals(config.tf), by yamldecode files.

To quickly add flexibility. I wanted to add var.env into this declaration, do different configuration variables can be enabled for each environment.

current config

workspace_role_assignment = yamldecode(file("${path.root}/config/workspace_role_assignment.yml)) 

I have tried some options for the yaml decode, but it does not initialize the var.env within yamldecode during run time. Both options fail.

workspace_role_assignment = yamldecode(file("${path.root}/config/${var.env}/workspace_role_assignment.yml"))

There is no error, however the yamldecode fails to find the file, as the for each shows plan skipping the objects.

Is there a workaround for this process? What am I doing wrong? Thank you.

2
  • The first example you tried with the ${var.env} interpolation syntax ought to work. Can you edit your question to focus only on that case, and mention which error message Terraform returned when you tried that? (The form where you just wrote var.env is not interesting, because that just tells Terraform to load from a directory literally called var.env and so it's not surprising that this failed with a "no file exists" error.) Commented Jul 22 at 22:38
  • Modified. For some reason, the Plan succeeded this time around. Will run few checks again Commented Jul 23 at 17:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.