Home > database >  Why do my Terraform steps in Git Actions work even without installing Terraform CLI in the workflow
Why do my Terraform steps in Git Actions work even without installing Terraform CLI in the workflow

Time:07-06

I have been playing around with Git Actions and terraform, and I noticed that my Workflows don't fail if I remove the

- uses: hashicorp/setup-terraform@v2

So basically all of my terraform commands still succeed (see below for the workflow code) but without me ever installing the terraform CLI during the workflow. Why is this, and why do people even use the - uses: hashicorp/setup-terraform@v2 step then if I can still run all of the commands without it?

name: "terraform init"

on:
  push:
    branches:
      - dev

defaults:
  run:
    working-directory: app1/sub

jobs:
  Terraform:
    name: Terraform Job
    runs-on: ubuntu-latest
    steps: 
      - name: Clone repo
        uses: actions/checkout@v3

     # - name: Setup Terraform
     #   id: terraform-setup
     #   uses: hashicorp/setup-terraform@v1

      - name: Terraform Init
        id: init
        run: terraform init
 
      - name : terra validate
        id: val
        run: terraform validate

      - id: plan
        run: terraform plan -no-color

      - run: echo ${{ steps.plan.outputs.stdout }}
      - run: echo ${{ steps.plan.outputs.stderr }}
      - run: echo ${{ steps.plan.outputs.exitcode }}

CodePudding user response:

Github hosted runners come with pre-installed tools and packages amongst which Terraform is included as well.

Since you are running on ubuntu-latest, it comes with Terraform 1.2.3 installed.

The reason people use hashicorp/setup-terraform@v1 is to specify the version of Terraform they want to be installed on the runner.

steps:
- uses: hashicorp/setup-terraform@v2
  with:
    terraform_version: 1.1.7

For more information

  • Related