Skip to content

About

Azure Infrastructure with Terraform - Multi-environment setup

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Terraform Azure Multi-Environment Setup

This Terraform configuration creates Azure resources across multiple environments (dev, test, prod) using a parent-child module structure.

Directory 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

Resources Created

Per Environment:

  • 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)

How to Use

1. Update Environment-Specific Values

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

2. Deploy to an Environment

# 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"

3. Verify Resources

After applying, outputs will display:

  • Resource Group ID and Name
  • Storage Account ID, Name, and Blob Endpoint

Module Architecture

Parent Module (main.tf)

  • Instantiates child modules (resource_group, storage_account)
  • Passes variables from root to child modules
  • Combines tags with environment-specific metadata

Child Modules

  • resource_group: Manages Azure Resource Group
  • storage_account: Manages Azure Storage Account with default container

Key Features

✅ 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

Variable Override Example

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"

Prerequisites

  • Azure CLI configured with appropriate credentials
  • Terraform >= 1.0
  • Valid Azure Subscription ID

About

Azure Infrastructure with Terraform - Multi-environment setup

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages