GitHub Action

AsCode Github Action allows to execute AsCode run command in response to a GitHub event such as updating a pull request or pushing a new commit to a specific branch.

This used in combination with the Terraform GitHub Actions allows to execute the different terraform commands init, plan and apply inside of a GitHub Workflow.

Parameters

ParameterMandatory/OptionalDescription
fileMandatoryStarlark file to execute. Default value: main.star
hclMandatoryHCL output file. Default value: generated.tf
name: 'Terraform & AsCode'
on:
  push:
    branches:
      - master
  pull_request:

jobs:
  terraform:
    name: 'Deploy'
    runs-on: ubuntu-latest
    env:
        TF_VERSION: latest
        TF_WORKING_DIR: .
    steps:
      - name: 'Checkout'
        uses: actions/checkout@master

      - name: 'AsCode Run'
        uses: mcuadros/ascode@gh-action

      - name: 'Terraform Init'
        uses: hashicorp/terraform-github-actions@master
        with:
          tf_actions_version: ${{ env.TF_VERSION }}
          tf_actions_subcommand: 'init'
          tf_actions_working_dir: ${{ env.TF_WORKING_DIR }}
          tf_actions_comment: true

      - name: 'Terraform Validate'
        uses: hashicorp/terraform-github-actions@master
        with:
          tf_actions_version: ${{ env.TF_VERSION }}
          tf_actions_subcommand: 'validate'
          tf_actions_working_dir: ${{ env.TF_WORKING_DIR }}
          tf_actions_comment: true

      - name: 'Terraform Plan'
        uses: hashicorp/terraform-github-actions@master
        with:
          tf_actions_version: ${{ env.TF_VERSION }}
          tf_actions_subcommand: 'plan'
          tf_actions_working_dir: ${{ env.TF_WORKING_DIR }}
          tf_actions_comment: true

      - name: 'Terraform Apply'
        uses: hashicorp/terraform-github-actions@master
        if: github.event_name == 'push'
        with:
          tf_actions_version: ${{ env.TF_VERSION }}
          tf_actions_subcommand: 'apply'
          tf_actions_working_dir: ${{ env.TF_WORKING_DIR }}