I want to output a postgreql provider from a module in terraform then use it to further configure the database.

Current use case is a module creating a postgres rds instance and i want to return a "postgresql provider" to continue setting up the roles and databases.


No you cannot do that. You need to return the login values from the module so you can setup a provider outside the module using those values.

I would just edit the module and do what you need inside the module so you don't have to output those things.


Instead of doing that, switch the principle and inject a Provider.

E.g. in your module you have

provider "azurerm" {
  version = "~> 1.16"

Now in the actual Environment I would switch to aliased Providers like

provider "azurerm" {
  version = "~> 1.16"
  alias   = "goldenrule"

Then you can inject it into the module like this

module "something-great" {
  source = "./great/thang/"
  providers = {
    azurerm  = "azurerm.goldenrule"
  • and then inside the module, you reference that azurerm provider how? I'm getting errors when I try the obvious: provider = "azurerm" – Christopher Thomas Jun 24 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.