<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Automation | John Nessime</title>
	<atom:link href="https://john-nessime.com/blog/tag/automation/feed/" rel="self" type="application/rss+xml" />
	<link>https://john-nessime.com/blog/tag/automation/</link>
	<description>Cloud, DevOps, Data &#38; AI — Built, Tested, Explained</description>
	<lastBuildDate>Fri, 31 Jul 2026 23:12:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://john-nessime.com/blog/wp-content/uploads/2026/07/cropped-jn-32x32.png</url>
	<title>Automation | John Nessime</title>
	<link>https://john-nessime.com/blog/tag/automation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Green Check, Broken Build: How to Build a Fail Fast Pipeline That Explains Why</title>
		<link>https://john-nessime.com/blog/devops/fail-fast-pipeline/</link>
					<comments>https://john-nessime.com/blog/devops/fail-fast-pipeline/#respond</comments>
		
		<dc:creator><![CDATA[John Nessime]]></dc:creator>
		<pubDate>Fri, 31 Jul 2026 23:12:22 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Technical Guides]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[CI/CD]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Exit Codes]]></category>
		<category><![CDATA[GitHub Actions]]></category>
		<category><![CDATA[GitLab CI]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Pipefail]]></category>
		<category><![CDATA[Pipeline Design]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[SRE]]></category>
		<category><![CDATA[Terraform]]></category>
		<guid isPermaLink="false">https://john-nessime.com/blog/?p=55</guid>

					<description><![CDATA[<p>A green pipeline that ships a broken build is worse than a red one. Here is how to order stages so failures surface in seconds, stop shell pipes from swallowing exit codes, and write failure output that tells the next engineer exactly what to fix.</p>
<p>The post <a href="https://john-nessime.com/blog/devops/fail-fast-pipeline/">Green Check, Broken Build: How to Build a Fail Fast Pipeline That Explains Why</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The deploy went out at the end of the day. Pipeline green, every stage a tick, nobody thought about it again. Twenty minutes later support asks why checkout is returning 502.</p>



<p class="wp-block-paragraph">You go back through the logs and there it is, four hundred lines up, in a step that reported success: a download that returned an HTML error page, got piped into <code>tar</code>, and produced an archive containing nothing useful. The shell reported the exit status of <code>tar</code>, not of <code>curl</code>. The build carried on. The pipeline was never lying on purpose. It just never asked the right question.</p>



<p class="wp-block-paragraph">Two things go wrong with pipelines, and only one of them gets talked about. The famous one is slow feedback: thirty-four minutes of build and integration tests before a linter tells you a file is missing a trailing newline. The expensive one is a pipeline that passes when it should have stopped. A <strong>fail fast pipeline</strong> fixes the first problem. Making it explain itself fixes the second, and that is the half most teams skip.</p>



<p class="wp-block-paragraph">This post covers both: how to order stages so real failures surface in seconds, how to stop the shell from hiding non-zero exits, how to design failure output that hands the next engineer the fix, and the troubleshooting steps for when a pipeline stubbornly refuses to fail at the right moment.</p>



<h2 class="wp-block-heading">The failure that actually bites: a pipeline that lies</h2>



<p class="wp-block-paragraph">Start here, because everything else is optimisation on top. A slow pipeline wastes your afternoon. A silently passing pipeline ships a broken artifact and burns a day of debugging in production, usually while somebody is on a call with a customer.</p>



<p class="wp-block-paragraph">The shell is where most of this happens. Bash gives you three defaults that are wrong for CI, and one line fixes all three.</p>



<pre class="wp-block-code"><code>#!/usr/bin/env bash
set -euo pipefail

# Without pipefail this line exits 0 even when curl fails,
# because the shell reports the status of the LAST command
# in the pipe, which is tar.
curl -sSL https://example.com/artifact.tar.gz | tar -xz</code></pre>



<h3 class="wp-block-heading">What each flag actually protects</h3>



<ul class="wp-block-list">
<li><strong><code>-e</code></strong> stops the script when a command exits non-zero. Without it, a failed database migration is followed by a successful <code>echo</code>, and the script exits 0 because the last command succeeded.</li>
<li><strong><code>-u</code></strong> turns an unset variable into an error. This is the one that saves you from <code>rm -rf "$PREFIX/build"</code> expanding to <code>rm -rf "/build"</code> when someone renames an environment variable in the pipeline settings and forgets the script.</li>
<li><strong><code>-o pipefail</code></strong> makes a pipeline return the first non-zero status instead of the last one. Every <code>curl | tar</code>, <code>cat | jq</code>, and <code>docker logs | grep</code> in your scripts is currently reporting only the exit code of the thing on the right.</li>
</ul>



<p class="wp-block-paragraph">The exit status is only half the story though. Plenty of tools return 0 while doing something useless, and <code>curl</code> is the classic offender.</p>



<pre class="wp-block-code"><code># curl exits 0 here even when the server returns 500,
# and you end up untarring an HTML error page.
curl -sSL "$ARTIFACT_URL" | tar -xz

# --fail          makes curl exit non-zero on 4xx and 5xx
# --show-error    keeps the reason visible even with --silent
# --location      follows redirects instead of saving a 302 body
curl --fail --silent --show-error --location "$ARTIFACT_URL" | tar -xz</code></pre>



<p class="wp-block-paragraph">Now the download failing stops the build, and <code>pipefail</code> makes sure that failure propagates past the pipe. The first fixes the check, the second makes sure the check is heard.</p>



<h3 class="wp-block-heading">Where <code>set -e</code> quietly gives up</h3>



<p class="wp-block-paragraph">This trips people up constantly. <code>set -e</code> is suspended whenever a command&#8217;s exit status is being consumed by something else. It is not a safety net, it is a default.</p>



<pre class="wp-block-code"><code>set -e

# -e does NOT stop the script here.
# The if statement consumes the exit status.
if grep -q "TODO" src/main.go; then
  echo "found"
fi

# -e does NOT stop the script here either.
# The left side of || is explicitly allowed to fail.
run_migrations || echo "migrations failed, continuing anyway"

# -e DOES stop the script here.
run_migrations</code></pre>



<p class="wp-block-paragraph">The same trap applies inside containers. On Debian-based images <code>/bin/sh</code> is <code>dash</code>, which has no <code>pipefail</code> option at all, so putting <code>set -o pipefail</code> inside a <code>RUN</code> line fails outright. Set the shell at the top of the Dockerfile instead. <a href="https://github.com/hadolint/hadolint" target="_blank" rel="noreferrer noopener">Hadolint</a> flags this as DL4006 and it is worth wiring into your static stage.</p>



<pre class="wp-block-code"><code># Set this before any RUN instruction that contains a pipe.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN curl --fail --silent --show-error --location 
      https://example.com/tool.tar.gz | tar -xz -C /usr/local/bin</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Order stages by cost, not by category</h2>



<p class="wp-block-paragraph">Most pipelines are laid out the way the team thinks about work: tests, then build, then security, then deploy. That grouping is comfortable and it is the wrong axis. Order by two things instead, cost and failure probability.</p>



<p class="wp-block-paragraph">The rule I use: <strong>every stage should be cheaper than the one after it and more likely to fail than the one after it.</strong> If a check catches ten percent of your broken commits and takes fifteen seconds, it goes in front of the check that catches two percent and takes nine minutes. That is the whole design principle behind a fail fast pipeline.</p>



<ol class="wp-block-list">
<li><strong>Syntax and static analysis.</strong> <code>shellcheck</code>, <code>hadolint</code>, <code>yamllint</code>, <code>terraform validate</code>, <code>tflint</code>, formatter checks, type checks. Seconds, no dependencies, no network. This stage catches an embarrassing share of broken pushes.</li>
<li><strong>Unit tests.</strong> No database, no containers, no network. If they need any of those, they are integration tests and belong further down.</li>
<li><strong>Secrets and dependency scanning.</strong> Fast, and a leaked credential is worth stopping before you build an image around it.</li>
<li><strong>Build.</strong> This is where you start spending real minutes and cache space.</li>
<li><strong>Integration and end-to-end.</strong> Slow, flaky, expensive to run. Everything above should have already caught the boring failures.</li>
<li><strong>Deploy and post-deploy verification.</strong></li>
</ol>



<p class="wp-block-paragraph">A note on the trade-off, because this ordering costs something. Splitting the fast checks into their own stage adds a checkout and a container pull before your unit tests even start. On a busy shared runner that overhead is real. If your static stage takes twelve seconds of work and forty seconds of setup, merge it into the test job and run it as the first step instead. The principle is failure order, not job count.</p>



<p class="wp-block-paragraph">The other thing that keeps the fast lane fast is caching, and it is the piece people get wrong in the opposite direction: they cache so aggressively that a stale dependency tree hides a genuine break. Cache the package manager&#8217;s download directory, not the resolved dependency tree, and key the cache on the lockfile hash.</p>



<h2 class="wp-block-heading">Let the platform kill work you already know is doomed</h2>



<p class="wp-block-paragraph">Ordering stages is only useful if the platform actually stops when something breaks. Three settings do most of the work, and they exist under different names on every runner.</p>



<h3 class="wp-block-heading">GitHub Actions</h3>



<pre class="wp-block-code"><code>concurrency:
  # A new push to the same branch cancels the run that is
  # already in flight. Nobody needs results for a commit
  # that has been superseded.
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  static:
    runs-on: ubuntu-latest
    timeout-minutes: 5          # a hung job is worse than a failed one
    steps:
      - uses: actions/checkout@v4   # pin to a full commit SHA in production
      - run: shellcheck scripts/*.sh
      - run: hadolint Dockerfile

  test:
    needs: static               # will not start until static passes
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      fail-fast: false          # see note below
      matrix:
        suite: [unit, contract]
    steps:
      - uses: actions/checkout@v4
      - run: make test-${{ matrix.suite }}</code></pre>



<p class="wp-block-paragraph">That <code>fail-fast: false</code> looks like it contradicts the whole post, so it is worth explaining. Matrix fail-fast defaults to true: one leg fails, the rest get cancelled. That is right when the legs are redundant and you only need to know that something broke. It is wrong when the legs tell you different things. If your matrix is three runtime versions and only one fails, cancelling the others hides whether this is a version-specific problem or a general one, and you will burn a rerun finding out. Fail fast on the pipeline, not on the diagnosis.</p>



<p class="wp-block-paragraph"><code>timeout-minutes</code> is the setting people skip and regret. A job waiting on an interactive prompt, a dead package mirror, or a container that never becomes healthy will sit there consuming a runner until someone notices. Set a timeout on every job, generous enough that a slow day does not trip it and tight enough that a hang gets caught inside one coffee break.</p>



<h3 class="wp-block-heading">GitLab CI</h3>



<pre class="wp-block-code"><code>stages: [static, test, build, deploy]

default:
  interruptible: true     # allows auto-cancel when a newer pipeline starts
  retry:
    max: 2                # capped at 2 by GitLab, so 3 attempts total
    when:
      # Retry only on infrastructure problems.
      # Never retry script_failure: that is your code failing,
      # and retrying it just hides a flaky test.
      - runner_system_failure
      - stuck_or_timeout_failure
      - api_failure

lint:
  stage: static
  timeout: 5m
  script:
    - shellcheck scripts/*.sh

integration:
  stage: test
  needs: [lint]           # DAG: starts as soon as lint passes
  script:
    - make integration</code></pre>



<p class="wp-block-paragraph">The <code>retry: when</code> list is the important bit and it is the one people get lazy about. A bare <code>retry: 2</code> retries on everything including a genuine test failure, which converts an intermittent bug into an invisible one. Scope retries to the failure classes that are genuinely the infrastructure&#8217;s fault. Jenkins has <code>failFast true</code> for parallel stages, Buildkite and CircleCI have their own equivalents, and the reasoning transfers cleanly.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">A failure should hand you the answer, not the search</h2>



<p class="wp-block-paragraph">Here is the test I apply to a pipeline failure. Can someone who did not write the change, at an inconvenient hour, fix it from the failure output alone without opening the source? If not, the failure message is incomplete.</p>



<p class="wp-block-paragraph">Four things need to be in there:</p>



<ul class="wp-block-list">
<li><strong>What failed</strong>, named precisely. Not &#8220;build failed&#8221; but the command and its exit code.</li>
<li><strong>Why</strong>, in terms of the input rather than the internals. &#8220;lockfile is out of date with package.json&#8221;, not &#8220;npm ci exited 1&#8221;.</li>
<li><strong>Where</strong>, meaning the file, the line, or the config key that caused it.</li>
<li><strong>What to do next.</strong> One concrete action, even if it is just a runbook link.</li>
</ul>



<p class="wp-block-paragraph">In shell, a small helper plus an <code>ERR</code> trap gets you most of the way there.</p>



<pre class="wp-block-code"><code>#!/usr/bin/env bash
set -euo pipefail

fail() {
  echo "ERROR: $1" &gt;&amp;2
  echo "  fix: $2" &gt;&amp;2
  exit 1
}

# Catches anything you did not write an explicit check for,
# and tells you the line and the command that blew up.
trap 'echo "FAILED at line $LINENO: $BASH_COMMAND" &gt;&amp;2' ERR

[[ -f config/app.yaml ]] || fail 
  "config/app.yaml is missing" 
  "copy config/app.yaml.example and set DATABASE_URL"

[[ -n "${IMAGE_TAG:-}" ]] || fail 
  "IMAGE_TAG is empty" 
  "check the tag job output; it sets IMAGE_TAG from the git SHA"</code></pre>



<p class="wp-block-paragraph">Note <code>${IMAGE_TAG:-}</code> rather than <code>$IMAGE_TAG</code>. Under <code>set -u</code> the bare form aborts with a shell error before your nice message ever prints, which is technically correct and practically useless.</p>



<p class="wp-block-paragraph">On GitHub Actions you can go one step further and attach the error to the file and line, so it shows up as an annotation on the pull request instead of something to be dug out of a log.</p>



<pre class="wp-block-code"><code># Renders as a red annotation on that exact line in the diff view.
echo "::error file=deploy/values.yaml,line=42::image tag is empty"

# Visible, but does not fail the job.
echo "::warning file=Dockerfile,line=7::apt cache not cleaned"</code></pre>



<p class="wp-block-paragraph">Two more habits worth building. Upload logs, test reports, and screenshots as artifacts on failure, conditionally, so the evidence survives the job that produced it. And emit test results as JUnit XML so the platform renders a list of failed test names instead of asking people to scroll. Both are cheap and both cut the time between &#8220;it broke&#8221; and &#8220;I know why&#8221; more than any clever retry logic will.</p>



<h2 class="wp-block-heading">Exit codes are a contract, so use more than one</h2>



<p class="wp-block-paragraph">Most scripts have two states: 0 and &#8220;something went wrong&#8221;. That collapses distinctions the pipeline needs. Terraform gets this right and it is a good model to copy.</p>



<pre class="wp-block-code"><code># -detailed-exitcode changes the meaning of the exit code:
#   0 = succeeded, no changes
#   1 = error
#   2 = succeeded, changes present
set +e
terraform plan -detailed-exitcode -out=tfplan
code=$?
set -e

case "$code" in
  0) echo "No drift. Skipping apply." ;;
  2) echo "Changes detected. Holding for approval." ;;
  *) echo "Plan failed. See log above." &gt;&amp;2; exit "$code" ;;
esac</code></pre>



<p class="wp-block-paragraph">The <code>set +e</code> around it is deliberate: with <code>-e</code> active, exit code 2 would kill the script before you got to interpret it. This is one of the few places where turning the flag off is the correct move, and it is worth a comment in the file explaining why so nobody &#8220;fixes&#8221; it later.</p>



<p class="wp-block-paragraph">Do the same in your own scripts. Reserve a code for &#8220;the thing you asked for is not possible&#8221; versus &#8220;I could not reach the API&#8221; versus &#8220;your input is wrong&#8221;. The pipeline can then retry one and refuse to retry the others, which is the difference between a retry that absorbs a runner hiccup and a retry that hides a race condition for six months.</p>



<h2 class="wp-block-heading">Gate on what you care about, not what is easy to check</h2>



<p class="wp-block-paragraph">This is the deploy-stage version of the same lie. Plenty of commands confirm that a request was accepted, not that the thing you wanted happened.</p>



<pre class="wp-block-code"><code># Returns 0 the moment the API server accepts the manifest,
# even if every pod goes into CrashLoopBackOff a second later.
kubectl apply -f k8s/

# This is the step that actually waits for the rollout,
# and fails the job if it does not converge.
kubectl rollout status deployment/api --timeout=180s

# And this proves the application answers a request,
# not just that a pod reports Ready.
curl --fail --silent --show-error https://api.example.com/healthz</code></pre>



<p class="wp-block-paragraph">Run that last check against the public hostname, through your CDN, rather than against the pod directly. If you front the app with Cloudflare or similar, a smoke test that skips the edge will happily pass while real users hit a cached error page or a misrouted origin. Same reasoning applies to the origin host itself: if the app runs on a VPS from a provider like InterServer behind a reverse proxy, verify through the proxy, because that is the path traffic takes.</p>



<p class="wp-block-paragraph">Then track how long each stage takes over time. Pipeline duration and failure rate per stage are perfectly ordinary metrics to ship into Prometheus and graph in Grafana, or into whatever platform you already use for application monitoring. When the fast lane creeps from forty seconds to four minutes, that is a slow regression nobody will notice from a single run.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Troubleshooting</h2>



<h3 class="wp-block-heading">The job passed but the artifact is wrong</h3>



<p class="wp-block-paragraph">Look for pipes first. Grep the scripts for <code>|</code> and check whether <code>pipefail</code> is set in that shell. Then check for tools that return 0 on failure: <code>curl</code> without <code>--fail</code>, <code>docker run</code> where the entrypoint swallows errors, anything wrapped in <code>|| true</code> that somebody added during an incident and never removed.</p>



<h3 class="wp-block-heading"><code>set -e</code> is set but the script keeps going</h3>



<p class="wp-block-paragraph">The failing command is almost certainly inside a condition, on the left of <code>||</code> or <code>&amp;&amp;</code>, or in a function that is itself being called from an <code>if</code>. Add <code>set -x</code> temporarily and read the trace to see exactly where control flow continued. Then use an explicit check with your <code>fail</code> helper rather than relying on <code>-e</code> at that point.</p>



<h3 class="wp-block-heading">Works locally, fails in CI (or the reverse)</h3>



<p class="wp-block-paragraph">Usually a shell difference. Your terminal runs bash or zsh, the runner may execute the script with <code>sh</code>. Add an explicit shebang, and on GitHub Actions set the shell on the step or at the job level rather than assuming. Inside containers, remember <code>dash</code> has no <code>pipefail</code> and no <code>[[ ]]</code>.</p>



<h3 class="wp-block-heading">The job hangs until the platform kills it</h3>



<p class="wp-block-paragraph">Something is waiting on stdin. Package managers prompting for confirmation, <code>ssh</code> asking about a host key, a database client waiting for a password. Add the non-interactive flags, set <code>CI=true</code> where tools respect it, and put a timeout on the job so the next occurrence fails in ten minutes instead of sixty.</p>



<h3 class="wp-block-heading">Fails on the first run, passes on rerun</h3>



<p class="wp-block-paragraph">Resist the retry. Log the failure with enough context to identify it later, quarantine the test into a non-blocking job if it is genuinely blocking the team, and give it an owner and a date. A blanket retry turns a flaky test into a permanent tax on everyone&#8217;s confidence in the pipeline.</p>



<h3 class="wp-block-heading">The failure output is a wall of noise</h3>



<p class="wp-block-paragraph">Suppress progress bars and spinners in CI, they render as thousands of unreadable lines. Then print a short summary block at the very end of the job, after the noise, listing what failed and what to do. People read the bottom of a log first.</p>



<h2 class="wp-block-heading">Common mistakes</h2>



<ul class="wp-block-list">
<li>Writing <code>set -e</code> without <code>-o pipefail</code> and assuming the script is covered.</li>
<li>Using <code>|| true</code> to silence a step that fails intermittently, instead of finding out why.</li>
<li>Running the slowest, flakiest checks before the ones that take fifteen seconds.</li>
<li>Retrying on every failure class rather than only infrastructure faults.</li>
<li>No job timeouts, so a hang consumes a runner until someone notices.</li>
<li>Treating <code>kubectl apply</code> or a deploy API call as proof the deploy worked.</li>
<li>Failure messages that name the internal function that threw, and nothing the reader can act on.</li>
<li>Caching so aggressively that a stale dependency tree hides a real break.</li>
<li>Discarding logs and test reports when the job fails, which is exactly when you need them.</li>
<li>Turning off matrix fail-fast everywhere by reflex, so every broken commit costs the full matrix.</li>
</ul>



<h2 class="wp-block-heading">Best practices</h2>



<ul class="wp-block-list">
<li>Put <code>set -euo pipefail</code> at the top of every shell script the pipeline runs, and set the Dockerfile <code>SHELL</code> before any piped <code>RUN</code>.</li>
<li>Order stages so each one is cheaper and more likely to fail than the next.</li>
<li>Give every job a timeout, and cancel superseded runs on the same branch.</li>
<li>Use explicit checks with actionable messages instead of relying on <code>-e</code> to catch everything.</li>
<li>Distinguish exit codes so the pipeline can react differently to different failures.</li>
<li>Verify deploys with a rollout status check plus a real HTTP request through the public path.</li>
<li>Upload artifacts and structured test reports on failure.</li>
<li>Pin action and image references to immutable digests so a green pipeline stays reproducible.</li>
<li>Track stage duration and failure rate over time, the same way you track application metrics.</li>
<li>Fix the failure message the first time somebody has to ask what it means.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">FAQ</h2>



<h3 class="wp-block-heading">What does &#8220;fail fast&#8221; actually mean in a CI/CD pipeline?</h3>



<p class="wp-block-paragraph">Two things. First, the pipeline stops as soon as it knows the result will be a failure, rather than finishing work whose outcome no longer matters. Second, the cheapest checks that are most likely to catch a problem run first, so the average failure surfaces in seconds. The second half is a design choice about ordering, not a platform setting.</p>



<h3 class="wp-block-heading">Is <code>set -e</code> enough on its own?</h3>



<p class="wp-block-paragraph">No. It is suspended inside conditions, on the left side of <code>&amp;&amp;</code> and <code>||</code>, and after <code>!</code>. It also does nothing about pipes, which is why <code>-o pipefail</code> matters, or about commands that return 0 while failing, which is why explicit checks matter. Use it as a baseline, not as your only line of defence.</p>



<h3 class="wp-block-heading">Should I disable matrix fail-fast?</h3>



<p class="wp-block-paragraph">Only when the legs give you different diagnostic information. If the matrix is runtime versions or operating systems and you need to know whether the break is universal or specific, let all legs run. If the legs are interchangeable shards of the same test suite, leave fail-fast on and save the compute.</p>



<h3 class="wp-block-heading">How do I stop a pipeline from passing when a step really failed?</h3>



<p class="wp-block-paragraph">Work through three things in order. Set <code>pipefail</code> so pipes propagate failure. Add the flags that make tools return non-zero on failure, such as <code>curl --fail</code>. Then replace implicit trust with explicit assertions: after a deploy, check that the rollout converged and that the service answers a request. Most silent passes come from one of those three gaps.</p>



<h3 class="wp-block-heading">Are automatic retries a good idea?</h3>



<p class="wp-block-paragraph">Only for failures that are the infrastructure&#8217;s fault: runner crashes, image pull errors, API timeouts from the CI platform itself. Never retry a script failure by default. And make retries visible, because a job that quietly succeeds on the third attempt is telling you something important that nobody sees.</p>



<h3 class="wp-block-heading">How long should a fast feedback stage take?</h3>



<p class="wp-block-paragraph">Short enough that an engineer waits for it rather than switching context. Somewhere under a couple of minutes for the combined lint, format, and unit stage is a reasonable target for most codebases. Past that, people push and walk away, and you lose the benefit of fast feedback even though the pipeline is technically quick.</p>



<h3 class="wp-block-heading">Does this apply to self-hosted runners too?</h3>



<p class="wp-block-paragraph">All of it, and timeouts matter more. On hosted runners a stuck job eventually hits the platform&#8217;s own ceiling. On your own machine it holds a slot until you intervene, so a hung job blocks the queue for everyone. Set explicit timeouts and make sure the runner cleans up its workspace between jobs.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">The one thing to take away</h2>



<p class="wp-block-paragraph">Speed is the part everyone optimises and honesty is the part that actually costs money. A fail fast pipeline that finishes in ninety seconds is worth very little if one of those seconds contains a swallowed exit code. Fix the lying first: <code>pipefail</code>, tools that return non-zero when they fail, and assertions that check the outcome rather than the request. Then reorder for speed.</p>



<p class="wp-block-paragraph">And judge every failure by one question. Could someone else fix this from the output alone, without reading the source? If the answer is no, the pipeline has not finished its job, no matter how quickly it went red.</p>



<h2 class="wp-block-heading">Need help fixing a pipeline that lies to you?</h2>



<p class="wp-block-paragraph">If any of this sounds like your CI, this is the kind of work I take on. Typical engagements look like:</p>



<ul class="wp-block-list">
<li>Auditing an existing GitHub Actions, GitLab CI, or Jenkins pipeline for silently swallowed failures and false-green stages.</li>
<li>Restructuring stage order and caching so the common failure surfaces in seconds instead of after the build.</li>
<li>Hardening deploy verification: rollout gates, smoke tests through the real public path, and automatic rollback on a failed health check.</li>
<li>Rewriting pipeline shell scripts with proper error handling, exit code contracts, and failure messages an on-call engineer can act on.</li>
<li>Wiring pipeline duration and failure metrics into Prometheus and Grafana so regressions get caught early.</li>
</ul>



<p class="wp-block-paragraph">Send me the workflow file and a link to a failing run, and I will tell you what I would change first.</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://www.upwork.com/freelancers/~01f15a912ad84a6620" target="_blank" rel="noreferrer noopener">Work with me on Upwork</a></div>
</div>
<p>The post <a href="https://john-nessime.com/blog/devops/fail-fast-pipeline/">Green Check, Broken Build: How to Build a Fail Fast Pipeline That Explains Why</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://john-nessime.com/blog/devops/fail-fast-pipeline/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Cleaning Up Docker Disk Usage Safely</title>
		<link>https://john-nessime.com/blog/devops/docker-disk-usage-cleanup/</link>
					<comments>https://john-nessime.com/blog/devops/docker-disk-usage-cleanup/#respond</comments>
		
		<dc:creator><![CDATA[John Nessime]]></dc:creator>
		<pubDate>Fri, 31 Jul 2026 19:52:19 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[Containers]]></category>
		<category><![CDATA[Disk Space]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Docker Compose]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Self Hosting]]></category>
		<category><![CDATA[Storage]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<guid isPermaLink="false">https://john-nessime.com/blog/?p=46</guid>

					<description><![CDATA[<p>The top search result tells you to run docker system prune -a --volumes. It frees the space and deletes your database. Here is how to measure Docker disk usage properly, reclaim it from safest to most destructive, and fix the logs that Docker never reports on.</p>
<p>The post <a href="https://john-nessime.com/blog/devops/docker-disk-usage-cleanup/">Cleaning Up Docker Disk Usage Safely</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The alert says the root partition is at 97%. You SSH in, run <code>df -h</code>, and <code>/var/lib/docker</code> is sitting on forty-something gigabytes. The first search result tells you to run <code>docker system prune -a --volumes</code>, and it will absolutely free the space. It will also delete the volume holding your Postgres data.</p>



<p class="wp-block-paragraph">Docker disk usage grows quietly because every part of it accumulates independently — images, stopped containers, volumes, build cache, and container logs, which are the one nobody expects and which no Docker command reports on. Cleaning it up is easy. Cleaning it up without destroying something takes about five more minutes.</p>



<p class="wp-block-paragraph">This is the order I work through it: measure first, reclaim from safest to most destructive, then fix the thing that caused the growth so you are not back here next month.</p>



<h2 class="wp-block-heading">Measure before you delete</h2>



<p class="wp-block-paragraph">Every cleanup starts here, and skipping it is how people delete the wrong thing:</p>



<pre class="wp-block-code"><code>docker system df</code></pre>



<p class="wp-block-paragraph">That gives you four rows — Images, Containers, Local Volumes, Build Cache — with a total size and a reclaimable figure for each. The reclaimable column is the one that matters. If build cache is eleven gigabytes and all of it is reclaimable, you have found your win and you never need to go near volumes.</p>



<p class="wp-block-paragraph">For the itemised version:</p>



<pre class="wp-block-code"><code>docker system df -v</code></pre>



<p class="wp-block-paragraph">Now you can see individual images with their sizes, which containers are using what, and which volumes have no container attached. Read this before running anything destructive.</p>



<p class="wp-block-paragraph">Two more views worth having open:</p>



<pre class="wp-block-code"><code># What is actually running, and what is just sitting there stopped
docker ps -a --format 'table {{.Names}}t{{.Image}}t{{.Status}}t{{.Size}}'

# Images by age, oldest first
docker images --format 'table {{.Repository}}:{{.Tag}}t{{.Size}}t{{.CreatedSince}}'</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Reclaim in order, safest first</h2>



<p class="wp-block-paragraph">These are ordered deliberately. Work down the list and stop as soon as you have enough space. Most of the time you never reach step four.</p>



<h3 class="wp-block-heading">1. Stopped containers</h3>



<pre class="wp-block-code"><code># See what would go
docker ps -a --filter status=exited --filter status=created

docker container prune</code></pre>



<p class="wp-block-paragraph">This removes stopped containers and their writable layers. Anything running is untouched, and named volumes attached to those containers survive — only the container&#8217;s own layer goes.</p>



<p class="wp-block-paragraph">The one caveat: if a stopped container held state in its writable layer rather than in a volume, that state is gone. That is a design problem rather than a cleanup problem, but it is worth a glance before you confirm.</p>



<h3 class="wp-block-heading">2. Build cache</h3>



<p class="wp-block-paragraph">On any machine that builds images regularly, this is usually the biggest single win and it is completely safe. Build cache is derived data. Deleting it costs you a slower next build and nothing else.</p>



<pre class="wp-block-code"><code># Everything older than a week
docker builder prune --filter "until=168h"

# Everything, no exceptions
docker builder prune -a</code></pre>



<h3 class="wp-block-heading">3. Dangling images</h3>



<pre class="wp-block-code"><code># Look first
docker images -f dangling=true

docker image prune</code></pre>



<p class="wp-block-paragraph">Without <code>-a</code>, this removes only dangling images — untagged layers left behind when a rebuild moved a tag to a new image. They are almost always genuine garbage.</p>



<h3 class="wp-block-heading">4. Unused images — read this one carefully</h3>



<pre class="wp-block-code"><code>docker image prune -a</code></pre>



<p class="wp-block-paragraph">Adding <code>-a</code> changes the meaning completely. It removes every image that does not have at least one container associated with it — running <em>or</em> stopped. So an image you pulled for a job that runs weekly, with no container currently existing, is gone. It will pull again, which is fine if you have bandwidth and the registry is reachable, and much less fine at 3am on a machine with a slow link.</p>



<p class="wp-block-paragraph">Safer in most cases is an age filter, which keeps anything recent:</p>



<pre class="wp-block-code"><code>docker image prune -a --filter "until=336h"   # older than 14 days</code></pre>



<h3 class="wp-block-heading">5. Volumes — the one that loses data</h3>



<p class="wp-block-paragraph">Volumes are where databases live. Treat this step as a data operation, not a cleanup.</p>



<p class="wp-block-paragraph">Before removing anything, look inside the candidates. This mounts each dangling volume read-only into a throwaway container so you can see what is actually in it:</p>



<pre class="wp-block-code"><code>docker volume ls -qf dangling=true | while read -r v; do
  echo "=== $v"
  docker run --rm -v "$v":/vol:ro alpine sh -c 'du -sh /vol; ls -la /vol' 2&gt;/dev/null | head -12
done</code></pre>



<p class="wp-block-paragraph">If you see anything resembling a data directory, back it up before it goes:</p>



<pre class="wp-block-code"><code>docker run --rm 
  -v my-volume:/vol:ro 
  -v "$PWD":/backup 
  alpine tar czf /backup/my-volume.tar.gz -C /vol .</code></pre>



<p class="wp-block-paragraph">Only then:</p>



<pre class="wp-block-code"><code>docker volume prune</code></pre>



<p class="wp-block-paragraph">On recent Docker versions this prunes only anonymous volumes by default, with <code>--all</code> needed to include named ones — a genuinely good safety change. Older versions removed named volumes too. Check which behaviour you have before trusting it:</p>



<pre class="wp-block-code"><code>docker version --format '{{.Server.Version}}'
docker volume prune --help</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">The gigabytes Docker never tells you about</h2>



<p class="wp-block-paragraph">Here is the part that catches experienced people. Container logs do not appear in <code>docker system df</code> at all, and no prune command touches them. A chatty application with the default logging driver will happily write tens of gigabytes and nothing in Docker&#8217;s own tooling will mention it.</p>



<pre class="wp-block-code"><code>sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail -10</code></pre>



<p class="wp-block-paragraph">To map a log file back to the container that owns it:</p>



<pre class="wp-block-code"><code>docker ps -aq | xargs docker inspect --format '{{.Name}} {{.LogPath}}'</code></pre>



<h3 class="wp-block-heading">Truncate, do not delete</h3>



<p class="wp-block-paragraph">This matters. Deleting a log file that a running container still has open removes the directory entry but not the data — the kernel keeps the blocks allocated until the process closes the descriptor, so <code>df</code> shows no improvement and you are left confused. Truncate instead:</p>



<pre class="wp-block-code"><code>sudo truncate -s 0 /var/lib/docker/containers/&lt;container-id&gt;/&lt;container-id&gt;-json.log</code></pre>



<h3 class="wp-block-heading">Then stop it happening again</h3>



<p class="wp-block-paragraph">Set a global default in <code>/etc/docker/daemon.json</code>:</p>



<pre class="wp-block-code"><code>{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}</code></pre>



<pre class="wp-block-code"><code>sudo systemctl restart docker</code></pre>



<p class="wp-block-paragraph">One thing people get wrong here: this applies to <strong>newly created containers only</strong>. Anything already running keeps the logging config it was created with. You have to recreate those containers for the limit to take effect — restarting them is not enough.</p>



<p class="wp-block-paragraph">While you are in that file, cap the build cache too:</p>



<pre class="wp-block-code"><code>{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "builder": {
    "gc": {
      "enabled": true,
      "defaultKeepStorage": "20GB"
    }
  }
}</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Automating it without automating a disaster</h2>



<p class="wp-block-paragraph">A weekly cron is worth having, provided it only ever does the safe operations. The rule is simple: never put <code>--volumes</code> in anything unattended.</p>



<pre class="wp-block-code"><code># /etc/cron.d/docker-prune
# Weekly, Sunday 03:00. Containers, networks, dangling images and build
# cache older than seven days. No volumes, ever.
0 3 * * 0 root /usr/bin/docker system prune -f --filter "until=168h" &gt;&gt; /var/log/docker-prune.log 2&gt;&amp;1</code></pre>



<p class="wp-block-paragraph">Note what <code>docker system prune</code> covers without flags: stopped containers, unused networks, dangling images and build cache. It does <em>not</em> touch volumes unless you explicitly pass <code>--volumes</code>, and it does not remove tagged images unless you pass <code>-a</code>. Those two flags are the whole difference between a routine job and an incident.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">If you are tempted to add <code>--volumes</code> to a cron job so you do not have to think about it again, you have swapped a disk space problem for a data loss problem on a timer.</p>
</blockquote>



<h2 class="wp-block-heading">Troubleshooting</h2>



<h3 class="wp-block-heading">Pruned everything, df has not moved</h3>



<p class="wp-block-paragraph">Deleted files still held open by a running process. Find them:</p>



<pre class="wp-block-code"><code>sudo lsof +L1 | head -20</code></pre>



<p class="wp-block-paragraph">Restarting the process that holds the descriptor releases the blocks. If it is the Docker daemon itself, a <code>systemctl restart docker</code> does it, at the cost of bouncing every container without a restart policy.</p>



<h3 class="wp-block-heading">&#8220;No space left on device&#8221; but df shows free space</h3>



<p class="wp-block-paragraph">You are out of inodes rather than bytes. Docker&#8217;s layered storage creates enormous numbers of small files:</p>



<pre class="wp-block-code"><code>df -i</code></pre>



<p class="wp-block-paragraph">The fix is the same — prune images and build cache, which is where the file count lives.</p>



<h3 class="wp-block-heading">overlay2 is huge and I have hardly any images</h3>



<pre class="wp-block-code"><code>sudo du -sh /var/lib/docker/*
sudo du -sh /var/lib/docker/overlay2 2&gt;/dev/null</code></pre>



<p class="wp-block-paragraph">Usually build cache or container writable layers rather than images. Do not delete anything under <code>overlay2</code> by hand — the directory names are referenced in Docker&#8217;s metadata, and removing them directly corrupts the daemon&#8217;s view of the world. Always go through <code>docker</code> commands.</p>



<h3 class="wp-block-heading">Running low and need space right now</h3>



<p class="wp-block-paragraph">Fastest safe sequence, in order:</p>



<pre class="wp-block-code"><code>docker builder prune -a -f
docker container prune -f
docker image prune -f
sudo truncate -s 0 /var/lib/docker/containers/*/*-json.log</code></pre>



<p class="wp-block-paragraph">Four commands, no volumes touched, no tagged images removed. That resolves the large majority of Docker disk usage emergencies.</p>



<h2 class="wp-block-heading">Common mistakes</h2>



<ul class="wp-block-list">
<li>Reaching for <code>docker system prune -a --volumes</code> first because it is the top search result.</li>

<li>Putting <code>--volumes</code> in a cron job.</li>

<li>Deleting log files instead of truncating them, then wondering why <code>df</code> did not change.</li>

<li>Setting log limits in <code>daemon.json</code> and assuming existing containers pick them up. They do not.</li>

<li>Removing directories under <code>/var/lib/docker/overlay2</code> by hand.</li>

<li>Storing application data in a container&#8217;s writable layer rather than a volume, so cleanup destroys it.</li>

<li>Never running <code>docker system df</code>, and so deleting the wrong category entirely.</li>

<li>Assuming inodes cannot be the problem.</li>
</ul>



<h2 class="wp-block-heading">Best practices</h2>



<ul class="wp-block-list">
<li>Set log rotation in <code>daemon.json</code> on every host, on day one.</li>

<li>Cap build cache with the builder GC settings rather than relying on manual pruning.</li>

<li>Use named volumes for anything you care about, so cleanup and data are clearly separated.</li>

<li>Use multi-stage builds and a real <code>.dockerignore</code>. Smaller images mean less to clean up.</li>

<li>Automate only the safe operations, with an age filter, and log what the job removed.</li>

<li>Alert on disk usage at 80% so cleanup is a scheduled task rather than an incident.</li>

<li>On busy build hosts, give <code>/var/lib/docker</code> its own partition so a runaway cache cannot take the OS down with it.</li>
</ul>



<h2 class="wp-block-heading">Frequently asked questions</h2>



<h3 class="wp-block-heading">Is <code>docker system prune</code> safe to run?</h3>



<p class="wp-block-paragraph">Without flags, yes, on most systems. It removes stopped containers, unused networks, dangling images and build cache. Adding <code>-a</code> also removes tagged images with no container attached. Adding <code>--volumes</code> is the one that can lose data.</p>



<h3 class="wp-block-heading">Will pruning delete my database?</h3>



<p class="wp-block-paragraph">Only if the database lives in a volume and you pass <code>--volumes</code>, or it lives in a container&#8217;s writable layer and you prune that container. If it is in a named volume attached to a running container, ordinary pruning will not touch it.</p>



<h3 class="wp-block-heading">Why does <code>docker system df</code> not match <code>du</code>?</h3>



<p class="wp-block-paragraph">Two reasons. It does not count container logs at all, and it accounts for shared image layers once rather than per image. <code>du -sh /var/lib/docker</code> is the honest total.</p>



<h3 class="wp-block-heading">How do I stop logs growing without limit?</h3>



<p class="wp-block-paragraph">Set <code>max-size</code> and <code>max-file</code> under <code>log-opts</code> in <code>/etc/docker/daemon.json</code>, restart the daemon, then recreate existing containers so they pick up the new configuration.</p>



<h3 class="wp-block-heading">Can I move Docker&#8217;s storage to another disk?</h3>



<p class="wp-block-paragraph">Yes, with <code>data-root</code> in <code>daemon.json</code>. Stop Docker, copy <code>/var/lib/docker</code> across preserving ownership and extended attributes, point <code>data-root</code> at the new location, then start it again. Copy rather than move until you have confirmed it works.</p>



<h3 class="wp-block-heading">Does pruning affect running containers?</h3>



<p class="wp-block-paragraph">No. Prune operations skip anything in use. The risk is always to things that are stopped, dangling or unattached — which is exactly why checking what is stopped before you prune is worth the thirty seconds.</p>



<h2 class="wp-block-heading">Wrapping up</h2>



<p class="wp-block-paragraph">Docker disk usage is four categories that grow independently, plus a fifth — logs — that hides from Docker&#8217;s own accounting. Run <code>docker system df</code>, work down from build cache to volumes, and stop as soon as you have the space. The nuclear option exists, but reaching for it first is how people discover which of their volumes mattered.</p>



<p class="wp-block-paragraph">Once the immediate problem is solved, spend ten minutes on log rotation and builder GC. Those two settings turn this from a recurring emergency into something you never think about again.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Need a hand with Docker in production?</h2>



<p class="wp-block-paragraph">I work with teams on container infrastructure — image sizes that got out of hand, build pipelines that cache badly, storage and logging defaults that were never set, and monitoring that catches a full disk before the alert does.</p>



<p class="wp-block-paragraph">If you would rather not spend the evening on it, you can hire me on Upwork.</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://www.upwork.com/freelancers/~01f15a912ad84a6620" target="_blank" rel="noreferrer noopener">Work with me on Upwork</a></div>
</div>
<p>The post <a href="https://john-nessime.com/blog/devops/docker-disk-usage-cleanup/">Cleaning Up Docker Disk Usage Safely</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://john-nessime.com/blog/devops/docker-disk-usage-cleanup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pulumi vs Terraform: Choosing a Lane</title>
		<link>https://john-nessime.com/blog/devops/pulumi-vs-terraform/</link>
					<comments>https://john-nessime.com/blog/devops/pulumi-vs-terraform/#respond</comments>
		
		<dc:creator><![CDATA[John Nessime]]></dc:creator>
		<pubDate>Thu, 30 Jul 2026 15:10:36 +0000</pubDate>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Technical Guides]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[CI/CD]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[HCL]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Infrastructure as Code]]></category>
		<category><![CDATA[OpenTofu]]></category>
		<category><![CDATA[Production]]></category>
		<category><![CDATA[Pulumi]]></category>
		<category><![CDATA[Terraform]]></category>
		<guid isPermaLink="false">https://john-nessime.com/blog/?p=36</guid>

					<description><![CDATA[<p>The licence changed, the community forked, IBM bought HashiCorp, CDKTF was archived, and Pulumi started speaking HCL. Here is an honest read of where Pulumi vs Terraform actually stands in 2026, and how to pick a lane you will not regret.</p>
<p>The post <a href="https://john-nessime.com/blog/devops/pulumi-vs-terraform/">Pulumi vs Terraform: Choosing a Lane</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Every few months someone on a platform team reopens the same argument. Half the room wants infrastructure in TypeScript because they are tired of writing loops in a configuration language. The other half points out that the last person who tried that left behind two thousand lines nobody can review. Both sides are right, which is why the argument never resolves.</p>



<p class="wp-block-paragraph">The Pulumi vs Terraform question got harder in the last two years, not easier. The licence changed, the community forked, IBM bought HashiCorp, HashiCorp killed its own general-purpose-language option, and Pulumi started speaking HCL. A lot of the comparison articles you will find were written before any of that happened.</p>



<p class="wp-block-paragraph">This is an attempt at an honest read of where things actually stand, what the real trade-off is once you strip away the marketing, and how to pick a lane you will not regret in eighteen months.</p>



<h2 class="wp-block-heading">What actually changed</h2>



<p class="wp-block-paragraph">A short timeline, because the current landscape only makes sense against it.</p>



<ul class="wp-block-list">
<li><strong>August 2023</strong> — HashiCorp relicensed Terraform from MPL 2.0 to the Business Source License. Source-available, free for provisioning your own infrastructure, but you cannot build a competing commercial product on it.</li>

<li><strong>January 2024</strong> — OpenTofu shipped 1.6.0, a fork of the last MPL-licensed code, governed by the Linux Foundation.</li>

<li><strong>February 2025</strong> — IBM completed its acquisition of HashiCorp, valued at around $6.4 billion.</li>

<li><strong>December 2025</strong> — HashiCorp deprecated CDK for Terraform and archived the repository. The official way to write Terraform in a general-purpose language no longer exists.</li>

<li><strong>Also December 2025</strong> — Pulumi announced native HCL support and the ability to work with Terraform and OpenTofu state.</li>
</ul>



<p class="wp-block-paragraph">Those last two matter more than the licence drama, and they point in opposite directions. HashiCorp closed the door on writing Terraform in a real language. Pulumi opened the door to writing Pulumi in HCL. Whatever else you conclude, &#8220;HCL versus real languages&#8221; is no longer a clean line between two products.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">The real axis: a configuration language or a programming language</h2>



<p class="wp-block-paragraph">Strip out the licensing and the corporate ownership and one genuine difference remains. HCL is a purpose-built configuration language that describes desired state. Pulumi runs an actual program that constructs a resource graph, and then applies it.</p>



<p class="wp-block-paragraph">Here is the same trivial thing in both. Terraform:</p>



<pre class="wp-block-code"><code>resource "aws_s3_bucket" "logs" {
  for_each = toset(var.environments)
  bucket   = "acme-logs-${each.key}"

  tags = {
    Environment = each.key
    ManagedBy   = "terraform"
  }
}</code></pre>



<p class="wp-block-paragraph">And Pulumi, in TypeScript:</p>



<pre class="wp-block-code"><code>import * as aws from "@pulumi/aws";

const environments = ["dev", "staging", "prod"];

const buckets = environments.map(env =&gt;
  new aws.s3.Bucket(`logs-${env}`, {
    bucket: `acme-logs-${env}`,
    tags: {
      Environment: env,
      ManagedBy: "pulumi",
    },
  })
);</code></pre>



<p class="wp-block-paragraph">For something this small the difference is aesthetic. It stops being aesthetic around the third nested conditional.</p>



<h3 class="wp-block-heading">What you actually gain with a general-purpose language</h3>



<ul class="wp-block-list">
<li><strong>Real abstractions.</strong> Classes, functions, inheritance. A Pulumi component that encapsulates &#8220;our standard service&#8221; is just a class, and it composes the way code composes.</li>

<li><strong>Real testing.</strong> Jest, pytest, Go&#8217;s testing package. You can unit test infrastructure logic with the same tools and the same CI as the rest of your codebase.</li>

<li><strong>The package ecosystem.</strong> Need to parse a CSV of subnets, call an internal API, or do something genuinely awkward? It is an npm install rather than an external data source and a shell script.</li>

<li><strong>IDE support that works.</strong> Type checking, refactoring, jump-to-definition. HCL tooling has improved a lot but it is not the same thing.</li>
</ul>



<h3 class="wp-block-heading">What you lose, which comparison posts skip</h3>



<p class="wp-block-paragraph">This is the part worth reading twice, because it is where the regret comes from.</p>



<ul class="wp-block-list">
<li><strong>Constraint is a feature.</strong> HCL is limited on purpose. When a language cannot express clever things, nobody writes clever things. Give a team a real language and someone will eventually build a metaprogramming layer that generates resource names from a database lookup, and reviewing that pull request will be nobody&#8217;s idea of a good afternoon.</li>

<li><strong>Readability across skill levels.</strong> A network engineer who has never written TypeScript can usually read HCL and tell you what it provisions. The reverse is not true. If your infrastructure is touched by people who are not primarily programmers, that matters enormously.</li>

<li><strong>The hiring pool.</strong> There are far more engineers with Terraform on their CV than Pulumi. That is not an argument about quality, it is an argument about how long it takes to backfill a role.</li>

<li><strong>A dependency on a runtime.</strong> Pulumi programs need Node, Python, or Go present and correct in every environment that runs them, including CI. It is one more thing that can drift.</li>

<li><strong>Asynchrony leaks into the model.</strong> Resource outputs are not plain values. They are futures, and you have to handle them as such. Every Pulumi team hits this on day two.</li>
</ul>



<pre class="wp-block-code"><code># This does not do what a newcomer expects. bucket.id is an Output,
# not a string, so you get an object reference in the name.
# bucket_name = f"logs-for-{bucket.id}"

# Correct: work inside apply, where the value is resolved.
bucket_name = bucket.id.apply(lambda bid: f"logs-for-{bid}")</code></pre>



<p class="wp-block-paragraph">None of these are dealbreakers. They are just the bill that arrives later, and it is worth reading before you sign.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">State, providers, and the things that actually break</h2>



<h3 class="wp-block-heading">State management</h3>



<p class="wp-block-paragraph">Both tools keep a state file mapping your code to real resources, and both will ruin your afternoon if that file gets corrupted or out of sync.</p>



<p class="wp-block-paragraph">Terraform and OpenTofu use pluggable backends: S3 with DynamoDB locking, Azure Blob, GCS, Consul, or HCP Terraform. OpenTofu added client-side state encryption, which Terraform does not have natively and which is a genuine advantage if your compliance people care about what is sitting in that bucket.</p>



<p class="wp-block-paragraph">Pulumi defaults to Pulumi Cloud, which is free for individuals and paid for teams. It also supports self-managed backends, and you should know this because the default sometimes gets mistaken for a requirement:</p>



<pre class="wp-block-code"><code># Self-managed state in S3, no Pulumi Cloud account involved
pulumi login s3://my-pulumi-state-bucket

# Or entirely local, useful for experiments
pulumi login --local</code></pre>



<p class="wp-block-paragraph">Pulumi encrypts secrets in state by default. With Terraform, values marked sensitive are redacted in output but still sit in plaintext in the state file, which surprises people who assumed otherwise.</p>



<h3 class="wp-block-heading">The provider ecosystem, and a myth worth killing</h3>



<p class="wp-block-paragraph">You will read that Pulumi has a much smaller provider ecosystem. That was true once and is mostly no longer the point, because Pulumi bridges Terraform providers. If a Terraform provider exists, you can almost certainly use it from Pulumi, either pre-built in the Pulumi Registry or generated on demand.</p>



<p class="wp-block-paragraph">Two caveats that are real:</p>



<ul class="wp-block-list">
<li>Bridged providers can lag upstream releases. If you need a resource type that shipped last week, check before committing.</li>

<li>When something breaks deep in a bridged provider, you are debugging across a translation layer. That is a worse afternoon than debugging the provider directly.</li>
</ul>



<p class="wp-block-paragraph">Pulumi also ships native providers for Kubernetes and Azure, generated from the platform APIs, which give same-day coverage of new resources rather than waiting on a bridge.</p>



<h3 class="wp-block-heading">Policy and governance</h3>



<p class="wp-block-paragraph">Terraform&#8217;s first-class answer is Sentinel, which is tied to HCP Terraform. OpenTofu users generally reach for OPA or Conftest. Pulumi has CrossGuard, where policies are written in the same languages as everything else.</p>



<p class="wp-block-paragraph">If you are in a regulated environment and your auditors already know what Sentinel is, that is a heavier thumb on the scale than any language preference.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Licensing, since it is what forced the question</h2>



<ul class="wp-block-list">
<li><strong>Terraform</strong> — BSL 1.1. Source-available. Fine for provisioning your own infrastructure. Not fine for building a product that competes with HashiCorp. Each release converts to an open licence four years after publication, but only that release.</li>

<li><strong>OpenTofu</strong> — MPL 2.0, OSI-approved, Linux Foundation governance. No single vendor can relicense it.</li>

<li><strong>Pulumi</strong> — Apache 2.0 for the engine and CLI. Permissive, with a patent grant. Pulumi Corp monetises through Pulumi Cloud rather than through the licence.</li>
</ul>



<p class="wp-block-paragraph">For the overwhelming majority of teams, the BSL changes nothing about daily work. You are provisioning your own infrastructure and that is explicitly permitted. The concern is not today&#8217;s terms, it is that a single vendor demonstrated it can change them, and that vendor is now part of IBM.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">If your objection to Terraform is licensing rather than language, the answer is OpenTofu, not Pulumi. Switching paradigms to solve a legal problem is an expensive way to do it.</p>
</blockquote>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Choosing a lane</h2>



<p class="wp-block-paragraph">Three coherent positions. Pick the one that matches your constraints rather than the one that sounds most modern.</p>



<h3 class="wp-block-heading">Lane one: OpenTofu</h3>



<p class="wp-block-paragraph">The default for most teams already running Terraform who are uneasy about the licence. Migration is genuinely close to free: same HCL, same providers, same state format, same commands.</p>



<pre class="wp-block-code"><code># Back up state first. Always.
terraform state pull &gt; backup-$(date +%F).tfstate

# Then initialise with tofu against the same backend
tofu init
tofu plan</code></pre>



<p class="wp-block-paragraph">A clean plan with no proposed changes means you are done. That is the whole migration for most codebases.</p>



<p class="wp-block-paragraph"><strong>Choose this if:</strong> you have existing Terraform, HCL is working for you, and you want open governance without retraining anyone.</p>



<h3 class="wp-block-heading">Lane two: Terraform with HCP</h3>



<p class="wp-block-paragraph">Still the biggest ecosystem, the most documentation, the most Stack Overflow answers, the most people who already know it. Stacks and ephemeral resources are Terraform-only. Sentinel is Terraform-only. If you are deep in HCP Terraform and it works, the licence is an abstract concern rather than a practical one.</p>



<p class="wp-block-paragraph"><strong>Choose this if:</strong> you are in a regulated industry, you need vendor support with a contract behind it, or your organisation is standardising on IBM and Red Hat tooling anyway.</p>



<h3 class="wp-block-heading">Lane three: Pulumi</h3>



<p class="wp-block-paragraph">The strongest case for Pulumi is not &#8220;real languages are nicer&#8221;. It is when your infrastructure genuinely needs logic that HCL fights you on: dynamic topologies, infrastructure derived from application code, platform teams building abstractions for other teams to consume. If you are writing a self-service platform rather than a set of environments, a real language stops being a preference and starts being the right tool.</p>



<p class="wp-block-paragraph"><strong>Choose this if:</strong> your team is primarily software engineers, your infrastructure has real branching logic, or you are building a platform product rather than provisioning a fixed estate.</p>



<p class="wp-block-paragraph"><strong>Do not choose it</strong> because writing loops in HCL annoyed you once.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">What migrating actually looks like</h2>



<p class="wp-block-paragraph">Terraform to OpenTofu is a swap. Terraform to Pulumi is a refactor, and anyone telling you otherwise is selling something.</p>



<p class="wp-block-paragraph">Pulumi does provide real tooling for it:</p>



<pre class="wp-block-code"><code># Convert HCL into a Pulumi program in your chosen language
pulumi convert --from terraform --language typescript

# Adopt the resources described by an existing state file
pulumi import --from terraform ./terraform.tfstate</code></pre>



<p class="wp-block-paragraph">Pulumi can also consume Terraform modules directly, so existing module investment is not automatically wasted. That is the single most useful fact for anyone considering a gradual move.</p>



<p class="wp-block-paragraph">A sane sequence:</p>



<ol class="wp-block-list">
<li>Pick one small, low-risk stack. Not the production VPC.</li>

<li>Convert it, import the state, and run a preview. The only acceptable result is no changes.</li>

<li>Refactor the generated code. Converted output is mechanically correct and stylistically awful, which is fine, but do not leave it that way.</li>

<li>Run both tools side by side for a while. Coexistence is supported; a big-bang cutover is not necessary.</li>

<li>Only then decide whether to move anything else.</li>
</ol>



<p class="wp-block-paragraph">If step two produces a diff you cannot explain, stop. An unexplained diff during an IaC migration is how resources get destroyed and recreated.</p>



<h2 class="wp-block-heading">Common mistakes</h2>



<ul class="wp-block-list">
<li>Switching tools to solve a licensing concern when OpenTofu solves it for free.</li>

<li>Picking the tool the loudest engineer prefers rather than the one the whole team can maintain.</li>

<li>Adopting CDKTF in 2026. It was archived in December 2025 and will not receive fixes.</li>

<li>Treating a converted program as finished code rather than a starting point.</li>

<li>Assuming Terraform state is safe because values are marked sensitive. Encrypt the backend.</li>

<li>Migrating production first because it is the stack that matters most. It is the stack that matters most.</li>

<li>Running two tools against the same resources without a clear ownership boundary.</li>
</ul>



<h2 class="wp-block-heading">Best practices whichever lane you pick</h2>



<ul class="wp-block-list">
<li>Remote state with locking and encryption, from the first commit. Never local state for anything shared.</li>

<li>Small stacks with clear boundaries. One enormous state file is the most common self-inflicted wound in this field.</li>

<li>Plan or preview output in every pull request, and require a human to read it.</li>

<li>Pin provider versions. Floating versions turn an unrelated deploy into an incident.</li>

<li>Policy as code before you need it, not after the audit.</li>

<li>Document the decision. Six months from now nobody will remember why, and the reasoning is worth more than the choice.</li>
</ul>



<h2 class="wp-block-heading">Frequently asked questions</h2>



<h3 class="wp-block-heading">Is Pulumi better than Terraform?</h3>



<p class="wp-block-paragraph">Neither is better in the abstract. Pulumi suits teams of software engineers building infrastructure with real logic in it. Terraform and OpenTofu suit teams provisioning a defined estate where constraint and readability matter more than expressiveness.</p>



<h3 class="wp-block-heading">Can I use Terraform providers with Pulumi?</h3>



<p class="wp-block-paragraph">Yes. Pulumi bridges Terraform providers, either pre-built in its registry or generated on demand, and can consume Terraform modules directly. Bridged providers can lag upstream releases, so verify coverage for anything recent.</p>



<h3 class="wp-block-heading">Should I move from Terraform to OpenTofu?</h3>



<p class="wp-block-paragraph">If licensing is your concern, it is close to free: same HCL, same providers, same state. Back up state, run <code>tofu init</code> and <code>tofu plan</code>, and confirm no changes. If you rely on Stacks, Sentinel, or HCP Terraform, staying put is reasonable.</p>



<h3 class="wp-block-heading">What happened to CDKTF?</h3>



<p class="wp-block-paragraph">HashiCorp deprecated it on 10 December 2025 and archived the repository. It gets no further fixes or compatibility updates. If you want general-purpose languages for infrastructure now, Pulumi is the maintained option.</p>



<h3 class="wp-block-heading">Does the BSL licence stop me using Terraform commercially?</h3>



<p class="wp-block-paragraph">Not for provisioning your own infrastructure, which is what almost everyone does. It restricts building a competing commercial IaC product on top of it. Check with your own legal team rather than a blog post if you are anywhere near that line.</p>



<h3 class="wp-block-heading">Can Pulumi and Terraform coexist?</h3>



<p class="wp-block-paragraph">Yes, and for any migration of size that is the sensible approach. Pulumi can reference Terraform state and consume Terraform modules. The rule is that each resource has exactly one owner.</p>



<h2 class="wp-block-heading">Wrapping up</h2>



<p class="wp-block-paragraph">The Pulumi vs Terraform decision is less about the tools than about who maintains your infrastructure and what it has to do. If your estate is a known set of environments maintained by people with mixed backgrounds, a constrained configuration language is a feature and OpenTofu gives you that without licensing anxiety. If you are building a platform, with branching logic and abstractions other teams consume, a real language earns its complexity and Pulumi is the maintained way to get one.</p>



<p class="wp-block-paragraph">What has genuinely changed is that the lanes are no longer walled off. Pulumi speaks HCL and reads Terraform state. OpenTofu is a drop-in for Terraform. Converting between them is tooling rather than a rewrite. That makes the decision less permanent than it feels, which is a good reason to pick deliberately and a bad reason to agonise.</p>



<p class="wp-block-paragraph">Pick the lane your team can still maintain when the person who chose it has moved on. Then write down why.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Need help choosing or migrating?</h2>



<p class="wp-block-paragraph">I work with teams on infrastructure as code decisions and the migrations that follow — Terraform to OpenTofu, Terraform to Pulumi, splitting up state files that grew too large, and wiring the whole thing into CI with policy checks that actually run.</p>



<p class="wp-block-paragraph">If you would rather talk it through with someone who has untangled a few of these, you can hire me on Upwork.</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://www.upwork.com/freelancers/~01f15a912ad84a6620" target="_blank" rel="noreferrer noopener">Work with me on Upwork</a></div>
</div>
<p>The post <a href="https://john-nessime.com/blog/devops/pulumi-vs-terraform/">Pulumi vs Terraform: Choosing a Lane</a> appeared first on <a href="https://john-nessime.com/blog">John Nessime</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://john-nessime.com/blog/devops/pulumi-vs-terraform/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
