Skip to content

About

Terraform Your Cloud Resume Challenge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Antonio's Cloud Resume (Terraform Edition)

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.

👉 View my resume here

Architecture Diagram

Table of Contents

- Prerequisites
- File Structure
- Local Workspace Setup
- Backend Part
- Frontend Part
- Cloud Setup
- CI/CD Setup
- Notes

Prerequisites

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

⚠️ Keep in mind that the focus of this README is only the implementation of Terraform. For a complete overview of the project please refer to my azure-cloud-resume-project repository. Reviewing that project first will help ensure you don’t miss any important context.

File Structure

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

Local Workspace Setup

Link to the official Azure Terraform documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs

  1. Install Terraform
    • Run terraform -info to verify installation
  2. Install HashiCorp Terraform extension in VS Code
    • HashiCorp.terraform
  3. Install Azure CLI
    • Run az --version to verify installation
  4. Authenticate to Azure using Azure CLI
    • Run az login --tenant TENANT_ID
  5. Create Terraform Configuration

Backend Part

  1. Create a Resource Group
    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
  2. 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
  3. Create a Blob Storage
    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_blob
  4. Create an App Service Plan
    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan
  5. Create a Flex Consumption Function App
    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app_flex_consumption
  6. 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

Frontend Part

  1. Create a Storage Account for the Static Website
    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account_static_website
  2. 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
  3. Automate a Domain with Cloudflare and Terraform
  4. 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 run az feature register --namespace Microsoft.Cdn --name BypassCnameCheckForCustomDomainDeletion to 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)

Cloud Setup

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:

  1. Create a Service Principal App Registration on the Azure Portal
  2. Create a Client Secret for the App Registration
  3. 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
  4. Sign up / Sign in to HCP Terraform
  5. Create an Organization
  6. Create a Workspace
  7. 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)
  8. Create Workspace Terraform Variables to store vars in Cloud

CI/CD Setup

Next, we will use GitHub Actions to automatically deploy code changes to Azure.

  1. 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
  2. Authenticate Terraform with Github
    • Generate a User API Token in Terraform
    • Add the token as a GitHub Repository Secret named TF_API_TOKEN
  3. Set Workspace to Automatically Apply Changes
    • Terraform Org => Workspace => Settings => General => Enable Auto-apply
  4. Create Deployment Workflow
  5. Create Destruction Workflow
    • I set up this workflow to be triggered manually only.

Notes

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.


About

Terraform Your Cloud Resume Challenge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages