Deploying Terraform using GitHub actions

When working with AWS services I have been using Terraform as my Infra As Code. In the project I am currently working on I have a CI/CD pipeline for deploying project code using GitHub actions. However, I would now like to extend my pipeline to deploy any infrastructure changes when there are any.

The Goals

  • I want the terraform action to only run when there has been changes to a file within my terraform directory, it doesn’t need to run on all code deployments
  • I want to be able to view a plan of my terraform changes, when any infra changes are pushed up in a commit to a PR. This will allow any reviewers to review the changes and plan as well.
  • I only want to proceed with a terraform deployment when the code has been merged into the main branch

TL;DR: If you are under time pressure, my working config is at the end of the blog with an explanation on how it works. I hope it helps!

Visit Now