hieven / terraform-visual

Terraform Visual is an interactive way of visualizing your Terraform plan
https://hieven.github.io/terraform-visual
MIT License
615 stars 53 forks source link

Include in the Readme an example of how to use it in CI/CD Github action #45

Open pcartas opened 1 year ago

pcartas commented 1 year ago

Hi! I been googleing how to show the html generated but i couldnt success ¿someone has an example of it used in a github action? I tried with this but doesnt work:

name: Pull Request Staging

on:
  pull_request:
    branches:
      - staging

jobs:
  Terraform:
    name: Terraform Plan
    runs-on: ubuntu-latest
    steps:

    - name: Checkout Repo
      uses: actions/checkout@v2

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

    - name: Terraform Init
      run: cd ./staging; terraform init
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        TF_ACTION_WORKING_DIR: './staging'
        AWS_ACCESS_KEY_ID:  ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY:  ${{ secrets.AWS_SECRET_ACCESS_KEY }}

    - name: Terraform Validate
      run: terraform validate

    - name: Terraform Plan
      run: cd ./staging; terraform plan -out=plan.out; terraform show -json plan.out > plan.json
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        TF_ACTION_WORKING_DIR: './staging'
        AWS_ACCESS_KEY_ID:  ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY:  ${{ secrets.AWS_SECRET_ACCESS_KEY }}

    - name: Terraform Visual Install
      run: cd staging; npm install -g @terraform-visual/cli

    - name: Generate the Report
      run: cd staging; terraform-visual --plan plan.json;

    - name: HTML preview
      id: html_preview
      uses: pavi2410/html-preview-action@v2
      with: 
        html_file: terraform-visual-report/index.html
ipc-zpg commented 1 year ago

When you say this isn't working - can you expand on that?

I have noticed that your html_file is likely pointing to the wrong place, as you're not in the 'staging' directory.