CareFlow Build JournalEntry 005
Infrastructure foundations · July 7, 2026

The infrastructure before the infrastructure.

Terraform needed an S3 bucket for remote state. The bucket needed Terraform to create it. I resolved the circle with one deliberately narrow exception—and an explicit handoff.

01 · The circle

The first dependency could not create itself.

Terraform uses state to connect configuration with the infrastructure it manages. For a team, that state needs a remote, restricted, and recoverable home. In CareFlow's AWS foundation, the intended home was S3—but the bucket did not exist until Terraform created it.

This was more than a clever interview question. State may contain sensitive values and infrastructure details. A lost, exposed, or concurrently modified state file can turn an ordinary change into a dangerous one.

02 · The exception

Local state was acceptable once because “once” had an exit.

I isolated a bootstrap configuration whose only job was to create the remote-state foundation. It used local state for that first apply, then ordinary environment configurations initialized against the new S3 backend.

The exception did not become the operating model. It created the operating model.

03 · The boundary

State separation followed account separation.

Development, production, and security responsibilities already lived in separate AWS accounts. I carried that model into state with a dedicated state bucket per account rather than a shared universal store.

The purpose was not aesthetic symmetry. It kept access aligned to the environment: a development workflow did not need permission to read or change production state.

04 · The controls

Four controls answered four different failure modes.

ENCRYPTION

Protect the state stored in the bucket with a deliberately managed key.

VERSIONING

Support recovery from accidental deletion or human error.

TLS-ONLY POLICY

Reject requests that do not use secure transport.

NATIVE LOCK FILE

Coordinate writers so concurrent operations do not collide.

Current Terraform documentation supports S3 lock files with use_lockfile and describes DynamoDB-based locking as deprecated. That replaced an older pattern and removed another bootstrap resource. Locking remained essential; only its implementation changed.

05 · The caveat

A guardrail is useful only when its edge is understood.

I added Terraform's prevent_destroy lifecycle rule to reject an ordinary plan that would destroy the protected bucket. But HashiCorp documents an important limit: if the resource configuration is removed, the rule is removed with it.

So the lifecycle rule was one guardrail—not a substitute for versioning, restricted access, review, backups, or a recovery owner.

06 · Decision ledger

The bootstrap had to remain small enough to explain.

DecisionReasonBoundary
Local state for bootstrapBreak the circular dependencyIsolated, one-time path
S3 backend per accountAlign access with environment ownershipNo shared universal state store
S3 native lock fileCoordinate writers without another databaseStill requires exact IAM permissions
prevent_destroyReject routine destructive plansNot protection after configuration removal
Core lesson

Make exceptions expire.

A safe bootstrap is defined as much by its handoff as by its first apply.

Security lesson

State is control-plane data.

Its access, recovery, encryption, and coordination deserve explicit design.

Architecture lesson

Let state follow the boundary.

Environment separation weakens when every environment shares one broad state credential.

Evidence lesson

Know where a guardrail stops.

A documented limitation is more useful than an overstated control.

Field check

Before the first environment uses remote state.

  1. Is the local bootstrap path isolated and assigned an owner?
  2. Are encryption, versioning, transport policy, and access verified?
  3. Can concurrent writers acquire the intended lock?
  4. Does state access follow account and environment boundaries?
  5. Has the local-to-remote handoff been proven without exposing identifiers?
Primary sources

Documentation behind the implementation.

This entry is educational, not security, compliance, or operational advice. It describes a dated CareFlow implementation; verify current platform behavior for your environment.

Visual edition

The infrastructure before the infrastructure.

A narrated walkthrough of the remote-state bootstrap, the controls around Terraform state, and the deliberate exit from the one-time local exception.

Terraform state bootstrap, control boundaries, and recovery-minded design.