Terraeasy — my new, very simple, DRY Terraform wrapper.

Jacek Kikiewicz
2 min readFeb 25, 2023

TL;DR

terraeasy.sh is a bash based terraform wrapper. You can get it here: https://github.com/jaceq/terraeasy

The why?

I recently came (yet again!) to a question: Should I use ‘naked’ terraform? Should I use terragrunt? Should I write some wrapper on my own?

I am not a fan of using terraform binary directly, it doesn’t allow DRY (Do not Repeat Yourself) approach in cases if you have similar environments (eg. staging, production etc.) sharing most, if not all of .tf state files — so no, no ‘naked’ terraform binary for me!

Terragrunt, it has become quite popular, many recommend it. I had a look at it and after my initial optimism I found it way too restrictive for my liking. Thing that pushes my away the most is that, if you follow ‘best practices’ for it, you give up something that terraform does really well — graphing dependencies within the state and ability to recognize ‘chain reaction’ of events, in case if a resource is changed, on other resources in a state. So… no, no terragrunt for me.

At that stage I decided to come up with something on my own, something very simple, that allows DRY approach but at the same time is simply customizable (and terragrunt binary sadly isn’t) and keeps terraform doing what it does best.

Terreasy

So, custom it is! I have written a very simple (bash based) wrapper, that remains very simple to extend, optimize, change (again, it’s in bash).
Basic ideas / concepts are:
- simplicity
- flexibility
- DRY
- clear structure (directory based, similar to terragrunt)
- efficient usage of multiple custom modules

Directory structure
There is a directory (in config example called ‘common’) that will contain any resources that are common between environments.
Them, every environment (eg. prod, stage) will have it’s own directory that will contain any extra resources needed for given environment and variables / values that are different as well as backend configuration.
There is also a ‘working’ directory, where .terraform and .terraform.lock.hcl will be stored.

How does it work?
Basically, on runtime, terraeasy.sh will link contents of ‘common’ directory and chosen environment (eg. prod) to working directory and run terraform binary on top of merged structure (while re-configuring backend every time).

Efficient usage of custom modules
Terraeasy (if git URL is provided in config file) will git clone / update common git repository with your custom modules. With this you can put local source for them and avoid pulling them one by one (this is handy when you have some of them). This option however requires installed and configured git — can be disables by simply not adding git URL in config.

Usage
Simply run ./terraeasy.sh and it will tell you what it needs :)

Where can I get it?
You can get it at my github: https://github.com/jaceq/terraeasy

--

--