Git Product home page Git Product logo

Comments (5)

aliscott avatar aliscott commented on August 23, 2024 1

Thanks @kaykhan, yeah this seems like something that could be accounted for in the Infracost CLI itself. We don't have a solution for that just now, but it's something we should probably consider.

from actions.

aliscott avatar aliscott commented on August 23, 2024

@kaykhan thanks for reporting. In the pipeline what are you passing in as inputs.TF_ROOT?

from actions.

kaykhan avatar kaykhan commented on August 23, 2024

@kaykhan thanks for reporting. In the pipeline what are you passing in as inputs.TF_ROOT?

To be clear terraform-ci.yaml is a reusable workflow (updated original post to show that). This reusable workflow is triggered via the below workflow.

TF_ROOT is applications/prod/msk

msk-prod-tf-ci.yaml

name: msk-prod-tf-ci

on:
  pull_request:
    paths: ['applications/prod/msk/**']
    
concurrency:
  group: terraform

jobs:
  ci:
    uses: ./.github/workflows/terraform-ci.yaml
    with: 
      TF_ROOT: applications/prod/msk
      TF_APP_NAME: msk-prod
    secrets: inherit

from actions.

aliscott avatar aliscott commented on August 23, 2024

Thanks @kaykhan. My initial thoughts are since you are passing in applications/prod/msk as the path to Infracost, then when it runs against the base branch it is actually erroring, instead of producing an empty output since that dir doesn't exist in that branch. Since the base branch is erroring for that project then the diff command will fail as well for that project.

One way to resolve this would be to use an Infracost config file to dynamically find the project directories that exist on each given branch.

Something like this infracost.yml.tmpl might work for your case:

version: 0.1
projects:
{{- range $project := matchPaths "applications/:env/:name" }}
    - path: {{ $project._path }}
      name: {{ $project.env }}/{{ $project.name }}
{{- end }}

And then updating your pipeline to generate the config.

For the base run:

infracost generate config --repo-path=. \
    --template-path=infracost.yml.tmpl \
    --out-file=infracost.yml
infracost breakdown --config-file=infracost.yml \
    --format=json \
    --out-file=/tmp/infracost-base.json

For the diff run:

infracost generate config --repo-path=. \
    --template-path=infracost.yml.tmpl \
    --out-file=infracost.yml
infracost diff --config-file=infracost.yml \
    --format=json \
    --compare-to=/tmp/infracost-base.json \
    --out-file=/tmp/infracost.json

Another option that might be simpler to test initially is just to ensure the directory exists when you run the base branch, i.e.:

mkdir -p ${{ inputs.TF_ROOT }}
infracost breakdown --path=${{ inputs.TF_ROOT }} \
    --format=json \
    --out-file=/tmp/infracost-base.json

from actions.

kaykhan avatar kaykhan commented on August 23, 2024

Alright i'll have to try the infracost config file another time.

Another option that might be simpler to test initially is just to ensure the directory exists when you run the base branch, i.e.:

Tested this just now and of course there is an additional error. No valid Terraform files found at path applications/prod/msk (main branch is emtpy)


What i am thinking of doing is checking for the presence of the folder inputs.TF_ROOT in an initial step.

  - name: Check baseline exists
    run: |

Based on the result of that step i can either continue to run the baseline + diff or just run the breakdown directly.

Maybe i was hoping for an extra flag that could be added to infracost diff (ignore any errors that are in infracost-base.json and run the breakdown) to do this but i dont know if this would introduce some unforeseen conflicts.

from actions.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.