DEV Community

Cover image for Deploy a Scalable Web App on Azure using Terraform
Seyi Lufadeju
Seyi Lufadeju

Posted on

Deploy a Scalable Web App on Azure using Terraform

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"
Enter fullscreen mode Exit fullscreen mode

Image description


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
Enter fullscreen mode Exit fullscreen mode

Image description


Step 3: Write Terraform Configuration

  • variables.tf

Image description

  • main.tf

Image description

  • outputs.tf

Image description


Step 4: Create Sample Website Files
Add the following files to the www/ directory:

  • www/index.html

Image description

  • www/style.css

Image description


Step 5: Deploy Infrastructure
Run Terraform commands:

terraform init #Initialize providers/modules

Image description


terraform plan # Preview changes

Image description


terraform apply # Deploy resources (type "yes" to confirm)

Image description

Image description


After deployment, Terraform will output:

  • storage_website_url: Direct URL to the storage-hosted website.

  • cdn_endpoint_url: CDN-accelerated URL.

Image description

Image description


Step 7: Clean Up Resources
Avoid unnecessary costs by destroying resources:

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Image description

Summary
In this project, we:

  1. Used Terraform to automate Azure infrastructure deployment.
  2. Hosted a static website on Azure Storage with HTTPS support.
  3. Accelerated content delivery globally using Azure CDN.
  4. 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)