Building on my Azure Cloud Resume Project, this time I am implementing Infrastructure as Code using Terraform.
Here, I’ve re-architected the entire Azure-based resume project to be fully automated and reproducible using Terraform.
This project is inspired by the Terraform Your Cloud Resume Challenge.
- Prerequisites
- File Structure
- Local Workspace Setup
- Backend Part
- Frontend Part
- Cloud Setup
- CI/CD Setup
- Notes
To get started with this project, you should have the following:
Accounts & Services:
- Azure Subscription (Required to deploy backend and storage resources.)
- Terraform Cloud Account (Used for remote Terraform execution, state management and storing Terraform variables.)
- Custom Domain (Purchase one from a registrar like Namecheap or similar.)
- Cloudflare Account (Required to manage DNS and apply CDN rules.)
Local Development Tools:
- Azure CLI
- Terraform CLI
📁 terraform-azure-cloud-resume-project/
├── 📁 frontend/
├── 📁 backend/
├── 📁 terraform/
│ ├── variables.tf (Defines input variables for the Terraform project)
│ ├── terraform.tfvars (Sets values for the input variables during local development)
│ ├── terraform.tfstate (Tracks the current state of infrastructure during local development)
│ └── ... .tf (All other terraform files)
├── 📁 .github/workflows/
│ ├── deploy.yml
│ └── destroy.yml
└── build.sh (Script used for local development to build and deploy resources)
Link to the official Azure Terraform documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
- Install Terraform
- Run
terraform -infoto verify installation
- Run
- Install HashiCorp Terraform extension in VS Code
- HashiCorp.terraform
- Install Azure CLI
- Run
az --versionto verify installation
- Run
- Authenticate to Azure using Azure CLI
- Run
az login --tenant TENANT_ID
- Run
- Create Terraform Configuration
- Follow the Challenge Guide to get more help.
- Create a Resource Group
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group - Create a Free Tier Azure Cosmos DB Account
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_account
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/manage-with-terraform#free-tier - Create a Blob Storage
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_blob - Create an App Service Plan
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan - Create a Flex Consumption Function App
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app_flex_consumption - Deploy code to Function App
https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies
https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies?tabs=linux#one-deploy
⚠️ One deploy is the only deployment technology supported for apps on a Flex Consumption plan. The end result is a ready-to-run .zip package that your function app runs on.
💡 Use Azure CLI to deploy code initially and GitHub Actions for CI/CD
https://learn.microsoft.com/en-us/cli/azure/functionapp/deployment/source?view=azure-cli-latest#az-functionapp-deployment-source-config-zip
- Create a Storage Account for the Static Website
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account_static_website - Upload frontend code from a local directory to a blob container
https://learn.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az-storage-blob-upload-batch - Automate a Domain with Cloudflare and Terraform
- Buy a domain
- Migrate DNS to Cloudflare
https://developers.cloudflare.com/registrar/get-started/transfer-domain-to-cloudflare/ - Create a Custom Cloudflare API Token
Permissions: ZoneSettings:Read,Page Rules:Edit,DNS:Edit - Create Cloudflare resources
https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs
- Create a CDN Profile and Add Custom Domain to Endpoint
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cdn_endpoint_custom_domain
⚠️ Azure may not immediately allow you to link your custom domain to the CDN endpoint due to DNS propagation delays. Wait a few minutes and try again if you get an error.
⚠️ When destroying resources, Azure won’t let you delete a CDN custom domain endpoint if its related DNS records still exist. To avoid a failure, make sure DNS records (like the CNAME for your domain) are destroyed before the custom domain resource.
💡 You can runaz feature register --namespace Microsoft.Cdn --name BypassCnameCheckForCustomDomainDeletionto allow Azure to delete a custom domain without requiring you to remove the associated CNAME record first. (This is a Subscription level Preview feature that can be enabled or disabled from the Azure Portal also)
Link to the official documentation which explains all steps: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret
To Store State and Variables on Terraform Cloud:
- Create a Service Principal App Registration on the Azure Portal
- Create a Client Secret for the App Registration
- Add Role Assignments
💡Add the IAM Roles on Subscription level so you don't have to manually reassign the roles every time you use terraform destroy.- Contributor
- Storage Blob Data Contributor
- Sign up / Sign in to HCP Terraform
- Create an Organization
- Create a Workspace
- Create Workspace Env Variables to authenticate Terraform with Azure
- ARM_CLIENT_ID (Sensitive)
- ARM_CLIENT_SECRET (Sensitive)
- ARM_SUBSCRIPTION_ID (Sensitive)
- ARM_TENANT_ID (Sensitive)
- Create Workspace Terraform Variables to store vars in Cloud
Next, we will use GitHub Actions to automatically deploy code changes to Azure.
- Set Up Azure Authentication and Permissions
- Settings => Secrets and variables => Actions => Repository secrets
- AZURE_CLIENT_ID | AZURE_SUBSCRIPTION_ID | AZURE_TENANT_ID
- Configure a Federated Identity in the App Registration
- Assign the Contributor Role and Storage Blob Data Contributor Role to the App at the Subscription level
- Authenticate Terraform with Github
- Generate a User API Token in Terraform
- Add the token as a GitHub Repository Secret named
TF_API_TOKEN
- Set Workspace to Automatically Apply Changes
- Terraform Org => Workspace => Settings => General => Enable Auto-apply
- Create Deployment Workflow
- Create Destruction Workflow
- I set up this workflow to be triggered manually only.
I chose Cloudflare as my DNS provider because it integrates smoothly with Terraform, allowing me to fully automate DNS record creation and management. This eliminates manual configuration and makes the setup repeatable and scalable.
To simplify local development and testing and reduce repetitive effort, I created a build.sh script. This shell script automates infrastructure provisioning with Terraform, as well as the build and deployment of both the backend and frontend code. for the Cloud Resume Challenge.
After deploying changes to the Function name, the Function URL may also change. If that happens, you’ll need to manually update the productionApiUrl field in main.js with the new URL.
