famous-eve-48967
08/17/2023, 3:20 PMinfracost diff --path=. --format=json --compare-to=infracost-base.json --out-file=infracost.json
where infracost-base.json
is from production/base
branch and infracost.json
is from the current
branch to be merged to production
branch.+ export 'INFRACOST_API_KEY=****'
+ infracost diff '--path=.' '--format=json' '--compare-to=infracost-base.json' '--out-file=infracost.json'
time="2023-08-17T15:06:39Z" level=info msg="Enabled tag policies"
time="2023-08-17T15:06:40Z" level=info msg="Evaluating Terraform directory at ."
Detected Terraform project at .
Detected Terraform project at .
time="2023-08-17T15:06:40Z" level=info msg="Starting: Downloading Terraform modules"
time="2023-08-17T15:06:40Z" level=info msg="Starting: Downloading Terraform modules"
time="2023-08-17T15:06:40Z" level=info msg="Starting: Retrieving cloud prices to calculate costs"
Error: Invalid --compare-to Infracost JSON, found duplicate project name org/repo
little-author-61621
infracost-base.json
are there any projects that have the same name?famous-eve-48967
08/17/2023, 3:27 PMgroovy
code/stages for more context
stage(name: "infracost-base.json - production") {
sh """
export INFRACOST_API_KEY=${JENKINS_INFRACOST_API_KEY}
rm -rf /tmp/base/
git clone https://${GITHUB_TOKEN}@github.com/org/${githubRepo}.git --branch='master' --single-branch /tmp/base
infracost breakdown --path /tmp/base --format json \
--out-file /tmp/infracost-base.json
"""
}
stage(name: "Infracost - Compare Costs"){
sh """
export INFRACOST_API_KEY=${JENKINS_INFRACOST_API_KEY}
infracost diff --path=. --format=json \
--compare-to=infracost-base.json \
--out-file=infracost.json
"""
}
stage(name: "Infracost - Push Costs (PR)"){
sh """
infracost comment github --path=infracost.json \
--repo="org/${githubRepo}" \
--pull-request="${githubPullRequestNumber}" \
--github-token="${GITHUB_TOKEN}" \
--behavior=update
"""
sh 'rm -rf /tmp/infracost*'
}
Hi @famous-eve-48967. In the@little-author-61621, it's the same projectare there any projects that have the same name?infracost-base.json
little-author-61621
infracost-base.json
file? The issue might be because for some reason there’s identical projects in there.famous-eve-48967
08/17/2023, 3:29 PM{"version":"0.2","metadata":{"infracostCommand":"breakdown","vcsBranch":"master","vcsCommitSha":"begt3","vcsCommitAuthorName":"user","vcsCommitAuthorEmail":"<mailto:1313+user@users.noreply.github.com|1313+user@users.noreply.github.com>","vcsCommitTimestamp":"2023-08-17T14:22:20Z","vcsCommitMessage":"commit msg"vcsRepositoryUrl":"<https://github.com/org/repo.git>"},"currency":"USD","projects":[{"name":"org/repo","metadata":{"path":"/tmp/base","type":"terraform_dir","errors":[{"code":5,"message":"Failed to download remote module \"secor-service-account\" - could not download module git@github.com:org/terraform?ref=0636270 to cache error downloading '<ssh://git@github.com/org/terraform?ref=231343>': /usr/bin/git exited with 128: Cloning into '/tmp/base/.infracost/terraform_modules/9287349'…\nNo user exists for uid 1022\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n","data":{"source":"ssh"}}]},"pastBreakdown":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"breakdown":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"diff":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"summary":{"totalDetectedResources":0,"totalSupportedResources":0,"totalUnsupportedResources":0,"totalUsageBasedResources":0,"totalNoPriceResources":0,"unsupportedResourceCounts":{},"noPriceResourceCounts":{}}},{"name":"org/repo","metadata":{"path":"/tmp/base","type":"terraform_dir","errors":[{"code":2,"message":"Error loading Terraform modules: could not load modules for path /tmp/base failed to inspect module path /tmp/base/.infracost/terraform_modules/1313/modules/service-accounts diag: Failed to read module directory: Module directory /tmp/base/.infracost/terraform_modules/13313/modules/service-accounts does not exist or cannot be read.","data":null}]},"pastBreakdown":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"breakdown":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"diff":{"resources":[],"totalHourlyCost":"0","totalMonthlyCost":"0"},"summary":{"totalDetectedResources":0,"totalSupportedResources":0,"totalUnsupportedResources":0,"totalUsageBasedResources":0,"totalNoPriceResources":0,"unsupportedResourceCounts":{},"noPriceResourceCounts":{}}}],"totalHourlyCost":"0","totalMonthlyCost":"0","pastTotalHourlyCost":"0","pastTotalMonthlyCost":"0","diffTotalHourlyCost":"0","diffTotalMonthlyCost":"0","timeGenerated":"2023-08-17T15:06:35.818194102Z","summary":{"totalDetectedResources":0,"totalSupportedResources":0,"totalUnsupportedResources":0,"totalUsageBasedResources":0,"totalNoPriceResources":0,"unsupportedResourceCounts":{},"noPriceResourceCounts":{}}}
little-author-61621
"name": "org/repo",
values in that file.famous-eve-48967
08/17/2023, 3:46 PMinfracost breakdown ..
cmd ??little-author-61621
famous-eve-48967
08/17/2023, 3:48 PMtree | grep tfvar
├── ter.auto.tfvars
├── terraform.tfvars
little-author-61621
infracost.yml
config file to specify the projects manually.
version: 0.1
projects:
- path: org/repo
name: org-repo
terraform_var_files:
- ter.auto.tfvars
- terraform.tfvars
And then run infracost
against that config file:
infracost breakdown --config-file=infracost.yml --format json --out-file /tmp/infracost-base.json
...
infracost diff --config-file=infracost.yml --format=json --compare-to=infracost-base.json --out-file=infracost.json
famous-eve-48967
08/17/2023, 3:55 PMlittle-author-61621
famous-eve-48967
08/17/2023, 3:58 PMstage(name: "infracost-base.json - production") {
sh """
export INFRACOST_API_KEY=${JENKINS_INFRACOST_API_KEY}
git checkout master
infracost breakdown --config-file /tmp/base/infracost.yaml --format json \
--out-file /tmp/base/infracost-base.json
"""
}
stage(name: "Infracost - Compare Costs"){
sh """
export INFRACOST_API_KEY=${JENKINS_INFRACOST_API_KEY}
git checkout ${env.BRANCH_NAME}
infracost diff --config-file=/tmp/base/infracost.yaml --format=json \
--compare-to=/tmp/base/infracost-base.json \
--out-file=/tmp/base/infracost.json
"""
}
stage(name: "Infracost - Push Costs (PR)"){
sh """
infracost comment github --path=/tmp/base/infracost.json \
--repo="TAKEALOT/${githubRepo}" \
--pull-request="${githubPullRequestNumber}" \
--github-token="${GITHUB_TOKEN}" \
--behavior=update
"""
}