OpsCanary
Back to daily brief
terraformprovidersPractitioner

Mastering Terraform Provider Requirements: What You Need to Know

5 min read HashiCorp DocsApr 23, 2026
PractitionerHands-on experience recommended

Provider requirements are essential in Terraform because they dictate which providers your modules need to function properly. Without clearly defined requirements, you risk running into issues where Terraform cannot find or install the necessary providers, leading to deployment failures and wasted time troubleshooting.

To declare a provider in your module, you need to follow a specific structure. Start by defining the provider's source, local name, and version in the required_providers block inside your top-level terraform block. For example:

HCL
tf{required_providers{mycloud={source="mycorp/mycloud" version="~> 1.0"}}}

After that, add a top-level provider block to configure the provider with necessary parameters like authentication and region. Finally, run terraform init to install the provider and update the Dependency lock file with the latest version that matches your specified constraints.

In production, be mindful of version compatibility. The syntax for required_providers was introduced in Terraform v0.13, so if you're working with older versions, you might face limitations. It's also worth noting that if you omit the source argument, Terraform defaults to using an implied source address, which can lead to confusion. Always specify explicit source addresses to avoid unexpected behavior and ensure your modules are portable across different environments.

Key takeaways

  • Declare required providers in the `required_providers` block to manage dependencies.
  • Specify explicit source addresses for all providers to avoid confusion.
  • Use version constraints to ensure compatibility with your module's requirements.
  • Run `terraform init` to install providers and update the Dependency lock file.

Why it matters

In production, clearly defined provider requirements can prevent deployment failures and ensure that your infrastructure is built with the correct resources. This reduces downtime and enhances reliability.

Code examples

HCL
terraform{required_providers{mycloud={source="mycorp/mycloud"version="~> 1.0"}}}
HCL
terraform{required_providers{mycloud={source="mycorp/mycloud"version="~> 1.0"}}}provider"mycloud"{# ...}
HCL
terraform{required_providers{# In the rare situation of using two providers that# have the same type name -- "http" in this example --# use a compound local name to distinguish them.hashicorp-http={source="hashicorp/http"version="~> 2.0"}mycorp-http={source="mycorp/http"version="~> 1.0"}}}# References to these providers elsewhere in the# module will use these compound local names.provider"mycorp-http"{# ...}data"http""example"{provider=hashicorp-http#...}

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.