How to Avoid Hardcoding Providers in Terraform Using Terragrunt’s Generate Block
Terraform Providers:
plugins that interact with cloud providers, SaaS providers, and other APIs. Each provider adds a set of resource types and/or data sources that Terraform can manage. Without providers, Terraform can't manage any kind of infrastructure.
All Terraform configurations must declare which providers they require so that Terraform can install and use them
Provider Configuration
- Duplication: Violates the DRY principle
- Configuration Drift
- Tightly coupled modules
- Scalability Problems
- Risks of Version conflicts
- State inconsistencies
generate
block, eliminating the need to hardcode provider blocks in each of your Terraform modules. We’ll work with two repositories:This blog concludes the series on writing DRY Terraform with Terragrunt. By breaking infrastructure into reusable modules, injecting providers dynamically, and managing everything through Terragrunt, you get a scalable, clean, and production-ready workflow.
Feel free to explore the repos, try it out yourself, and drop any questions or feedback in the comments!