worried-soccer-67640
09/13/2022, 4:55 PMmysterious-teacher-68276
09/13/2022, 4:55 PMbreakdown
cmd is possible, however, I don’t think it’s currently possible to set the AWS profile per project. Let me double-check.worried-soccer-67640
09/13/2022, 4:56 PMworkflows:
terragrunt:
plan:
steps:
- env:
name: INFRACOST_OUTPUT
command: 'echo "/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/$WORKSPACE-${REPO_REL_DIR//\//-}-infracost.json"'
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- run: direnv-allow-all
- run: direnv exec . terragrunt plan -input=false -out=$PLANFILE
- run: direnv exec . terragrunt show -json $PLANFILE > $SHOWFILE
- run: |
if [ ! -d "/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM" ]; then
mkdir -p /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
fi
/tmp/infracost breakdown --path=$SHOWFILE \
--format=json \
--log-level=info \
--out-file=$INFRACOST_OUTPUT
apply:
steps:
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- run: direnv-allow-all
- run: direnv exec . terragrunt apply -input=false $PLANFILE
mysterious-teacher-68276
09/13/2022, 5:00 PMworried-soccer-67640
09/13/2022, 5:02 PMpath
is not a filter, and is actually a relative path to a planfile.
what i want is a way to say, any plan file under aws/accounts/nonprod
will use X as the AWS_PROFILE and anything under aws/accounts/prod
will use something elseaws/accounts/nonprod/eu-west-1/eks/terragrunt.hcl
aws/accounts/prod/ap-northeast-1/ec2/terragrunt.hcl
mysterious-teacher-68276
09/13/2022, 5:07 PMpath
field accepts both a terraform dir or plan JSON.worried-soccer-67640
09/13/2022, 5:08 PMmysterious-teacher-68276
09/13/2022, 5:08 PMworried-soccer-67640
09/13/2022, 5:09 PM/tmp/infracost breakdown --path=$SHOWFILE \
--format=json \
--log-level=info \
--out-file=$INFRACOST_OUTPUT
and have a config yaml that determines which AWS_PROFILE to use depending on the folder it's in.mysterious-teacher-68276
09/13/2022, 5:10 PMworried-soccer-67640
09/13/2022, 5:10 PMpath
field in the config field accepted wildcards like aws/accounts/nonprod/*
mysterious-teacher-68276
09/13/2022, 5:10 PM- path: aws/accounts/prod
env:
AWS_PROFILE: infracost-prod
- path: aws/accounts/prod
env:
AWS_PROFILE: infracost-stag
path
config valueworried-soccer-67640
09/13/2022, 5:14 PMmysterious-teacher-68276
09/13/2022, 5:14 PMworried-soccer-67640
09/13/2022, 11:27 PM#!/bin/bash
echo -e "version: 0.1\n\nprojects:" > infracost-generated.yml
ACCOUNTS=( prod nonprod shared connectivity )
process(){
for i in $(find aws/accounts/$1 -name "*.hcl" | grep -v "terragrunt-cache" ); do
x=$(dirname $i)
echo -e " - path: $x" >> infracost-generated.yml
echo -e " env:" >> infracost-generated.yml
echo -e " AWS_PROFILE: infracost-$1\n" >> infracost-generated.yml
done
}
for a in "${ACCOUNTS[@]}"; do
process $a
done
will test it out tomorrow.mysterious-teacher-68276
09/14/2022, 9:05 AMworried-soccer-67640
09/14/2022, 2:07 PM