Deploying an Azure Static Web App
This guide provides a complete walkthrough for setting up and deploying a static website to Azure Static Web Apps using Terraform for infrastructure provisioning and GitHub Actions for automated CI/CD.
Overview
Deploying a static site to Azure Static Web Apps involves two main phases:
- Infrastructure Setup: Create the Azure Static Web App resource using Terraform
- CI/CD Configuration: Set up automated deployment using GitHub Actions
Prerequisites
- An Azure subscription
- Terraform installed and configured
- A GitHub repository with your static site code
- Azure CLI installed (for authentication)
You can set up a fully configured environment using a templated dev container. See Setting Up Dev Containers for details.
Required Permissions and Secrets
GitHub Actions workflow requires specific permissions and secrets. If you're already using the DX bootstrap module, these are pre-configured aside custom roles for the static web app.
- Azure Identity Role: Assign
PagoPA Static Web Apps List Secretsrole - Workflow Permissions: Ensure
id-token: write,contents: read,pull-requests: write - Secrets: Use
secrets: inheritor configure Azure authentication secrets
Step 1: Infrastructure Setup with Terraform
Create the Azure Static Web App resource using Terraform.
Use the official azurerm_static_web_app resource:
resource "azurerm_static_web_app" "example" {
name = provider::azuredx::resource_name(merge(
var.naming_config,
{
name = "website",
resource_type = "static_web_app",
})
)
resource_group_name = var.resource_group_name
location = "westeurope"
sku_size = "Standard"
tags = var.tags
}
Step 2: Configure CI/CD with GitHub Actions
Use the reusable workflow to automate build and deployment.
The workflow automates the entire deployment process:
- Detects your package manager (pnpm, yarn, or npm)
- Builds the application using
turbo build - Deploys using the official Azure Static Web Apps action
- Creates preview environments for pull requests