The idea of writing isn’t new. It has been in my head for years, with always an excuse not to. One of the bigger ones was that the site never quite felt right. Bollocks, of course. It is the fear of starting, to be honest. My work gives me enough topics to share: problems, opinions, examples, and plenty of things worth writing down.
A couple of years ago I started looking for something easy to maintain. Until then I had hosted my photography on WordPress, but it required more infrastructure than I wanted to deal with. Through my own work in Azure I came across Static Web Apps, and that was exactly the level of infrastructure I was looking for. So recently I picked it up again to start building it out.
This post covers what I ended up with, why, and a few things worth knowing if you’re considering something similar.
The stack#
- Hugo: static site generator
- Blowfish: Hugo theme
- Azure Static Web Apps: hosting
- Azure Blob Storage: media (gallery photos)
- Terraform with AVM: infrastructure as code
- GitHub Actions: CI/CD
Hugo#
So the search for the right technology began. Static site generators was the first term on Google and quickly Hugo and Jekyll were the first to pop up. A quick comparison and test showed my personal preference for Hugo, just a gut feeling, no real other reason.
One of the big advantages of static site generators is the immediate feedback loop. You run a local server, make a change, and the page refreshes instantly. I love working that way.
Technology decided, now a theme. Here another struggle began. So many options, just like I had with WordPress. Luckily most have demo pages so you can see what they look like before committing. I looked at whether the structural interface was appealing, but also whether the documentation was there to help me along.
Then I came across Blowfish. The look and feel were right, the documentation was solid, and it allows for quite some customisation if you want to go further.
Theme decided, time to build the infrastructure.
Azure Static Web Apps#
So for those who are not familiar with Azure Static Web Apps, a little background. It is a hosting service built specifically for, as the name suggests, static sites. So you are able to host sites like Hugo, Jekyll and Gatsby. But you are also able to host sites created with JavaScript frameworks like Angular, React and Vue or Next.js and many more. Last but certainly not least you can integrate a Static Web App with a Function App as an API backend. This gives you quite some options and integrations.
A few useful things to know:
- Free SSL on both the default hostname and custom domains
- GitHub Actions integration out of the box. The deploy workflow is generated automatically when you link a repository.
- Staging environments for pull requests, automatically provisioned and torn down
- Custom domain support including apex domain, without needing Azure Front Door or a Traffic Manager
- Authentication via Entra ID and GitHub included out of the box, both available on the free tier
The free tier is sufficient for a personal blog. No compute costs, no storage costs for the static assets.
The limitation worth knowing: Static Web Apps doesn’t support server-side rendering. If you need dynamic content (API backends, database queries), you’d need to integrate with Azure Functions or reach for a different hosting model. For a static site hosting a blog that’s not a constraint at all.
Terraform and AVM#
As I work with Terraform quite a bit, managing the infrastructure with it was an easy choice. It gives full control over the deployed resources and their configuration, and adding new pieces later is straightforward.
Writing Terraform for Azure has become much easier since Microsoft is also chipping in with AVM, Azure Verified Modules. It is Microsoft’s standard for Terraform (and Bicep) modules for Azure. The modules follow a strict specification and are created and maintained by Microsoft or verified community contributors. You and I can also contribute features and bug fixes, which is part of what keeps the quality up.
In practice it gives you modules that are structured consistently and easy to adopt. Instead of writing modules yourself every time, you pick up something that already meets the standard.
AVM deserves its own post and it will get one. For now, here is what it looks like in practice.
The infrastructure for this blog is straightforward. A resource group, a Static Web App, and a storage account for media. Using the AVM module the Static Web App looks like this:
module "static_web_app" {
source = "Azure/avm-res-web-staticsite/azurerm"
version = "~> 0.6"
location = azurerm_resource_group.blog.location
name = var.static_web_app_name
resource_group_name = azurerm_resource_group.blog.name
sku_size = "Free"
sku_tier = "Free"
tags = var.tags
enable_telemetry = false
custom_domains = var.custom_domains
}The Static Web App resource exposes a deployment API key as an output. That key is what GitHub Actions uses to authenticate deploys. Terraform is not limited to Azure resources. Adding the GitHub provider lets it write the secret directly to GitHub Actions, nothing to copy manually from the portal.
provider "github" {
owner = var.github_owner
}
resource "github_actions_secret" "swa_api_token" {
repository = var.github_repository
secret_name = "AZURE_STATIC_WEB_APPS_API_TOKEN"
plaintext_value = module.static_web_app.resource.api_key
}The GitHub provider authenticates via the GITHUB_TOKEN environment variable, which you can populate from the gh CLI
before running Terraform:
$env:GITHUB_TOKEN = (gh auth token -u example_username)
terraform applyThe -u flag targets a specific account. Only needed if you have multiple accounts logged in with the gh CLI. After
apply, the secret is in GitHub and the workflow picks it up from there.
Custom Domains#
The Static Web App custom domains are also managed through Terraform. The www subdomain is straightforward. The apex
domain is not.
You cannot use a CNAME record at the zone apex. It is a DNS standard restriction. SWA validates custom domains using
CNAME by default, so pointing takebakker.nl at the SWA hostname that way fails with a 400. The fix is TXT record
validation instead:
custom_domains = {
www = {
domain_name = "www.takebakker.nl"
}
apex = {
domain_name = "takebakker.nl"
validation_type = "dns-txt-token"
}
}Run terraform plan and it will output the validation token for the apex domain. Create a TXT record at your DNS
provider with that value, then run terraform apply. For the actual routing, use an ALIAS or ANAME record at the
apex pointing to the SWA hostname. Not a CNAME.
GitHub Actions#
GitHub Actions are a method to configure actions based on the repository structure and anything you could reach during a action. It gives amazing options to automate stuff. And we did in this case to deploy the Hugo content to the Static Web App.
The deployment workflow is simple. Every push to main, hugo builds the site and that build is deployed to the Static
Web App via the official Azure/static-web-apps-deploy action.
- name: Build and Deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: upload
app_location: public
output_location: ""
skip_app_build: trueThe one non-obvious thing: Hugo can use Git submodules for themes. If your Actions workflow doesn’t check out submodules, the build will fail silently. Hugo will build, but the theme won’t be there and you’ll get an empty site. The fix is adding two lines in the checkout step:
- uses: actions/checkout@v4
with:
submodules: truePull requests automatically get a staging environment. The action detects the PR context and provisions one. GitHub
posts a comment on the PR with the preview URL once the deploy completes. There is a catch though: for that comment to
be posted, the job needs pull-requests: write permission. Without it, the deploy succeeds but the URL never appears.
permissions:
pull-requests: write
contents: readWhen the PR is closed the staging environment is torn down automatically. A separate job handles this close_staging
which runs the action with action: close.
close_staging:
name: Close Staging Environment
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Close staging environment
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: closeTo recap the whole pipeline I used:
name: Deploy Blog
on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- main
workflow_dispatch:
inputs:
close_environment:
description: 'Name of preview environment to close (leave empty to deploy normally)'
required: false
default: ''
jobs:
close_environment:
name: Close Preview Environment
if: github.event_name == 'workflow_dispatch' && inputs.close_environment != ''
runs-on: ubuntu-latest
steps:
- name: Close named environment
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: close
deployment_environment: ${{ inputs.close_environment }}
build_and_deploy:
name: Build and Deploy
if: >
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.action != 'closed') ||
(github.event_name == 'workflow_dispatch' && inputs.close_environment == '')
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: latest
extended: true
- name: Build site
run: hugo --minify
env:
TZ: Europe/Amsterdam
- name: Build and Deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: upload
app_location: public
output_location: ""
skip_app_build: true
close_staging:
name: Close Staging Environment
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Close staging environment
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: closeWhat I’d do the same#
The Hugo + Static Web Apps combination works well for this use case. Build time is fast, the deploy pipeline is simple, and there’s nothing running in production that can break at 2am.
Terraform for the infrastructure was the right call even for something this small. It helps so be able to quickly build and adjust the configuration. Additionally the state has all details which come in handy such as the DNS configuration for custom domains and the static web app token. The later required for the GitHub action.
What I’d approach differently#
Blowfish is a good theme but Tailwind CSS complicates customisation. The compiled CSS only includes the utility classes actually used in the theme source. If you want to use a Tailwind class that isn’t in the compiled output, you either write plain CSS overrides or you rebuild the Tailwind CSS from source. Both are manageable, but it’s worth knowing before you start.
The media workflow, uploading photos to Blob Storage manually via Azure CLI or Storage Explorer, is functional but not particularly smooth. I’ll probably automate it at some point.
