broad-zoo-34077
03/14/2022, 5:09 PMenough-hair-29012
03/14/2022, 5:12 PMinvalid_blocks
error.enough-hair-29012
03/14/2022, 5:12 PMenough-hair-29012
03/14/2022, 5:13 PMenough-hair-29012
03/14/2022, 5:13 PMenough-hair-29012
03/14/2022, 5:16 PMlittle-author-61621
wc -c /tmp/infracost_combined.json
after the infracost output
line so we can see the length?little-author-61621
stocky-salesmen-15167
03/15/2022, 7:07 AMenough-hair-29012
03/15/2022, 8:30 AMwc -c
but as I am sending "/tmp/infracost_combined.json" after doing further formatting. Shouldn't I do character count for slack-message.json?little-author-61621
little-author-61621
stocky-salesmen-15167
03/15/2022, 8:56 AMstocky-salesmen-15167
03/15/2022, 8:56 AMenough-hair-29012
03/15/2022, 9:06 AM- name: Post to Slack channel
run: |
infracost output --path=/tmp/infracost_combined.json --format slack-message --out-file slack-message.json
#Count the number of characters in slack-message.json
wc -c slack-message.json
SLACK_WEBHOOK_URL="<removed-value>"
#Output slack-message.json on screen
echo "-------Contents of slack-message.json------------------"
cat slack-message.json
# Skip posting to Slack if there's no cost change
cost_change=$(cat /tmp/infracost_combined.json | jq -r "(.diffTotalMonthlyCost // 0) | tonumber")
if [ "$cost_change" = "0" ]; then
echo "Not posting to Slack since cost change is zero"
exit 0
fi
#Post to Slack
curl -X POST -H "Content-type: application/json" -d "@slack-message.json" $SLACK_WEBHOOK_URL
enough-hair-29012
03/15/2022, 9:07 AMenough-hair-29012
03/15/2022, 9:07 AMlittle-author-61621
little-author-61621
But why β¦ maybe thatβs what I donβt get?@stocky-salesmen-15167 we probably need a better way of doing this in the future, but the start and end of the output tend to include the most important information, so we thought truncating in the middle made the most sense.
enough-hair-29012
03/15/2022, 9:17 AM{
"attachments": [
{
"color": "#dcd8e1",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Infracost output*\n```Project: flysas-tech/cdx-terraform-infra/hub/prod/plan_hub-prod.json\n\n~ module.hub.azurerm_firewall.hub\n -3,553 kr (12,434 kr β 8,882 kr)\n\n ~ Deployment (Premium β Standard)\n -3,553 kr (12,434 kr β 8,882 kr)\n\nMonthly cost change for flysas-tech/cdx-terraform-infra/hub/prod/plan_hub-prod.json\nAmount: -3,553 kr (SEK) (12,557 kr β 9,005 kr)\nPercent: -28%\n\nββββββββββββββββββββββββββββββββββ\nProject: flysas-tech/cdx-terraform-infra/hub/test/plan_hub-test.json\n\n~ module.hub.azurerm_firewall.hub\n -3,553 kr (12,434 kr β 8,882 kr)\n\n ~ Deployment (Premium β Standard)\n -3,553 kr (12,434 kr β 8,882 kr)\n\nMonthly cost change for flysas-tech/cdx-terraform-infra/hub/test/plan_hub-test.json\nAmount: -3,553 kr (SEK) (12,557 kr β 9,005 kr)\nPercent: -28%\n\nββββββββββββββββββββββββββββββββββ\nProject: flysas-tech/cdx-terraform-infra/management-subscription/prod/plan_management-subscription-prod.json\n\n~ module.management_subscription.azurerm_log_analytics_workspace.management-log\n Monthly cost depends on usage\n\n + Log data retention\n Monthly cost depends on usage\n +1.27 kr per GB\n\nMonthly cost change for flysas-tech/cdx-terraform-infra/management-subscription/prod/plan_management-subscription-prod.json\nAmount: 0.00 kr (SEK) (0.00 kr β 0.00 kr)\n\nββββββββββββββββββββββββββββββββββ\nProject: flysas-tech/cdx-terraform-infra/management-subscription/test/plan_management-subscription-test.json\n\n~ module.management_subscription.azurerm_log_analytics_workspace.management-log\n Monthly cost depends on usage\n\n + Log data retention\n Monthly cost depends on usage\n +1.27 kr per GB\n\nMonthly cost change for flysas-tech/cdx-terraform-infra/management-subscription/test/plan_management-subscription-test.json\nAmount: 0.00 kr (SEK) (0.00 kr β 0.00 kr)\n\nββββββββββββββββββββββββββββββββββ\n\nThe following projects have no cost estimate changes: flysas-tech/cdx-terraform-infra/spokes/prod/plan_spokes-prod.json, flysas-tech/cdx-terraform-infra/spokes/test/plan_spokes-test.json\nRun infracost breakdown to see their full breakdown.\n\nββββββββββββββββββββββββββββββββββ\nKey: ~ changed, + added, - removed\n\n156 cloud resources were detected, rerun with --show-skipped to see details:\nβ 46 were estimated, 8 include usage-based costs, see <https://infracost.io/usage-file>\nβ 42 weren't estimated, report them in <https://github.com/infracost/infracost>\nβ 68 were free```"
}
}
]
}
],
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "π° Infracost estimate: *monthly cost will decrease by 7,105 kr (-28%) π*"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "plain_text",
"text": "Project"
},
{
"type": "plain_text",
"text": "Diff"
},
{
"type": "plain_text",
"text": "flysas-tech/cdx-terr.../plan_hub-prod.json"
},
{
"type": "plain_text",
"text": "-3,553 kr (12,557 kr β 9,005 kr)"
},
{
"type": "plain_text",
"text": "flysas-tech/cdx-terr.../plan_hub-test.json"
},
{
"type": "plain_text",
"text": "-3,553 kr (12,557 kr β 9,005 kr)"
},
{
"type": "plain_text",
"text": "flysas-tech/cdx-terr...scription-prod.json"
},
{
"type": "plain_text",
"text": "0.00 kr (0.00 kr β 0.00 kr)"
},
{
"type": "plain_text",
"text": "flysas-tech/cdx-terr...scription-test.json"
},
{
"type": "plain_text",
"text": "0.00 kr (0.00 kr β 0.00 kr)"
},
{
"type": "plain_text",
"text": "All projects"
},
{
"type": "plain_text",
"text": "-7,105 kr (25,115 kr β 18,009 kr)"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "2 projects have no cost estimate changes."
}
}
]
}
little-author-61621
little-author-61621
# Make sure we don't exceed the maximum Slack fields
cat slack-message.json | jq 'del(.blocks[2].fields[10:])' > slack-message-truncated.json
...
curl -X POST -H "Content-type: application/json" -d "@slack-message-truncated.json" $SLACK_WEBHOOK_URL
enough-hair-29012
03/15/2022, 10:09 AMenough-hair-29012
03/15/2022, 10:10 AMenough-hair-29012
03/15/2022, 10:15 AMenough-hair-29012
03/15/2022, 10:16 AMlittle-author-61621
little-author-61621
Just one more thing, we have multiple terraform projects in a single repository. So,I donβt thing merging the json for all the project would be a good idea from Slack point of view.Are you wanting a separate slack message for each project?
little-author-61621
enough-hair-29012
03/15/2022, 2:34 PMlittle-author-61621
enough-hair-29012
03/16/2022, 1:10 PMlittle-author-61621