Member-only story

Easy Test Deployments with Terraform

Ben Force
2 min readAug 18, 2022

Recently I was forced into using Terraform to define infrastructure. I’m so used to CDK and being able to adjust everything through context settings that I quickly ran into a problem: how do I deploy a copy of my project to test it?

Editing Files Directly

All I needed to update was the backend and my AWS profile. So the first way I tried was pretty obvious, edit the main terraform file where the backend and AWS provider is defined. The obvious problem is that I make frequent commits and usually just do git commit -a -m .... So I knew those changes would run in a pipeline and blow it up.

What About Variables?

My next idea was to use variables that would work for the AWS profile. The problem is the backend block needed to be set to local, and you can't pass variables into block labels.

Override Files

It turns out that HashiCorp has a solution for this: Override Files. They essentially work the same as my first method of editing the terraform file, but it’s done in a special file to keep it out of the repository.

Add *override.tf to your .gitignore file, then add a file next to the one you want to update with the same name, but add _override to the end. For example, I created the file…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Ben Force
Ben Force

Written by Ben Force

I am a 5x AWS certified senior full-stack developer. I write about cloud architecture, infrastructure as code, and automation.

No responses yet

Write a response

Recommended from Medium

Lists

See more recommendations