Skip to content

Commit 0bc6922

Browse files
mariusz89016mariusz.wojakowski
andauthored
fix: Post infracost comment only once (#12)
* fix: Post infracost comment only once * fix: Run post-workflow hook based on existence of directory --------- Co-authored-by: mariusz.wojakowski <[email protected]>
1 parent 4a83370 commit 0bc6922

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

main.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22
#Repo attributes that are meant to simplify configuration rather than being actual repo options
3-
helper_options = ["allow_all_server_side_workflows", "terragrunt_atlantis_config"]
3+
helper_options = ["allow_all_server_side_workflows", "terragrunt_atlantis_config", "infracost"]
44

55
#Remove all options that are null
66
repos_with_non_null_values = [
@@ -50,7 +50,20 @@ locals {
5050
lookup(repo, "post_workflow_hooks", []),
5151
lookup(repo, "workflow", "") != "" && lookup(local._workflows, lookup(repo, "workflow", ""), "") != "" ? (
5252
local._workflows[lookup(repo, "workflow", "")].infracost.enabled ? [
53-
{ run : "infracost comment gitlab --repo $BASE_REPO_OWNER/$BASE_REPO_NAME --merge-request $PULL_NUM --path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json --gitlab-token $GITLAB_TOKEN --behavior new" }
53+
{ run : <<EOT
54+
if [ ! -d "/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM" ]; then
55+
exit 0
56+
fi
57+
58+
infracost comment gitlab --repo $BASE_REPO_OWNER/$BASE_REPO_NAME \
59+
--merge-request $PULL_NUM \
60+
--path /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM/'*'-infracost.json \
61+
--gitlab-token $GITLAB_TOKEN \
62+
--behavior new
63+
64+
rm -rf /tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM
65+
EOT
66+
}
5467
] : []) : []
5568
)
5669
})

0 commit comments

Comments
 (0)