Improve Terraform Last Plan Output in GitHub Actions – DZone – Uplaza

Terraform is an Infrastructure as Code (IaC) device that permits the DevOps engineer to automate the availability and administration of infrastructure sources. It makes use of configuration information written in HashiCorp Config Language (HCL) to outline the specified state of the infrastructure and has varied instructions to configure and apply the infra sources. 

GitHub Actions is a steady integration and supply platform (CI/CD) that permits builders to automate construct, take a look at, and deployment pipelines. Through the deployment configuration, we have to outline a step: a step is a person motion that GitHub Actions performs. 

Present State

Whereas deploying an infrastructure useful resource by Terraform usually, the Terraform plan output exhibits all of the execution logs and shows the ultimate plan output eventually. If many infrastructure modifications are occurring on the identical time, all modifications will get dumped right into a single plan output, and the reviewer must scroll all the way down to see the ultimate output. It might result in distraction and the potential for lacking the ultimate plan output clearly, which ends up in destroying the sources accidentally after execution.  

Proposed Answer

On this article, I’ve given an easier answer to how you can overcome the above downside in an easier method. This may separate the Terraform output step into 3 steps.

Prerequisite

For this mock pipeline execution, I’ve used Google Cloud for the useful resource deployment. Earlier than the code execution, arrange the Google credentials as required (highlighted within the under code snippet).  

Step 1

Introduce a brand new step in GitHub actions to gather all Terraform stdout log output.

Step 2

This output must be saved right into a GitHub output variable.

Step 3

Use the output variable within the subsequent steps, filter the plan output log alone to show on this step execution log, and supply the textual content contents and background colour to achieve consideration through the pull request opinions. 

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version