Cost Estimation
Template Definition
flow:
- type: "terraformPlan"
name: "Terraform Plan with Cost Estimation"
step: 100
commands:
- runtime: "GROOVY"
priority: 100
after: true
script: |
import Infracost
String credentials = "version: \"0.1\"\n" +
"api_key: $INFRACOST_KEY \n" +
"pricing_api_endpoint: https://pricing.api.infracost.io"
new Infracost().loadTool(
"$workingDirectory",
"$bashToolsDirectory",
"0.10.12",
credentials)
"Infracost Download Completed..."
- runtime: "BASH"
priority: 200
after: true
script: |
terraform show -json terraformLibrary.tfPlan > plan.json;
INFRACOST_ENABLE_DASHBOARD=true infracost breakdown --path plan.json --format json --out-file infracost.json;
totalCost=$(jq -r '.totalMonthlyCost' infracost.json);
urlTotalCost=$(jq -r '.shareUrl' infracost.json);
echo "Total Monthly Cost: $totalCost USD"
echo "For more detail information please visit: $urlTotalCost"
if (($totalCost < 100));
then
echo "The total cost for the resource is below 100 USD. Deployment is approved";
else
echo "The total cost for the resource is above 100 USD, cancelling operation";
exit 1
fi;
- type: "terraformApply"
name: "Terraform Apply"
step: 200
Terraform resources






Was this helpful?