Accessing backend configuration

Hi guys,
I’ve been searching without success, but I would like to know if it is possible to access the backend configuration from within another resource.

I’m using the PG backend, configured through the command line with the backend-config arguement, so that the conn_str is unique.

We’re using a single database, so all module are sharing the same conn_str, only the workspace is different.

However, if I want to use a terraform_remote_state, that use the same PG connection string, I have to replicate the configuration as I cannot access value of the backend.

I tried terraform.backend.conn_str and but that doesn’t exist, only terraform.workspace does.

Is accessing the backend configuration currently supported? Or do I have to duplicate the configuration for every module?


Hi @pbusquemdf,

The backend and the rest of the configuration are two completely separate ideas in Terraform, so indeed if they do have some configuration arguments in common then you’ll need to specify them in both places.

Backend configuration is essentially global state in Terraform, so to expose it in the way you’re thinking would cause your child modules to be coupled to the specific configuration they are called from, and that would defeat a major purpose of modules: that they can be called from many different configurations that might have very different usage patterns, such as using a different backend entirely. I’d recommend writing modules such that they are decoupled from their callers to give you the most flexibility for refactoring in future.