Optum/runiac

Interpolation of variables in backend.tf

samar-upadhyay opened this issue · 6 comments

I want to be able to use a variable in the key field in backend.tf for azurerm provider. The use case is that I am building a self service app registration component and I want to keep application specific tfstate files separate. I want to append app name in the key. Currently, there isn't a way to do it.

Thank you @samar-upadhyay. To clarify, by app name are you referring to a runiac provided variable, e.g. runiac_project?

@tiny-dancer - Possibly. We could probably use this variable to build the key in backend.tf if we added the substitution in the interpolation code. Or it could be any fringe variable that can be used to build the key. It just happens to be app name in our case.
In my runiac.yml, I have:

project: application-resource-creation

Application name (app1, app2, etc.) is an input variable based on which the project provisions the necessary resources needed to run the application. I want the state file to be unique per application so I have the ability to destroy the application resources and recreate them. So the key name would be something like this:

key = "${var.app_name}.${var.runiac_step}.terraform.tfstate"

Ah, okay. That adds a bit of complexity to generally support incoming variables for interpolation, up to this point we've been leveraging a select few variable in a quick win fashion. We won't be adding support for general variable interpolation in the current fashion. We may switch to use template files which would help accomplish this.

Additionally you could leverage entrypoint.sh to do any string interpolation or templating as desired.

#24 may be of interest as well

Ah, okay. That adds a bit of complexity to generally support incoming variables for interpolation, up to this point we've been leveraging a select few variable in a quick win fashion. We won't be adding support for general variable interpolation in the current fashion. We may switch to use template files which would help accomplish this.

Additionally you could leverage entrypoint.sh to do any string interpolation or templating as desired.

OK. That is currently what I'm doing.

#24 may be of interest as well

Interesting. I'll take a look.