witty-book-85526
10/05/2022, 7:22 PMgenerate an Infracost JSON file as the baseline
+
generate a diff by comparing the latest code change with the baseline
and the Infracost PR comments gets published as expected, however for some reason the infracost
estimate remains: unchanged
every time and it does not seem to update 📉 and 📈 emojis as changes are pushed ---
What I’ve checked so far:
[x] CircleCI Box: /tmp dir structure
.
├── base
├── circle-agent-runner.pid
├── circleci-1594698576
├── circleci-ts.sock
├── infracost.json
└── infracost-base.json
[x] ran cost estimate breakdown locally
infracost breakdown --path .
It produced all the cloud resources that got detected while on the PR it showed only the ones that got changed --- on local and on the PR the overall cost however matches as expected!
[?] as I have CircleCI orb [circleci/terraform@3.1.0] for terraform, did terraform show -json plan.out > infracost-base.json so I can persist it and attach it within the Infracost job but somehow got lost on the way and not sure if that is needed as Infracost job itself already produced the terraform plan ...
Any advise or direction on how to continue will be greatly appreciated!busy-agent-35515
10/05/2022, 7:27 PMwitty-book-85526
10/05/2022, 7:29 PM- 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
busy-agent-35515
10/05/2022, 7:30 PMwitty-book-85526
10/05/2022, 7:32 PM- 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
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 anywaybusy-agent-35515
10/05/2022, 7:36 PMTF_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#L62witty-book-85526
10/05/2022, 7:37 PMjobs:
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
busy-agent-35515
10/05/2022, 7:46 PMBASE_BRANCH
should be the branch you want to compare withTF_ROOT: /tmp/base
- TF_ROOT is the main path of your code from feature branch, in the example it is terraform
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 changesinfracost breakdown
commandwitty-book-85526
10/05/2022, 7:59 PMbusy-agent-35515
10/05/2022, 7:59 PMwitty-book-85526
10/05/2022, 8:00 PMbusy-agent-35515
10/05/2022, 8:04 PMwitty-book-85526
10/05/2022, 8:04 PMbusy-agent-35515
10/05/2022, 8:04 PMwitty-book-85526
10/05/2022, 8:06 PMbusy-agent-35515
10/05/2022, 8:07 PMwitty-book-85526
10/06/2022, 11:38 AM422 Validation Failed
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?busy-agent-35515
11/02/2022, 1:05 PMinfracost comment github
or doing a API request directly?crooked-daybreak-55253
11/02/2022, 1:06 PMbusy-agent-35515
11/02/2022, 1:07 PMcrooked-daybreak-55253
11/02/2022, 1:08 PMGitHubMaxMessageSize = 262144
hmmmbusy-agent-35515
11/02/2022, 1:09 PMwitty-book-85526
11/02/2022, 1:12 PMInfracost v0.10.13
infracost comment github
as part of the Post Infracost comment block for CircleCIbusy-agent-35515
11/02/2022, 1:20 PMwitty-book-85526
11/02/2022, 1:32 PMdocker:
- image: infracost/infracost:ci-0.10
busy-agent-35515
11/02/2022, 1:33 PMwitty-book-85526
11/02/2022, 1:33 PMbusy-agent-35515
11/02/2022, 1:34 PMwitty-book-85526
11/02/2022, 1:37 PMinfracost/infracost:ci-0.10
ci-0.10.13
ci-latest
and still getting the errorbusy-agent-35515
11/02/2022, 1:45 PMwitty-book-85526
11/02/2022, 2:02 PMbusy-agent-35515
11/02/2022, 2:03 PMwitty-book-85526
11/02/2022, 2:06 PMbusy-agent-35515
11/02/2022, 2:07 PMwitty-book-85526
11/15/2022, 1:12 PMTerraform 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 …
- attach_workspace:
at: /tmp
plan.json
file that got generated to the infracost and get the diff and output the calculated cost?busy-agent-35515
11/15/2022, 1:13 PMwitty-book-85526
11/15/2022, 1:14 PMbusy-agent-35515
11/15/2022, 1:15 PMinfracost breakdown --path=path/to/code --out-file=/tmp/infracost.json --format=json
infracost diff --path=path/to/code --compare-to=/tmp/infracost.json
path/to/code
can be a Terraform JSON file toowitty-book-85526
11/15/2022, 1:17 PMterraform
orb I am using
orbs:
terraform: i circleci/terraform@3.1.0
I have a CircleCI job called:
terraform-build-deploy:
I produce the plan.json with
terraform show -json plan.out > plan.json
busy-agent-35515
11/15/2022, 1:17 PMwitty-book-85526
11/15/2022, 1:18 PMpath=path/to/code
is where I tries to use the path to where the plan.json file
is sotredbusy-agent-35515
11/15/2022, 1:18 PMwitty-book-85526
11/15/2022, 1:18 PM/temp
busy-agent-35515
11/15/2022, 1:18 PMpath/plan.json
witty-book-85526
11/15/2022, 1:19 PMbusy-agent-35515
11/15/2022, 1:19 PM--path=
should point to the file, not just the directory where it is located./temp
), and Infracost job would be able to access this /temp
so the command would look like infracost breakdown --path=/temp/plan.json
witty-book-85526
11/15/2022, 1:24 PMworkspaces
to share date between jobsplan.json
from the terraform job in /temp
busy-agent-35515
11/15/2022, 1:25 PMattach_workspace
to access the filewitty-book-85526
11/15/2022, 1:26 PM/temp
and then use
- persist_to_workspace:
busy-agent-35515
11/15/2022, 1:27 PMwitty-book-85526
11/15/2022, 1:27 PM/temp/plan.json
busy-agent-35515
11/15/2022, 1:27 PMwitty-book-85526
11/15/2022, 1:46 PMpersist_to_workspace
won’t do it … it does not recognizr that there is such a dir/
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 itbusy-agent-35515
11/15/2022, 1:47 PMworking_directory: /tmp
witty-book-85526
11/15/2022, 1:52 PMworking_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 🙂busy-agent-35515
11/15/2022, 1:52 PMwitty-book-85526
11/16/2022, 2:34 PMplan.json
that I created! 🙂🎉
Do you know by any chance if I can pass two --path
within the
infracost diff --path ...
multiple
--- plan.json
files that I want to pass on and this is a bit tricky …---path
but it does not seem to be working …busy-agent-35515
11/16/2022, 2:37 PMwitty-book-85526
11/16/2022, 2:44 PMthis
is because I am expecting several tfstate
files which I want to merge into one eventually …busy-agent-35515
11/16/2022, 2:45 PMwitty-book-85526
11/16/2022, 2:46 PMlerna
project with multiple Cloudfront
distributuons and each Cf distro has .tf
files associated with .tf
modules + Lambda etc…tfstate
files for diff scenariosbusy-agent-35515
11/16/2022, 2:47 PMwitty-book-85526
11/16/2022, 2:48 PMbaseline
at all --- I am using the Terraform plan JSON
and then run just
infracost diff --path ./terraform/tfplan.json
tfplan.json
files which I somehow want to merge together into one filebusy-agent-35515
11/16/2022, 2:49 PMwitty-book-85526
11/16/2022, 2:49 PMbusy-agent-35515
11/16/2022, 2:50 PMinfracost breakdown
and provide several --path
diff
command is to have a baseline (for example, the master/main branch), and compare PR branches with the baselinewitty-book-85526
11/16/2022, 2:53 PMinfracost
breakdown allows to have multiple options --- will give it a try nowinfracost
breakdown and it ran fine as you described it!
However, now onto the Infracost
comment I hit another roadblock 😞
invalid Infracost JSON file version. Supported versions are 0.2 ≤ x ≤ 0.2
busy-agent-35515
11/16/2022, 3:34 PMinfracost breakdown --path path1 --path path2 --format json --out-file infracost.json
witty-book-85526
11/16/2022, 3:51 PMinfracost 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 expectedinfracost
comment
infracost comment github --path=./terraform/tfplan.json \
busy-agent-35515
11/16/2022, 3:52 PMinfracost.json
to avoid confusion with tfplan files that have completely different format 🙂witty-book-85526
11/16/2022, 3:53 PMbusy-agent-35515
11/16/2022, 3:53 PMwitty-book-85526
12/06/2022, 9:06 PM