A configuration using the Docker provider
docker is kreuzwerker/docker, so omitting source makes init fail confusingly
resource "docker_container" "app" {
name = "app"
} 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.
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.
Nothing else to flag.
No formatting problems, and nothing the rules object to. Worth remembering what that covers: this reads the file you pasted, not the account or cluster it will be applied to.
No finding matches that filter.
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.
docker is kreuzwerker/docker, so omitting source makes init fail confusingly
resource "docker_container" "app" {
name = "app"
}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"
}These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.
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.
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.
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.
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.
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.
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.
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.
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.
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 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.