Gabriel
06/13/2021, 8:34 PMinfracost breakdown --path
is returning the above for me:
No such file or directory
Alistair (Infracost)
06/13/2021, 8:38 PMNo 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?Gabriel
06/13/2021, 8:41 PMinfracost breakdown --path ./terraform
pointing to the folder does indeed worksAlistair (Infracost)
06/13/2021, 8:45 PMterraform show -json
? For statefiles we check for the following keys: format_version
and values
in the JSON.Gabriel
06/13/2021, 8:48 PMAlistair (Infracost)
06/13/2021, 8:57 PMcd /path/to/tf
terraform show -json > state.json
Gabriel
06/13/2021, 8:59 PMAlistair (Infracost)
06/13/2021, 9:00 PMGabriel
06/13/2021, 9:02 PMinfracost output --path /tmp/state/*.json
git checkout
, terraform plan
and terraform output -json
every branch, and then generate the uniform report. Any better idea?Alistair (Infracost)
06/13/2021, 9:05 PMGabriel
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 nameAlistair (Infracost)
06/13/2021, 9:19 PM# 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/*.json
Gabriel
06/13/2021, 9:22 PMAlistair (Infracost)
06/13/2021, 9:25 PMGabriel
06/13/2021, 9:25 PMscript:
- 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 table
Alistair (Infracost)
06/14/2021, 8:06 AMGabriel
06/14/2021, 1:33 PM