Skip to content

Lesson 5 of 9 · 26m

Provisioning Workflows, GitOps, and Safe Automation

Build auditable provisioning flows using declarative desired state, controlled plan/apply boundaries, idempotent automation, and rollback-aware operations.

Every mature platform eventually confronts the same uncomfortable truth: the automation is production infrastructure. A broken provisioning workflow can strand teams, orphan resources, leak credentials, or destroy data with commendable efficiency. The design goal is not merely "run Terraform automatically." It is to make desired state explicit, execution auditable, failure inspectable, and recovery boring.

Declarative desired state beats ticket-triggered scripts

A GitOps-style flow stores intent in version control and lets a controller reconcile it:

developer request -> reviewed intent -> merged desired state -> controller reconcile
                                                              -> status and events

The exact technology can be Argo CD, Flux, Crossplane, Terraform Cloud, GitHub Actions, or an internal controller. The important shape is stable: desired state is durable, actor identity is clear, changes are reversible in version control, and runtime state is observed continuously.

Keep plan and apply intellectually separate

Infrastructure automation often fails because teams treat plan output as a curiosity rather than the production decision artifact:

terraform init -input=false
terraform plan -input=false -out=tfplan -detailed-exitcode
terraform show -no-color tfplan > plan.txt
terraform apply -input=false tfplan

The saved plan is what you approved. Applying a freshly evaluated plan after variables, branches, or cloud state changed is not the same thing. In high-risk workflows, preserve the plan artifact and tie it to the requesting identity.

A controller should expose honest status

Users need to know whether the system is working, blocked, degraded, or lying:

status:
  phase: Ready
  observedGeneration: 14
  endpoint: billing-db.cluster-ro.internal
  conditions:
    - type: Provisioned
      status: "True"
      reason: ApplySucceeded
    - type: BackupConfigured
      status: "True"
      reason: BackupPolicyAttached

A phase of Provisioning that lasts nine hours without events is not status; it is a shrug. Emit condition transitions, external resource IDs, error summaries, and ownership metadata.

Idempotency and state locking are non-negotiable

Retries are normal in distributed systems. If running the same operation twice creates two databases, your automation is not idempotent. Use unique deterministic names, external-state locking, creation tokens, or controller reconciliation. Terraform state locking is table stakes:

terraform {
  backend "s3" {
    bucket         = "platform-tf-state"
    key            = "databases/billing-db.tfstate"
    region         = "us-east-1"
    dynamodb_table = "platform-tf-locks"
    encrypt        = true
  }
}

The exact backend matters less than the guarantees: no concurrent writers, encrypted state, restricted access, recoverable backups, and no secrets casually printed into logs.

Destructive operations need product design

Deletion is not simply the reverse of creation. Data resources need retention windows, finalizers, export hooks, and approval rules:

delete requested -> protect dependents -> snapshot/export if configured
                -> enter retention period -> delete infrastructure -> record audit

A finalizer in Kubernetes terms is a useful pattern even outside Kubernetes: do not consider the object gone until its external consequences are resolved.

Roll forward is often safer than rollback

Application rollbacks can be simple; infrastructure rollback can be impossible after data mutation. Design for forward recovery: re-run reconciliation, repair drift, restore from backup, or create a replacement resource. The question "can we roll back?" is usually incomplete. Ask "what state must be preserved, and what is the recovery point and recovery time objective?"

Field notes

  • Never pipe cloud credentials into long-lived automation workers broader than the job requires; use short-lived workload identity where possible.
  • Logs love secrets. Treat provisioning output as sensitive and redact aggressively.
  • Reconciliation loops need backoff. Infinite fast retries convert a cloud API incident into a self-inflicted denial of service.
  • Manual emergency changes will happen. Detect drift and provide a documented path to adopt it rather than pretending it cannot occur.

Was this lesson helpful?

Sign in to rate