broad-zoo-34077
03/10/2022, 1:24 PMfamous-ocean-61698
03/10/2022, 1:24 PMworkflows:
terragrunt:
plan:
steps:
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- env:
name: TF_CLI_ARGS
value: "-no-color"
- run: terragrunt plan -out $PLANFILE >/dev/null 2>$PLANFILE.err || ! cat $PLANFILE.err
- run: terragrunt show $PLANFILE 2>/dev/null
- env:
name: INFRACOST_TERRAFORM_BINARY
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- run: "/home/atlantis/infracost_atlantis_diff.sh"
apply:
steps:
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- env:
name: TF_CLI_ARGS
value: "-no-color"
- run: terragrunt apply $PLANFILE
famous-ocean-61698
03/10/2022, 1:25 PMfamous-ocean-61698
03/10/2022, 1:27 PMmysterious-teacher-68276
03/10/2022, 1:29 PMinfracost_atlantis_diff.sh
to refresh my memory what we do heremysterious-teacher-68276
03/10/2022, 1:37 PMinfracost breakdown
step in your plan
stage and using the post-workflow
hook. This is easier as it solves you having issues with resolving plan files in a separate workflow step. Using infracost comment
in a post-workflow
hook has glob support so it’s much easier to combine into a single comment when all the files have been built.mysterious-teacher-68276
03/10/2022, 1:37 PM--path /tmp/*-infracost.json
famous-ocean-61698
03/10/2022, 1:39 PMpost-workflow
hook. And will add a breakdown step to the existing workflow. Would it mean what comment will be posted only after the whole workflow is finished even with apply step?mysterious-teacher-68276
03/10/2022, 1:39 PMmysterious-teacher-68276
03/10/2022, 1:40 PMmysterious-teacher-68276
03/10/2022, 1:41 PMapply
stage is one with a manual confirmationmysterious-teacher-68276
03/10/2022, 1:41 PMPR
.famous-ocean-61698
03/10/2022, 1:41 PMmysterious-teacher-68276
03/10/2022, 1:46 PMmysterious-teacher-68276
03/10/2022, 1:48 PMpost_workflow
hook is only executed after all non confirmed steps. Let me just confirm that.famous-ocean-61698
03/10/2022, 1:50 PMmysterious-teacher-68276
03/10/2022, 1:56 PMapply
step is external to post_workflow_hooks
. In your case the post_workflow_hook
will run after plan
has finishedmysterious-teacher-68276
03/10/2022, 1:56 PMfamous-ocean-61698
03/10/2022, 1:58 PMfamous-ocean-61698
03/11/2022, 8:52 AMrepos:
- id: /.*/
workflow: terraform-infracost
mysterious-teacher-68276
03/11/2022, 9:53 AMmysterious-teacher-68276
03/11/2022, 9:54 AMfamous-ocean-61698
03/11/2022, 9:55 AMmysterious-teacher-68276
03/11/2022, 9:55 AMmysterious-teacher-68276
03/11/2022, 9:56 AMmysterious-teacher-68276
03/11/2022, 9:58 AMrepos:
- id: <http://github.com/your-org/infracost-repo|github.com/your-org/infracost-repo>
workflow: terraform-infracost
- id: /.*/
workflow: another-workflow-that-all-repos-use
mysterious-teacher-68276
03/11/2022, 9:59 AMworkflows:
terraform-infracost:
plan:
steps:
...
- run: infracost breakdown
another-workflow-that-all-repos-use:
plan:
...
famous-ocean-61698
03/11/2022, 9:59 AMfamous-ocean-61698
03/11/2022, 10:00 AMfamous-ocean-61698
03/11/2022, 10:00 AMmysterious-teacher-68276
03/11/2022, 10:04 AMfamous-ocean-61698
03/11/2022, 10:12 AMmysterious-teacher-68276
03/11/2022, 10:13 AMatlantis.yml
mysterious-teacher-68276
03/11/2022, 10:16 AM- id: /.*/
workflow: my-default-workflow
allowed_overrides: [workflow]
repo atlantis.yml
version: 3
automerge: true
delete_source_branch_on_merge: true
projects:
- name: my-project-name
dir: .
workflow: my-specific-workflow
mysterious-teacher-68276
03/11/2022, 10:16 AMfamous-ocean-61698
03/11/2022, 10:28 AMfamous-ocean-61698
03/11/2022, 3:22 PMinfracost breakdown
.famous-ocean-61698
03/11/2022, 3:26 PMexit status 1: running "infracost breakdown --path=$PLANFILE \\\n --format=json \\\n --log-level=info \\\n --out-file=$INFRACOST_OUTPUT\n" in "/atlantis-data/repos/us-east-1/s3":
time="2022-03-11T12:58:55Z" level=info msg="Detected Terraform plan file at /atlantis-data/us-east-1/s3/default.tfplan"
time="2022-03-11T12:58:55Z" level=info msg="Starting: Running terraform show"
famous-ocean-61698
03/11/2022, 3:27 PMworkflows:
terragrunt:
plan:
steps:
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- env:
name: TF_CLI_ARGS
value: "-no-color"
- env:
name: INFRACOST_OUTPUT
command: 'echo "/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM-$WORKSPACE-${REPO_REL_DIR//\//-}-infracost.json"'
- env:
name: INFRACOST_COMMENT_TAG
command: 'echo "$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM-$WORKSPACE-${REPO_REL_DIR//\//-}"'
- run: terragrunt plan -out $PLANFILE >/dev/null 2>$PLANFILE.err || ! cat $PLANFILE.err
- run: terragrunt show $PLANFILE 2>/dev/null
- run: |
infracost breakdown --path=$PLANFILE \
--format=json \
--log-level=info \
--out-file=$INFRACOST_OUTPUT
- run: |
infracost comment github --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
--pull-request $PULL_NUM \
--path $INFRACOST_OUTPUT \
--github-token $ATLANTIS_GH_TOKEN \
--tag $INFRACOST_COMMENT_TAG \
--behavior update
apply:
steps:
- env:
name: TERRAGRUNT_TFPATH
command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
- env:
name: TF_CLI_ARGS
value: "-no-color"
- run: terragrunt apply $PLANFILE
famous-ocean-61698
03/11/2022, 3:28 PMmysterious-teacher-68276
03/11/2022, 3:29 PMlog-level=debug
famous-ocean-61698
03/11/2022, 3:40 PMinfracost breakdown
. Atlantis publishing plan ok. Maybe its related to terragrunt somehow?
exit status 1: running "infracost breakdown --path=$PLANFILE \\\n --format=json \\\n --log-level=info \\\n --out-file=$INFRACOST_OUTPUT\n" in "/atlantis-data/repos/productboard/pb-infrastructure/828/default/aws/pb-staging-793677888466/us-east-1/s3":
time="2022-03-11T13:45:34Z" level=info msg="Detected Terraform plan file at /atlantis-data/repos/productboard/pb-infrastructure/828/default/aws/pb-staging-793677888466/us-east-1/s3/default.tfplan"
time="2022-03-11T13:45:34Z" level=info msg="Starting: Running terraform show"
Terraform command failed with:
Error: Module source has changed
on <http://developer-productboard-info.tf|developer-productboard-info.tf> line 2, in module "developer-productboard-info":
2: source = "terraform-aws-modules/s3-bucket/aws"
The source address was changed since this module was installed. Run
"terraform init" to install all modules required by this configuration.
Error: Module source has changed
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
famous-ocean-61698
03/11/2022, 3:42 PMmysterious-teacher-68276
03/11/2022, 3:42 PMplanfile
to the breakdownmysterious-teacher-68276
03/11/2022, 3:43 PMfamous-ocean-61698
03/11/2022, 3:44 PMmysterious-teacher-68276
03/11/2022, 3:44 PMmysterious-teacher-68276
03/11/2022, 3:47 PMterragrunt show -json $PLANFILE > $SHOWFILE
then using:
- run: |
infracost breakdown --path=$SHOWFILE \
--format=json \
--log-level=info \
--out-file=$INFRACOST_OUTPUT
would do the trickfamous-ocean-61698
03/11/2022, 3:50 PMfamous-ocean-61698
03/14/2022, 10:56 AMmysterious-teacher-68276
03/14/2022, 10:57 AMfamous-ocean-61698
03/14/2022, 11:36 AMmysterious-teacher-68276
03/14/2022, 11:38 AMinfracost comment
. However, it’s a good idea and maybe something we can incorporate. Though I’m unsure how we would identify the atlantis comment (we use special markdown tags to identify infracost comments)mysterious-teacher-68276
03/14/2022, 1:15 PMinfracost comment
step. You’re using --behavior update
which will cause the comment to be posted once and updated every re-run, --behavior new
or --behavior hide-and-new
might be better for you. hide-and-new
removes prior comment and posts a new one & new
just adds a new comment. These are less likely to get lost in atlantis comment noisefamous-ocean-61698
03/14/2022, 1:45 PMmysterious-teacher-68276
03/14/2022, 1:46 PM