broad-zoo-34077
09/15/2022, 10:41 PMworried-soccer-67640
09/15/2022, 10:43 PMworried-soccer-67640
09/15/2022, 10:43 PM--path=$SHOWFILE
?worried-soccer-67640
09/15/2022, 10:44 PMworried-soccer-67640
09/15/2022, 10:44 PMwhite-airport-8778
worried-soccer-67640
09/15/2022, 10:44 PMworried-soccer-67640
09/15/2022, 10:45 PMinfracost
understand which variables to set depending on what paths were being parsed to itwhite-airport-8778
white-airport-8778
worried-soccer-67640
09/15/2022, 10:45 PMworried-soccer-67640
09/15/2022, 10:46 PMwhite-airport-8778
white-airport-8778
worried-soccer-67640
09/15/2022, 10:47 PMworried-soccer-67640
09/15/2022, 10:47 PMworried-soccer-67640
09/15/2022, 10:47 PMwhite-airport-8778
white-airport-8778
path:
values would be plan JSON files though, not directoriesworried-soccer-67640
09/15/2022, 10:53 PMpath: aws/accounts/connectivity/eu-west-1/ec2/plan.json
env:
AWS_ACCESS_KEY_ID: xxxxx
AWS_SECRET_ACCESS_KEY: xx+xx/xx
AWS_SESSION_TOKEN: xxxxx
path: aws/accounts/connectivity/eu-west-1/eks/plan.json
env:
AWS_ACCESS_KEY_ID: xxxxx
AWS_SECRET_ACCESS_KEY: xx+xx/xx
AWS_SESSION_TOKEN: xxxxx
and then use a command like this?
infracost breakdown \
--format=json \
--config-file /atlantis-data/repos/org/infrastructure/$PULL_NUM/default/infracost-generated.yml
--log-level=info \
--out-file=$INFRACOST_OUTPUT
white-airport-8778
infracost breakdown \
--format=json \
--config-file /atlantis-data/repos/b2c2/infrastructure/$PULL_NUM/default/infracost-generated.yml
--log-level=info \
--out-file=$INFRACOST_OUTPUT \
--sync-usage-file --usage-file /tmp/ignore.yml
The last line is what tells the CLI to fetch the usage data and use a tmp file as you donât care about storing that usage or checking it into your repo, you just want the CLI output to include the usage data. This workaround is mentioned here in the docs too.white-airport-8778
white-airport-8778
# infracost-config.yml file:
version: 0.1
projects:
- path: aws/accounts/connectivity/eu-west-1/ec2/plan.json
usage_file: /tmp/infracost-usage-1.yml
env:
AWS_ACCESS_KEY_ID: xxxxx
AWS_SECRET_ACCESS_KEY: xx+xx/xx
AWS_SESSION_TOKEN: xxxxx
- path: aws/accounts/connectivity/eu-west-1/eks/plan.json
usage_file: /tmp/infracost-usage-2.yml
env:
AWS_ACCESS_KEY_ID: xxxxx
AWS_SECRET_ACCESS_KEY: xx+xx/xx
AWS_SESSION_TOKEN: xxxxx
infracost breakdown \
--format=json \
--config-file /atlantis-data/repos/org/infrastructure/$PULL_NUM/default/infracost-generated.yml
--log-level=info \
--out-file=$INFRACOST_OUTPUT \
--sync-usage-file
worried-soccer-67640
09/15/2022, 11:17 PMworried-soccer-67640
09/15/2022, 11:17 PMwhite-airport-8778
worried-soccer-67640
09/16/2022, 10:20 AMdev/eks/
worried-soccer-67640
09/16/2022, 10:20 AMworried-soccer-67640
09/16/2022, 10:20 AMworried-soccer-67640
09/16/2022, 10:20 AMwhite-airport-8778
worried-soccer-67640
09/16/2022, 8:50 PMworried-soccer-67640
09/16/2022, 8:50 PM#!/usr/bin/env bash
set -e
export HOME=/tmp
process(){
case $1 in
"prod")
accountId=x
;;
"nonprod")
accountId=y
;;
"shared")
accountId=z
;;
"connectivity" )
accountId=w
;;
*)
exit 1
;;
esac
credentials="$(aws sts assume-role --role-arn=arn:aws:iam::${accountId}:role/infracost --role-session-name session | jq -r .Credentials)"
AccessKeyId="$(echo "${credentials}" | jq -r .AccessKeyId)"
SecretAccessKey="$(echo "${credentials}" | jq -r .SecretAccessKey)"
SessionToken="$(echo "${credentials}" | jq -r .SessionToken)"
echo -e "version: 0.1\n\nprojects:" > "${CONFIG_DIR}"/infracost-generated.yml
echo -e " - path: $JSONFILE" >> "${CONFIG_DIR}"/infracost-generated.yml
echo -e " usage_file: usage.yml" >> "${CONFIG_DIR}"/infracost-generated.yml
echo -e " env:" >> "${CONFIG_DIR}"/infracost-generated.yml
echo -e " AWS_ACCESS_KEY_ID: $AccessKeyId" >> "${CONFIG_DIR}"/infracost-generated.yml
echo -e " AWS_SECRET_ACCESS_KEY: $SecretAccessKey" >> "${CONFIG_DIR}"/infracost-generated.yml
echo -e " AWS_SESSION_TOKEN: $SessionToken\n" >> "${CONFIG_DIR}"/infracost-generated.yml
}
CONFIG_DIR=$(dirname "$PLANFILE")
JSONFILE="${CONFIG_DIR}/default.json"
ACCOUNT=$(echo "${PLANFILE}" | cut -d/ -f10 )
process $ACCOUNT
white-airport-8778
worried-soccer-67640
09/16/2022, 8:51 PMworried-soccer-67640
09/16/2022, 8:51 PMworried-soccer-67640
09/16/2022, 8:52 PMwhite-airport-8778
infracost comment
Great! Feel free to share the link on the general chat, I can also include it in the monthly blog+newsletter.