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.

More terraform tools

Terraform Validator & Formatter Does it parse, and is it formatted? Terraform dynamic Block Generator It is ingress.value, not each.value Terraform check and precondition Generator A failed check does not stop the apply Terraform variables.tf Generator From the var. references you already wrote Terraform Unused Declaration Linter Dead variables, locals and data sources Terraform Atlantis YAML Generator when_modified misses your modules Terraform Function Tester and HCL Console terraform console, in a tab Terraform for Expression Tester Where do the keys collide? Terraform Interpolation Tester null becomes an empty string Terraform templatefile Tester Render it before you apply it Terraform Resource Count Calculator How many objects, not how many blocks Terraform count to for_each Converter With the moved blocks it needs Terraform moved Block Generator Rename without destroying Terraform state mv Command Builder No plan, no undo Terraform target Flag Builder And why to stop using it Terraform outputs.tf Generator Outputs are not sensitive by default Terraform Remote State Data Source Generator It grants read of the whole state Terraform .gitignore Generator and Checker .terraform* eats the lock file Terraform to OpenTofu Migration Checker The state is the part to watch Terraform tfvars to JSON Converter The JSON file wins Terraform Version Constraint Parser What ~> actually allows Terraform Resource Address Parser Quote it before the shell eats it Terraform cidrsubnet Calculator newbits is added, not the target Terraform Import Block Generator The id is not the name Terraform Lock File Viewer Why CI fails and your laptop does not Terraform Variables Checker A missing value hangs CI Terraform tfvars to Env Vars Converter Lists and maps have to be JSON Terraform Deprecated Syntax Checker What a current Terraform rejects Terraform State File Viewer Read it without uploading it Terraform Plan JSON Viewer It is not redacted Terraform HCL to JSON Converter And what the conversion loses Terraform Module Source Validator version only works for the registry Terraform Backend Config Decoder Is state actually locked? Terraform Naming Convention Validator A hyphen makes a resource unreferenceable

Elsewhere on the site