This message was deleted.
# general
b
This message was deleted.
b
Hello! Can you share the comment command you're using?
w
sure! --- formatting does not seem well, though!
Copy code
- run:
          name: Post Infracost comment
          command: |
              # Extract the PR number from the PR URL
              PULL_REQUEST_NUMBER=${CIRCLE_PULL_REQUEST##*/}
              infracost comment github --path=/tmp/infracost.json \
                                       --repo=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME \
                                       --pull-request=$PULL_REQUEST_NUMBER \
                                       --github-token=$GITHUB_TOKEN \
                                       --behavior=update
πŸ‘€ 1
b
W/r/t the terraform plan creation: is there a reason you're generating a plan? Infracost parses HCL without TF binary, and it's much quicker, so if you don't need the plan for Infracost, you can skip it πŸ™‚
βœ… 1
The comment command looks okay, may I also ask how you're generating the diff? Do you follow our examples maybe?
w
sure! And yes followed the example as it is available from here: link
Copy code
- run:
          name: Generate Infracost cost estimate baseline
          command: |
              infracost diff --path=${TF_ROOT} \
                            --format=json \
                            --compare-to=/tmp/infracost-base.json \
                            --out-file=/tmp/infracost.json
πŸ‘ 1
My initial thought was I need to generate terraform plan from the
circleci orb
which I am using and use it so I can attach it to the infracost job --- then found out that is not needed as infracost does it already anyway
b
Ah, I think I see the problem in our docs: the idea is to generate the baseline against your main/master branch. So when you diff it with your feature branch, there, well, will be a diff πŸ˜„ It seems like the instructions have an error on this line: https://github.com/infracost/infracost-circleci/blob/master/README.md?plain=1#L80
βœ… 1
Instead of
TF_ROOT
it should be
/tmp/base
where we clone the main branch on line https://github.com/infracost/infracost-circleci/blob/master/README.md?plain=1#L62
βœ… 1
Could you try to change it and re-run?
w
sure! Will do it now! πŸ™‚
πŸ™Œ 1
Just to make sure, I got this right!
Copy code
jobs:
  infracost:
    docker:
      - image: infracost/infracost:ci-0.10
    environment:
      TF_ROOT: /tmp/base
      BASE_BRANCH: poc/setup-infracost
changed
TF_ROOT
to
/tmp/base
and for
BASE_BRANCH
I am still using the feat/ branch --- in this case
poc/setup-infracost
b
I think
BASE_BRANCH
should be the branch you want to compare with
It can be main/master or maybe another branch, but not the same as your feature branch, otherwise they will have identical TF code, right?
βœ… 1
Oh, one more thing, sorry, missed it
w
right! So in this case
master
---
b
Yeah, sorry, I'm slow πŸ˜„
πŸ˜ƒ 1
TF_ROOT: /tmp/base
- TF_ROOT is the main path of your code from feature branch, in the example it is
terraform
βœ… 1
Let me explain the flow πŸ™‚
πŸ™Œ 1
1. We clone your feature branch to
TF_ROOT
- it is our main place to run Infracost 2. We clone the master branch to
/tmp/base
- it is our baseline place 3. We run
infracost breakdown --path /tmp/base --out-file /tmp/infracost-base.json --format json
to generate the baseline Infracost data 4. Now we need to run
infracost diff --path TF_ROOT --compare-to /tmp/infracost-base.json
command (with other flags) - this way we compare baseline with your feature branch changes
πŸ™Œ 1
So in your case you would change only one line - the one with
infracost breakdown
command
Let me push the fix to our example, hopefully it would make sense visually πŸ™‚
πŸ’― 1
w
Explaining the whole flow has been very useful! Appreciate it very much! πŸ™
πŸ™Œ 1
b
Let's see if this works πŸ™‚
w
testing it now!
πŸš€ 1
It all went well! β€οΈπŸ™πŸ’― I want to thank you Vadim very much for assisting me and helping me understand where I was wrong!
b
Awesome! 🦜 Glad it worked! πŸ™‚
w
I’ve spent quite a lot of time trying to figure it out and couldn’t so that has been amazing! πŸ™‚
b
To be fair, it's our example had an error, so you were not wrong πŸ˜„
πŸ˜€ 1
Sorry about that πŸ˜„
Thank you for your patience! We fixed the issue, hopefully other CircleCI users will have a smoother experience πŸ™‚
πŸ’― 1
βœ… 1
w
All good! I guess you hear that a lot of time, but you guys are making a difference and this tools brings a lot of value! πŸ™‚ If there is anything I can help out with or contribute with my humble experience I will be more than happy to take on anything you got on your backlog!
b
Oh, thank you for the kind words! This means a lot to us infraheart
πŸ™ 1
If you're willing to contribute, we have some issues that are good to get familiar with the Infracost code: https://github.com/infracost/infracost/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22.
βœ… 1
Look around and if you find anything you like, just leave a comment that you'd like to work on it, and we'll gladly assign you πŸ™‚
βœ… 1
Thank you for using Infracost and for your interest! πŸ™‚
πŸ™Œ 1
Please forgive me for a shameless plug: we are also working on our SaaS with the goal to help your team and organization to tackle the cloud costs even better than CLI alone. https://dashboard.infracost.io/
βœ… 1
w
will sure check it out!
πŸ™Œ 1
Hey @busy-agent-35515 have been using Infracost for sometime now and it works great. There is something that I noticed when you try to POST Infracost on Github - I get following
422 Validation Failed
Copy code
422 Validation Failed [{Resource:IssueComment Field:data Code:unprocessable Message:Body is too long (maximum is 65536 characters)}]
It seems the Terraform plan output is too big to display --- any idea how I can navigate this?
b
Hey! Glad to hear you have a nice experience! πŸ™‚ How do you do that? Using
infracost comment github
or doing a API request directly?
c
And which infracost CLI version are you using? This was supposed to be fixed in v0.10.10
πŸ‘ 1
b
Yep, that was my next question. Thanks Tim! πŸ˜„
c
Although looking at that PR we use
GitHubMaxMessageSize = 262144
hmmm
b
Yeah, it doesn't translate number of characters == the number of bytes
πŸ™‡ 1
Ah, I left a comment about that, in the commit message though, not in code: https://github.com/orgs/community/discussions/27190#discussioncomment-3254953
w
I am currently using
Infracost v0.10.13
πŸ‘ 1
for the Infracost CLI version
just to follow up on Vadim’s comment - I am using
infracost comment github
as part of the Post Infracost comment block for CircleCI
b
Hm, interesting πŸ€” As Tim mentioned, we fixed this issue and your CLI version should be okay. Let me try to replicate that
πŸ‘ 1
w
could it be that I am still using this docker image
Copy code
docker:
      - image: infracost/infracost:ci-0.10
I mean, if a new img is released with an updated tag
b
Yeah, this image should have the latest 0.10.x version
Can you try to pull it just in case?
w
sure, will try it now
πŸ™Œ 1
w
just pulled it
infracost/infracost:ci-0.10
I’ve tried with following versions of the docker img
Copy code
ci-0.10.13
ci-latest
and still getting the error
b
I'm still trying to go over the limit. You need a bunch of resources for that πŸ˜…
πŸ₯² 1
Okay, got the error now
Hm, okay, seems like the message size is still off, although the truncation works πŸ€”
We're going to fix that and it should be out with the next release, but until then, you might be blocked 😞
πŸ‘ 1
w
all good, Vadim! That will not stop me from using Infracost as my team has seen immense value up until now β€” will be around and wait for the new release πŸ™‚
πŸ™Œ 1
any idea, when is it expected?
b
Not sure, maybe next week
πŸ‘ 1
By the way, have you tried our new GitHub App integration?
With it you don't need CircleCI integration, however, it's part of Infracost Cloud plan
w
I haven’t, I would have given it a try, it’s not RFC compliant though that is why I am stuck with CircleCI --- I mean within the company that I work at
b
Oh, I see
w
Hey @busy-agent-35515 it’s me again, apologies for bothering! Here is what I am trying to do: I have a CircleCI workflow, which has a terraform orb and I’ve managed to generate the
Terraform plan JSON
and it produced the file
plan.json
which now I am trying to pass over to the Infracost job --- however I cannot attach it to workspace, because that’s already taken for the base branch … also I cannot pass it over to
TF_ROOT: terraform/plan.json
’cause it won’t find it …
Copy code
- attach_workspace:
          at: /tmp
any ideas how can I pass the
plan.json
file that got generated to the infracost and get the diff and output the calculated cost?
b
Hey! No worries πŸ™‚
πŸ™ 1
Can you show me the commands you're using?
w
sure
b
Usually we do something like
infracost breakdown --path=path/to/code --out-file=/tmp/infracost.json --format=json
So it will save the Infracost JSON to /tmp/
Then we use
infracost diff --path=path/to/code --compare-to=/tmp/infracost.json
The
path/to/code
can be a Terraform JSON file too
w
this is the
terraform
orb I am using
Copy code
orbs:
  terraform: i circleci/terraform@3.1.0
I have a CircleCI job called:
terraform-build-deploy:
I produce the plan.json with
Copy code
terraform show -json plan.out > plan.json
b
Ah, okay
w
oh, I see the
path=path/to/code
is where I tries to use the path to where the
plan.json file
is sotred
but it won’t find it
b
It should be the explicit file in this case
w
as it attaches the workspace to
/temp
b
path/plan.json
w
explicit file, you mean the one generated by Infracost ,right?
b
Sorry, I'll rephrase: when using TF JSON files, the
--path=
should point to the file, not just the directory where it is located.
πŸ‘ 1
I'm not very familiar with CircleCI, is it possible to share the generated plan with other orbs?
πŸ‘€ 1
My understanding is that the terraform orb generates the plan and stores it somewhere (like
/temp
), and Infracost job would be able to access this
/temp
so the command would look like
infracost breakdown --path=/temp/plan.json
w
good question! not sure --- I am familar with using only
workspaces
to share date between jobs
so if I generate the
plan.json
from the terraform job in
/temp
Infracost sohuld be able to find it
right
theortically
b
From this https://circleci.com/docs/workspaces/ looks like that the Infracost jobs need to have something like
attach_workspace
to access the file
πŸ‘ 1
w
will generate the file in
/temp
and then use
Copy code
- persist_to_workspace:
b
Yep, looks like it's required
w
to store it in
/temp/plan.json
and see if Infracost will find it
give me a min and will try it
πŸ‘ 1
b
Hope this works πŸ™‚
w
ah, the
persist_to_workspace
won’t do it … it does not recognizr that there is such a dir/
Copy code
The specified paths did not match any files in /tmp
Here is what I am thinking of --- having another
mid
job which carries the output from the
plan.json
and then attaching the workspace to
/tmp
where Infracost is looking for it
it ain’t very smart, but cannot think of anything else 😞
b
Sorry, I haven't used CircleCI, so can't be much help here πŸ₯²
But first step is making it working, then refactor πŸ™‚
The example in the docs also shows that "executor" should have the working directory set as
Copy code
working_directory: /tmp
w
oh, that is a good point! Will add the
working_directory
and try it out again! Please don’t feel bad, I am very much
greateful
for you taking the time and looking into it as I was stuck and making no progress and ran out of ideas --- hope I am not bothering you and asking always stuff πŸ™‚
b
No worries! We want to make our users happy πŸ™‚
❀️ 1
w
@busy-agent-35515 managed to get it working with the
plan.json
that I created! πŸ™‚πŸŽ‰ Do you know by any chance if I can pass two
--path
within the
Copy code
infracost diff --path ...
πŸŽ‰ 1
as I have
multiple
---
plan.json
files that I want to pass on and this is a bit tricky …
I’ve tried adding second
---path
but it does not seem to be working …
b
Good job!
The diff command expects only one path and one compare-to. So if you have multiples, I guess you'll have to run the diff command N times
πŸ‘ 1
But then the comment/upload commands accept multiple paths to merge all diff info together
βœ”οΈ 1
w
Alright! Will give it a try to have the infracost diff replicated and then if the infracost comment supports multiple paths should do the trick! πŸ˜‰
The reason why I am doing
this
is because I am expecting several
tfstate
files which I want to merge into one eventually …
b
Are these different projects/repos?
w
It is a
lerna
project with multiple
Cloudfront
distributuons and each Cf distro has
.tf
files associated with
.tf
modules + Lambda etc…
and once setup, it will produce diff
tfstate
files for diff scenarios
b
I wonder what is the baseline then?
w
good question! I am avoiding it, I mean I don’t setup
baseline
at all --- I am using the
Terraform plan JSON
and then run just
Copy code
infracost diff --path ./terraform/tfplan.json
and I am expecting multiple
tfplan.json
files which I somehow want to merge together into one file
b
So diff will always show $0 -> $XXX change, right?
w
tbh don’t know yet, I guess you are right! πŸ™‚
b
Okay, then in this case you don't need the diff command at all
You can just use
infracost breakdown
and provide several
--path
πŸ‘ 1
It will produce the infracost JSON that you can use with the comment command
βœ”οΈ 1
The point of the
diff
command is to have a baseline (for example, the master/main branch), and compare PR branches with the baseline
If you don't have baseline (aka previous state), then the diff will produce the identical output as breakdown
βœ… 1
Sorry I misunderstood your setup
w
No, all good! This is a really good point though! πŸ™‚ Using the
infracost
breakdown allows to have multiple options --- will give it a try now
πŸ‘ 1
tried the
infracost
breakdown and it ran fine as you described it! However, now onto the
Infracost
comment I hit another roadblock 😞
Copy code
invalid Infracost JSON file version. Supported versions are 0.2 ≀ x ≀ 0.2
b
The comment command expects Infracost JSON file, the one you generate via
infracost breakdown --path path1 --path path2 --format json --out-file infracost.json
πŸ‘ 1
w
Thanks @busy-agent-35515 this is how I fixed it
Copy code
infracost breakdown --path=./terraform \
                                  --format=json \
                                  --out-file=./terraform/tfplan.json
had to pass first the
./terraform
dir and then to
--out-file
I just pointed to the
tfplan.json
file which was expected
then within the
infracost
comment
Copy code
infracost comment github --path=./terraform/tfplan.json \
b
Awesome πŸ™‚ We deliberately call the output file as
infracost.json
to avoid confusion with tfplan files that have completely different format πŸ™‚
πŸ‘ 1
w
Appreciate the help and sticking through all the Qs! πŸ™
b
Of course πŸ™‚
❀️ 1
@witty-book-85526 Hello! Sorry it's been a month, but we finally released a new CLI version that fixes the long GitHub comments. Hope it'll still be useful for you.
❀️ 1
w
Hey @busy-agent-35515 that’s brilliant! πŸŽ‰ πŸ™ πŸ’― It will surely come in very handy!
πŸ™Œ 1
116 Views