broad-zoo-34077
06/13/2021, 8:34 PMlittle-author-61621
No such file or directory shows if we can't find the path and Could not detect path type shows if the path exists but we don't recognise the type. What type of path are you passing?hallowed-caravan-40528
06/13/2021, 8:41 PMhallowed-caravan-40528
06/13/2021, 8:42 PMinfracost breakdown --path ./terraform
pointing to the folder does indeed workslittle-author-61621
terraform show -json? For statefiles we check for the following keys: format_version and values in the JSON.hallowed-caravan-40528
06/13/2021, 8:48 PMlittle-author-61621
cd /path/to/tf
terraform show -json > state.jsonhallowed-caravan-40528
06/13/2021, 8:59 PMhallowed-caravan-40528
06/13/2021, 8:59 PMhallowed-caravan-40528
06/13/2021, 8:59 PMlittle-author-61621
hallowed-caravan-40528
06/13/2021, 9:02 PMinfracost output --path /tmp/state/*.jsonhallowed-caravan-40528
06/13/2021, 9:03 PMgit checkout , terraform plan and terraform output -json every branch, and then generate the uniform report. Any better idea?little-author-61621
hallowed-caravan-40528
06/13/2021, 9:06 PMhallowed-caravan-40528
06/13/2021, 9:06 PMcurl --header 'Authorization:Bearer ${CI_JOB_TOKEN}' '<https://gitlab.com/api/v4/projects/xx/terraform/state/global>' -o /tmp/state/global.json
global is my branch/state namelittle-author-61621
# Generate branch1 state JSON
mkdir -p /tmp/state/branch1
touch /tmp/state/branch1/main.tf
curl --header 'Authorization:Bearer ${CI_JOB_TOKEN}' '<https://gitlab.com/api/v4/projects/xx/terraform/state/branch1>' -o /tmp/state/branch1/state.json
terraform -chdir=/tmp/state/branch1/ init
terraform -chdir=/tmp/state/branch1/ show -json > /tmp/state/branch1.json
# Generate branch2 state JSON
mkdir -p /tmp/state/branch2
touch /tmp/state/branch2/main.tf
curl --header 'Authorization:Bearer ${CI_JOB_TOKEN}' '<https://gitlab.com/api/v4/projects/xx/terraform/state/branch12> -o /tmp/state/branch2/state.json
terraform -chdir=/tmp/state/branch2/ init
terraform -chdir=/tmp/state/branch2/ show -json > /tmp/state/branch2.json
# Run infracost
infracost breakdown --path=/tmp/state/*.jsonlittle-author-61621
hallowed-caravan-40528
06/13/2021, 9:22 PMlittle-author-61621
hallowed-caravan-40528
06/13/2021, 9:25 PMhallowed-caravan-40528
06/14/2021, 1:18 AMscript:
- mkdir -p /tmp/state
- mkdir -p /tmp/json
- mkdir -p /tmp/breakdown
- cd /tmp/state
- |
cat > <http://main.tf|main.tf> << EOF
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.38"
}
}
backend "http" {
}
}
EOF
- gitlab-terraform init
- gitlab-terraform state pull > /tmp/state/global.json
- gitlab-terraform show -json /tmp/state/global.json > /tmp/json/global.json
- infracost breakdown --path /tmp/json/global.json --format json > /tmp/breakdown/global.json
- infracost output --path /tmp/breakdown/*.json --format json > /tmp/report.json
- INFRACOST_LOG_LEVEL=info infracost output --path /tmp/breakdown/*.json --format tablelittle-author-61621
hallowed-caravan-40528
06/14/2021, 1:33 PM