This Terraform configuration creates Azure resources across multiple environments (dev, test, prod) using a parent-child module structure.
.terraform/
├── provider.tf # Azure provider configuration
├── main.tf # Parent module that calls child modules
├── variables.tf # Input variables
├── outputs.tf # Root outputs
├── modules/
│ ├── resource_group/ # Child module for Resource Group
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ └── storage_account/ # Child module for Storage Account
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf
└── environments/
├── dev/
│ └── terraform.tfvars # Dev environment values
├── test/
│ └── terraform.tfvars # Test environment values
└── prod/
└── terraform.tfvars # Prod environment values
- Azure Resource Group - Named as
{project_name}-{environment}-rg - Azure Storage Account - With HTTPS enforcement and default container
- Dev & Test: LRS (Locally Redundant Storage)
- Prod: GRS (Geo-Redundant Storage)
Edit each environment file and replace placeholder values:
environments/dev/terraform.tfvars:
subscription_id = "your-actual-subscription-id"
project_name = "myapp"
location = "East US"environments/test/terraform.tfvars and environments/prod/terraform.tfvars: Same pattern
# Initialize Terraform
terraform init
# Plan for dev environment
terraform plan -var-file="environments/dev/terraform.tfvars"
# Apply for dev environment
terraform apply -var-file="environments/dev/terraform.tfvars"
# For other environments
terraform plan -var-file="environments/test/terraform.tfvars"
terraform apply -var-file="environments/test/terraform.tfvars"
terraform plan -var-file="environments/prod/terraform.tfvars"
terraform apply -var-file="environments/prod/terraform.tfvars"After applying, outputs will display:
- Resource Group ID and Name
- Storage Account ID, Name, and Blob Endpoint
- Instantiates child modules (resource_group, storage_account)
- Passes variables from root to child modules
- Combines tags with environment-specific metadata
- resource_group: Manages Azure Resource Group
- storage_account: Manages Azure Storage Account with default container
✅ Multi-environment support (dev, test, prod)
✅ Parent-child module structure
✅ Environment-specific configurations
✅ HTTPS-only storage access
✅ Geo-redundant storage for production
✅ Automatic naming conventions
✅ Comprehensive tagging strategy
You can override variables at the command line:
terraform apply \
-var-file="environments/dev/terraform.tfvars" \
-var="location=West US" \
-var="storage_account_tier=Premium"- Azure CLI configured with appropriate credentials
- Terraform >= 1.0
- Valid Azure Subscription ID