Terraform Provider Block Generator

Work out which providers a configuration needs from its resource types, and get a required_providers block with every source spelled out. The reason to spell them out is below.

Paste below, or drop a file anywhere on this panel

Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.

The answer appears here

Paste on the left and press Generate. Nothing leaves this tab.

Examples

Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.

A configuration using the Docker provider

docker is kreuzwerker/docker, so omitting source makes init fail confusingly

resource "docker_container" "app" {
  name = "app"
}

A resource pinned to an aliased provider

The alias needs its own provider block, and a module needs it passed explicitly

resource "aws_s3_bucket" "eu" {
  provider = aws.eu_west
  bucket   = "eu"
}

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Leaving source off a provider that is not HashiCorp's

    Terraform looks for hashicorp/NAME, which for docker, kubectl, mysql and several others is either absent or an abandoned namesake. The error looks like a registry or network fault.

    Instead:Always write the source. docker is kreuzwerker/docker.

  2. Expecting a module to inherit an aliased provider

    Inheritance covers the default provider only. An alias has to be passed in, and the module validates fine on its own, so the failure appears at the call site.

    Instead:Pass it: providers = { aws = aws.eu_west } in the module block.

  3. Putting a provider block inside a reusable module

    The caller loses control of the region and the credentials, and the module cannot be used twice against different accounts.

    Instead:Declare required_providers in the module and configure the provider in the root module.

An omitted source means hashicorp/, and that is often wrong

Terraform resolves an unqualified provider name to registry.terraform.io/hashicorp/NAME. For a good number of common providers that address is not where the provider lives.

The providers that are not HashiCorp's

docker is kreuzwerker/docker. kubectl is gavinbunney/kubectl. mysql is petoju/mysql, postgresql is cyrilgdn/postgresql, github is integrations/github, datadog is DataDog/datadog, cloudflare is cloudflare/cloudflare. Without an explicit source, init either fails with a registry 404 that looks like a network problem, or finds an abandoned provider of the same name and then fails on arguments the real one supports.

Spell out every source, including the HashiCorp ones

It costs one line and it removes a class of question. A reader can see where each provider comes from without knowing the default, and moving to a mirror or to OpenTofu later becomes a search-and-replace rather than an investigation.

An aliased provider is not implicit

Referencing aws.eu_west with no matching provider block that has that alias fails at validate, and the message names the alias without saying that the missing thing is a block. Every alias needs its own provider block.

A module using an aliased provider needs it passed explicitly

providers = { aws = aws.eu_west } in the module call. Provider inheritance works for the default provider and not for aliases, which is the part that surprises people: the module validates on its own and fails when called.

A provider block inside a reusable module is an anti-pattern

It takes the region and the credentials away from the caller, and it means the module cannot be used twice against two accounts. A module should declare required_providers and let the caller configure them. Keep provider blocks in root modules.

Version constraints belong in required_providers, not the provider block

version inside a provider block has been deprecated since 0.13. It still works, and it is ignored when the same provider appears in required_providers, so two places can disagree and the one you are reading is not necessarily in force.