broad-zoo-34077
12/14/2021, 9:13 AMlittle-author-61621
--path=/path/to/tf.plan this should work. Is the issue that you want to do this for multiple plan files at the same time?plain-ocean-92335
12/14/2021, 9:19 AMlittle-author-61621
plain-ocean-92335
12/14/2021, 9:20 AMplain-ocean-92335
12/14/2021, 9:22 AMstocky-salesmen-15167
12/14/2021, 9:23 AMterraform.tfplan ?
Which would mean you would need to create a config file like here https://www.infracost.io/docs/multi_project/config_file/, right?plain-ocean-92335
12/14/2021, 9:24 AMstocky-salesmen-15167
12/14/2021, 9:25 AMplain-ocean-92335
12/14/2021, 9:26 AMterragrunt run-all plan step which infracost breakdown  action does, since I already have one presentlittle-author-61621
infracost breakdown for each of them, and then combine them using infracost output.little-author-61621
plain-ocean-92335
12/14/2021, 9:32 AMname: Terraform Validate dev
on:
  pull_request:
    paths:
      - ".terra*-version"
      - "terraform/**"
      - ".github/workflows/*-dev.yml"
      - "scoma/**"
    branches:
      - develop
defaults:
  run:
    shell: bash
env:
  AWS_REGION: "eu-central-1"
  ACCOUNT: scoma-dev
  CONFIG_PATH: terraform/scoma
  AWS_ROLE_TO_ASSUME: ${{ secrets.AWS_ROLE_TERRAFORM_DEV }}
  XRAY_ENABLED: ${{ github.event.inputs.x-ray }}
  TERRAGRUNT_PARALLELISM: 4 # limit CPU usage
jobs:
  terraform-validate:
    name: TF code in scoma-dev
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Set variables
        run: |
          TF_VER=$(cat .terraform-version)
          TG_VER=$(cat .terragrunt-version)
          echo "TERRAFORM_VERSION=$TF_VER" >> $GITHUB_ENV
          echo "TERRAGRUNT_VERSION=$TG_VER" >> $GITHUB_ENV
      # Setup terraform
      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1.3.2
        with:
          terraform_version: ${{ env.TERRAFORM_VERSION }}
          terraform_wrapper: false
      - name: Terragrunt Binary Installer Action
        uses: autero1/action-terragrunt@v1.0.1
        with:
          terragrunt_version: ${{ env.TERRAGRUNT_VERSION }}
      - name: Config Terraform plugin cache
        run: |
          TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"
          echo "TF_PLUGIN_CACHE_DIR=$TF_PLUGIN_CACHE_DIR" >> $GITHUB_ENV
          mkdir --parents $TF_PLUGIN_CACHE_DIR
          TERRAGRUNT_DOWNLOAD="$HOME/.terragrunt-cache/${{ env.ACCOUNT }}/$(date +%F)"
          echo "TERRAGRUNT_DOWNLOAD=$TERRAGRUNT_DOWNLOAD" >> $GITHUB_ENV
          mkdir --parents $TERRAGRUNT_DOWNLOAD
      - name: Cache Terraform
        uses: actions/cache@v2
        with:
          path: |
            ~/.terraform.d/plugin-cache
          key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
      - name: Cache Terragrunt
        uses: actions/cache@v2
        with:
          path: |
            ~/.terragrunt-cache/
          key: ${{ runner.os }}-${{ env.TERRAGRUNT_DOWNLOAD }}-${{ hashFiles('**/project.hcl', '**/.terraform.lock.hcl') }}
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ env.AWS_REGION }}
          role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
          role-duration-seconds: 1800
          role-session-name: scoma-${{ github.run_id }}
      - name: Plan and validate for ${{ env.ACCOUNT }}
        run: |
          scripts/terragrunt/init_terraform_plugins.sh
          source scripts/terragrunt/ssh-agent.source
          scripts/terragrunt/run_terragrunt run-all validate
          scripts/terragrunt/run_terragrunt run-all plan -out terraform.tfplan
        env:
          SSH_PRIVATE_KEY: ${{ secrets.GIT_SSH_PRIVATE_KEY }}
      - name: Setup Infracost
        uses: infracost/actions/setup@v1
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}
      - name: Run Infracost
        run: infracost breakdown --path=${{ env.CONFIG_PATH}} --format=json --out-file=/tmp/infracost.json
      - name: Post Infracost comment
        uses: infracost/actions/comment@v1
        with:
          path: /tmp/infracost.json
          behavior: update # Create a single comment and update it.stocky-salesmen-15167
12/14/2021, 9:35 AM#!/usr/bin/env bash
cfgfile="/tmp/infracost.yml"
# write the infracost config file header
echo -e "version: 0.1\n\nprojects:\n" > $cfgfile
# Loop through plans and create Infracost config file
planfiles=($(find . -name "terraform.tfplan" | tr '\n' ' '))
for planfile in "${planfiles[@]}"; do
  echo "Adding $planfile to infracost config";
  echo "  - path: $planfile" >> $cfgfile
done
# export config file name to Github env
# use it in the next step as env.infracost_configfile
echo "infracost_configfile=$cfgfile" >> $GITHUB_ENV
You can then call infracost with ${{env.infracost_configfile}} as path to the config file.plain-ocean-92335
12/14/2021, 9:38 AMstocky-salesmen-15167
12/14/2021, 9:39 AMplain-ocean-92335
12/14/2021, 9:41 AMlittle-author-61621
--path parameter could accept some sort of glob pattern or somethinglittle-author-61621
plain-ocean-92335
12/14/2021, 12:02 PMlittle-author-61621