Demonstration study. The blog infrastructure is planned in Terraform. The procedures in this article are criteria for a future exercise, not evidence of resources already provisioned.

Infrastructure as code and operational responsibility

A temporary lab should be as easy to recreate as it is to remove. Infrastructure as Code (IaC) makes the desired configuration reviewable and reduces reliance on manual procedures. It does not remove the need to understand AWS service APIs, permissions and lifecycles.

In the blog, infrastructure and content have distinct responsibilities: Terraform defines the CloudFront distribution, private S3 origin and delivery components; Hugo and Pagefind produce the published artifact. A routine editorial change should not require infrastructure reprovisioning.

Plan, state and desired configuration

ElementPurposePrecautions
.tf filesDescribe the desired configurationReview changes and retain Git history
Terraform stateAssociate managed resources with real objectsProtect access, integrity and recovery
.terraform.lock.hclRecord provider selections and checksumsTrack in Git and review updates
Saved planRecord proposed actions for an executionTreat as a potentially sensitive file

State is more than an inventory. Losing or improperly modifying it can compromise management of existing resources. Values marked as sensitive can still appear in state and plans. The selected backend should protect those data and support state locking when operations can run concurrently. Git should not be used as state storage.1

A verifiable change workflow

The following illustrative sequence assumes an existing IaC directory, valid temporary credentials and an authorized AWS account. It is not part of the website build.

terraform init
terraform fmt -check -recursive
terraform validate
terraform plan -out=lab.tfplan
terraform show lab.tfplan

validate checks the configuration, whereas the plan reads state and proposes changes. Neither replaces functional tests in AWS. Review the plan before applying it: expected resources, permissions, destructive changes, dependencies and financial impact.

Only in an authorized environment would the next step be terraform apply lab.tfplan. An old plan can become inappropriate after external changes, so approval must correspond to the plan actually applied.

Teardown without losing what must remain

The disposable nature of the lab applies to temporary resources, not to the loss of approved editorial content. Before dismantling the infrastructure, identify data that must survive, verify recovery mechanisms and review the destruction plan separately (terraform plan -destroy). S3 versioning, retention requirements and protection policies may require specific procedures.

Teardown alone does not guarantee that all costs have stopped: resources outside the state, retained storage and recorded usage can remain. The final check should include inventory and billing.

Acceptance criteria

  • The code and selected versions allow the environment to be reconstructed from a clean checkout.
  • The plan is reviewed before any resource changes; secrets and state stay out of the repository.
  • A subsequent plan, after application and stabilization, shows no unexpected changes.
  • The teardown procedure preserves authorized data and identifies residual costs.

Record these results in an infrastructure exercise. A successful local build does not prove that the lab can be recreated.

Related reading: Static blog architecture on AWS and CI/CD for static content.

References