CICD for Terraform with GitHub Actions


something like this ;)


Terraform Plan

  • name section is the name of the workflow
  • on defines when the workflow should be triggered. Here when there is a Pull Request created to the main branch and when there is changes for files inside infrastructure
  • env defines the environment variables required for this particular workflow or for the jobs that is going to run. The variables are related to terraform config that is run. All those secrets are stored in GitHub Secrets.
  • jobs section contains all the jobs that needs to run for this workflow. There is:
    - Install terraform
    - Check terraform formatting is proper
    - Initialize terraform
    - Validate terraform
    - Run terraform Plan
    - Run commands to update the PR if its passed or failed
  • Terraform is installed all the time, because I am using a public ubuntu image and I am not sure if proper version of terraform is installed or not. This additional help is better than building my own custom image and using it.
  • The posting info job uses actions/github-script@v6 . You will need to give more attention on the format on printing information, otherwise it might look a bit ugly :P

Terraform Apply

Terraform plan
terraform apply

Next Steps

  • PR and merge from feature to development branch, goes to DEV
  • PR and merge from development to main branch, goes to TEST/UAT
  • And creation of tag and deploying it will go to PROD.




Passionate DevOps and Automation Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store