devopsing.dev
This site: Hugo on a private S3 bucket behind CloudFront with a custom domain, provisioned by Terraform and shipped by GitHub Actions.
- Status
- Live
- CI/CD
- GitHub Actions: plan on PR, apply + deploy on merge (OIDC)
- Cost
- < $0.10/month
- Stack
Architecture diagram coming soon
Cloudflare DNS → CloudFront (ACM certificate, TLS 1.2+, HTTP/3) → private S3 bucket via Origin Access Control. A CloudFront Function maps /path/ to /path/index.html; missing pages return a custom 404.
Key decisions
- Private bucket + OAC instead of S3 website hosting: HTTPS only, no public bucket. The bucket policy is pinned to this distribution with
AWS:SourceArn. - OIDC, no access keys. A read-only
planrole for pull requests and anapplyrole only for theproductionenvironment onmain. Neither role can touch IAM. - ACM in us-east-1 via a provider alias; DNS validation records are created in Cloudflare with
for_each. - Split Cloudflare tokens: DNS read for PRs, DNS edit only in
production.
CI/CD
- Pull request: Hugo build check and
terraform plan, posted as a PR comment that is updated in place. - Merge to
main: Hugo build →terraform applyof the saved plan →s3 sync→ CloudFront invalidation. mainis protected: a PR with passing checks is required. Plan and apply share one concurrency group per state.
Problems I hit
- OIDC
AccessDenied: CloudTrail showed GitHub’s new immutablesubformat (owner@id/repo@id); the trust policy was updated to match. - A manual
s3 sync --deletefrom the wrong folder wiped the site. The pipeline now builds before it gets AWS credentials and refuses to deploy withoutindex.html. - IAM details: bucket vs object ARNs, actions that only accept
"*"(ListCachePolicies), and policies adding up (s3:*silently allowed deleting state).
What’s next
- CloudFront flat-rate Free plan with WAF.
- Preview environments for pull requests.