Interview Prep/Terraform/Modules and Code Structure

Why should the AWS provider be configured in the root module and not in a reusable child module?

BeginnerScenarioModules and Code Structure
Answer

Situation read → A junior added provider "aws" with a hardcoded region inside a module.

What I'd do → Remove it; let the module inherit the root's default provider, and declare only required_providers.

# module
terraform {
  required_providers {
    aws = { source = "hashicorp/aws", version = ">= 5.0" }
  }
}

Why → Region and credentials are deployment decisions, not module decisions. Modules with embedded providers can't be removed cleanly and break reuse across regions.

Interview tip → In modules, set minimum provider versions with >=; the root pins the exact range.

All Terraform questions Roadmap: Terraform

More on Modules and Code Structure