DEV Community

Adam the Automator
Adam the Automator

Posted on • Originally published at adamtheautomator.com on

Getting Started with GitHub Actions and Terraform: A Hands-On Tutorial

In the world of DevOps, it's critical to ensure consistent and repeatable builds, testing and deployment. Continuous Integration (CI) and Continuous Delivery (CD) (CI/CD) should be an important goal to strive for. In this article, you're going to learn about one of those platforms, GitHub Actions. You will learn from both a theoretical and hands-on approach to working with GitHub Actions.

GitHub Actions: What's the Big Deal?

GitHub Actions is a CI/CD system developed by GitHub to integrate directly with GitHub repositories (repos). It allows developers to customize their CI/CD workflows by defining workflows using YAML files.

A workflow, as defined by GitHub Actions, or a pipeline is a common term to describe all of the tasks to perform to build, package, test and deploy code to an environment. A workflow is used to compile code, deploy software or create cloud infrastructure like virtual machines, virtual networks, storage, etc. GitHub Actions is the workflow.

Continuous Integration is the ability to merge all working developer code to a shared location several times a day. This could be to a master branch for example while using proper Gitflow.

Swift Feedback is Important

As developers (devs) build software, they need constant feedback. They need to know what bugs exist in code, what issues arise when running the code on infrastructure or what potential problems may occur. GitHub Actions allows devs to get feedback in a fast and efficient manner.

Devs can commit code to a GitHub repo, begin a build and test process and immediately notice any issue that crop up. That issue could be syntax, a wrong method, or some other bug that they're unaware of. Automating your build and deployment workflow with GitHub Actions allows you to know how your code interacts with the environment right away.

Benefits of GitHub Actions

GitHub Actions brings up a lot of interesting use cases and benefits. Some of the most common use cases include:

  • Continuously deploying code to dev, QA and production environments - Development and QA environments will always have the latest code if you're constantly deploying to environments with GitHub Actions. Once that code has passed QA, you can automagically have it deploy to User Acceptance Testing( UAT) and even prod as well.
  • Seeing code in action right away - The moment code is committed to source control, it can be tested, deployed and provide immediate feedback.
  • Deploying code directly from GitHub repo - When using other CI/CD systems using a GitHub repo, GitHub has to send webhooks to other systems. Using Actions, everything remains within GitHub.
  • Automating deployments to environments at any time - Etsy and Netflix deploy their code 50+ times per day, for example.

Tutorial Overview

Enough about understanding what GitHub Actions can do. Let's see how you can use it in a hands-on tutorial! In the upcoming tutorial, you're going to see a real-world example of how to deploy code with GitHub Actions. Although there are a near-infinite number of use cases for GitHub Actions, we'll focus on a fairly standard use case for DevOps. You'll learn how to use the infrastructure-provisioning tool Terraform to deploy Azure resources.

In the tutorial, you will:

  • Create a resource group in Azure using Terraform
  • Create a YAML file for GitHub Actions and learn about Terraform-GitHub-Actions extension - This extension allows you to interact with Terraform via GitHub Actions.
  • Execute Terraform configuration and build Azure resources

To follow along with this tutorial, please head over to the original post at https://adamtheautomator.com/github-actions/ written by Michael Levan (https://clouddev.engineering).

Top comments (0)