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.
${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 wrotevar.envis not interesting, because that just tells Terraform to load from a directory literally calledvar.envand so it's not surprising that this failed with a "no file exists" error.)