INTRODUCTION
This guide walks you through deploying a static website on Azure using Terraform. You’ll use Azure Storage for hosting the website and Azure CDN for global scalability and performance. By the end, you’ll have a fully automated infrastructure-as-code setup.
Prerequisites
Azure Account: Create a free account .
Terraform Installed: Download here.
Azure CLI: Installation guide.
Git (optional): To clone the sample code.
Step 1: Set Up Azure Authentication
Authenticate Terraform to manage Azure resources
az login #Log in to Azure via CLI
az account set --subscription="YOUR_SUBSCRIPTION_ID"
Step 2: Project Structure
Create a directory with the following structure:
terraform-azure-webapp/
├── main.tf # Terraform configuration
├── variables.tf # Input variables
├── outputs.tf # Output URLs
└── www/ # Sample website files
├── index.html
└── style.css
Step 3: Write Terraform Configuration
- variables.tf
- main.tf
- outputs.tf
Step 4: Create Sample Website Files
Add the following files to the www/ directory:
- www/index.html
- www/style.css
Step 5: Deploy Infrastructure
Run Terraform commands:
terraform init #Initialize providers/modules
terraform plan # Preview changes
terraform apply # Deploy resources (type "yes" to confirm)
After deployment, Terraform will output:
storage_website_url: Direct URL to the storage-hosted website.
cdn_endpoint_url: CDN-accelerated URL.
Step 7: Clean Up Resources
Avoid unnecessary costs by destroying resources:
terraform destroy
Summary
In this project, we:
- Used Terraform to automate Azure infrastructure deployment.
- Hosted a static website on Azure Storage with HTTPS support.
- Accelerated content delivery globally using Azure CDN.
- Practiced infrastructure-as-code principles for reproducibility.
This setup provides a foundation for scalable web apps, with Terraform ensuring consistency and reducing manual errors.
Top comments (0)