Made using ChatGPT conversation (included this README.md
) ❤️
This is a Golang application that listens for Terraform Cloud webhooks and sends formatted messages to a Discord webhook based on the webhook payload.
- Terraform Cloud account
- Discord account
- Golang installed on your local machine or server
- Docker installed on your local machine or server (optional)
- Docker Compose installed on your local machine or server (optional)
-
Create a Discord webhook for your server or channel. Follow the instructions in this guide to create a webhook URL.
-
Set the
TF_DISCORD_PROXY_WEBHOOK_URL
environment variable to the Discord webhook URL:export TF_DISCORD_PROXY_WEBHOOK_URL=<your-discord-webhook-url>
-
(Optional) Set the
TF_DISCORD_PROXY_PORT
environment variable to the desired port number (default is8080
):export TF_DISCORD_PROXY_PORT=<your-port-number>
-
(Optional) Set the
TF_DISCORD_PROXY_AUTH_TOKEN
environment variable to the Terraform Cloud webhook auth token:export TF_DISCORD_PROXY_AUTH_TOKEN=<your-terraform-cloud-webhook-auth-token>
-
Build and run the Golang application:
go run main.go
or
docker run -p $TF_DISCORD_PROXY_PORT:8080 -e TF_DISCORD_PROXY_WEBHOOK_URL=$TF_DISCORD_PROXY_WEBHOOK_URL -e TF_DISCORD_PROXY_AUTH_TOKEN=$TF_DISCORD_PROXY_AUTH_TOKEN smark91/terraform-cloud-discord-webhook:<image-version>
-
In your Terraform Cloud workspace, create a notification configuration with the following settings:
- Name: Discord Webhook
- Trigger: All events
- URL:
<your-server-url>/webhook
(replace<your-server-url>
with the URL of your server where the Docker container is running) - Token:
<your-terraform-cloud-webhook-auth-token>
(optional, replace<your-terraform-cloud-webhook-auth-token>
with a secret webhook auth token)
- Create a new run in your Terraform Cloud workspace to trigger the webhook.
If you prefer to use Docker Compose to run the Terraform Cloud Discord webhook proxy, follow these steps:
-
Create a Discord webhook for your server or channel. Follow the instructions in this guide to create a webhook URL.
-
Create a file named
docker-compose.yml
with the following contents:version: '3' services: terraform-cloud-discord-webhook-proxy: image: smark91/terraform-cloud-discord-webhook-proxy:<image-version> ports: - "8080:8080" environment: - TF_DISCORD_PROXY_WEBHOOK_URL=<your-discord-webhook-url> # - TF_DISCORD_PROXY_PORT=8080 # - TF_DISCORD_PROXY_AUTH_TOKEN=<your-terraform-cloud-webhook-auth-token>
Replace
<your-discord-webhook-url>
with the Discord webhook URL, and<your-terraform-cloud-webhook-auth-token>
with the Terraform Cloud webhook auth token (if you specified one). -
Run the following command to start the Docker Compose stack:
docker-compose up -d