Gabriel
infracost breakdown --path
is returning the above for me:No such file or directory
Alistair (Infracost)
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?Gabriel
infracost breakdown --path ./terraform
pointing to the folder does indeed worksAlistair (Infracost)
terraform show -json
? For statefiles we check for the following keys: format_version
and values
in the JSON.Gabriel
Alistair (Infracost)
cd /path/to/tf
terraform show -json > state.json
Gabriel
Alistair (Infracost)
Gabriel
infracost 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)
Gabriel
curl --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)
# 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
Alistair (Infracost)
Gabriel
script:
- 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)