DEV Community

Cover image for GitHub template for Terraform projects
Mark Sta Ana
Mark Sta Ana

Posted on

GitHub template for Terraform projects

Photo by Shane McLendon on Unsplash

Hot on the heels of my last template for Rust, I've created a new one for Terraform. As before this gives you a new Terraform ready project that uses GitHub Actions for Terraform as a CI pipeline.

What this means, is that your project from day one will always perform the following Terraform commands against any code changes (PRs, pushes, etc):

  • fmt - Rewrites all Terraform configuration files to a canonical format.
  • init - Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
  • validate - Validate the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc.

Here's how to use it

  • go to my template:
  • click on the "Use this template" button
  • fill out the project details using the new project wizard
  • clone your new project
  • cd to your project
  • initialise the project i.e. create a and add resources
  • commit and push your changes up to GitHub
  • sit back and relax as GitHub Actions will now perform checks against any code changes submitted to your new Rust project

If you're wondering why I don't include a, it's rare for terraform projects to have similar infrastructure. Also, I didn't see the point of sticking an empty terraform file for the sake of having one.

You maybe have noticed that plan and apply aren't included, these usually require secrets to be set i.e. API keys, Cloud Vendor access keys and again these are too specific to a given project.

Update: turns out init will be unhappy if there's any remote backends. I will write a new blog post to share my findings of wiring up this workflow to an existing remote backend on Azure Storage.

I'd love to know what you think of this template. :)

Top comments (0)