Color theme Dark mode Font size Content width


Published on 04/24/2020

I just released a tiny tool function I’ve been using for some time called terrasave. It’s a Bash / Fish function that prevents you from running terraform without the -target option.

Why does this exist?

In terraform it is incredibly easy to destroy things with terraform apply. If you run apply terraform shows a huge output and sometimes you may overlook a thing being “replaced” instead of updated. Once upon a time I destroyed a MongoDB Atlas Cluster this way and lost all its data, because the “must be replaced” was hidden in a lot of terraform output and I simply didn’t see it. I only realized when terraform logged “Still destroying cluster…” to the console.

Some terraform resources, like Amazon ECS Services, are not idempotent, so they change on every apply. This cluttered my terminal with stuff I could ignore on every change as well as unnecessary updates to the infra (ECS Services being replaced despite no changes were made).

To prevent this, I forced myself to only use terraform with the -target switch, and this tiny script helps me accomplish that.


After installing the tool you can just work as you’d normally do: terrasave acts as a shell alias for terraform so whenever you run terraform in a terminal, the call goes “through” the terrasave function. If the function detects apply but not -target it outputs an error and exits.

$ terraform apply
Please run "terraform apply" with -target option

If you must run terraform without a target you can do so by specifying an environment variable:


You can get the source code and installation instructions on Hopefully this little tool will save your infra. :)



Like this?

If this content has helped you or your company, consider making a donation to a good cause.

For example, consider donating to the following causes:

A Selfie of me

Kevin Gimbel

is a DevOps Engineer and avid (Video) Gamer. He’s also interested in Sci-Fi, Cyberpunk, and dystopian books.

Wearing a mask is a good idea!

You can find out more about me if you wish.