Is there an easy way to push a terraform plan output to Teams/Slack?
I have a very basic bash script that posts to Teams via a Teams connector webhook based on the -detailed-exitcode
,but this is just reporting something has changed, I want the entire plan. I'm thinking there must be an easier way. I could grab the plan JSON but I'd rather have something readable within the message itself, not just an attachment
terraform plan -detailed-exitcode
export planresult=$?
if [[ "${planresult}" == "2" ]]
then
TEXT="Plan Changed"
TITLE="Changes in Development Terraform Plan"
WEBHOOK_URL=[webhook url]
COLOR="RED"
MESSAGE=$( echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g" )
JSON="{\"title\": \"${TITLE}\", \"themeColor\": \"${COLOR}\", \"text\": \"${MESSAGE}\" }"
# Post to Microsoft Teams.
curl -H "Content-Type: application/json" -d "${JSON}" "${WEBHOOK_URL}"
fi