A Terraform provider for managing Discord resources such as servers (guilds), channels, roles, and more using infrastructure-as-code principles.
-
Resources
discord_server- Manage a Discord server (guild)discord_channel- Manage a channel within a serverdiscord_role- Manage a role within a serverdiscord_emoji- Manage custom emojis in a serverdiscord_webhook- Manage webhooks for channelsdiscord_invite- Manage channel invitesdiscord_channel_permission_overwrite- Set per-channel permission overwrites for roles/membersdiscord_member_role- Assign a role to a guild memberdiscord_message- Send a message to a channel (create-only)
-
Data Sources
discord_server- Read information about an existing serverdiscord_channel- Read information about an existing channeldiscord_role- Read information about an existing role
- Terraform >= 1.9
- Go >= 1.25 (for building from source)
- A Discord bot token with appropriate permissions
The provider is available on the Terraform Registry. Add to your Terraform configuration:
terraform {
required_providers {
discord = {
source = "echohello-dev/discord"
version = "~> 0.1"
}
}
}Download the latest release for your platform from the GitHub Releases page.
git clone https://github.com/echohello-dev/terraform-provider-discord.git
cd terraform-provider-discord
go build -o terraform-provider-discord| Option | Type | Required | Default | Description |
|---|---|---|---|---|
token |
string | Yes | - | Discord bot token |
export DISCORD_TOKEN="your-bot-token"resource "discord_server" "community" {
name = "My Terraform Community"
region = "us-west"
verification_level = 1
default_message_notifications = 0
explicit_content_filter = 2
afk_timeout = 300
}resource "discord_channel" "general" {
server_id = discord_server.community.id
name = "general"
type = 0 # GUILD_TEXT
topic = "General discussion"
}
resource "discord_channel" "voice" {
server_id = discord_server.community.id
name = "General Voice"
type = 2 # GUILD_VOICE
}resource "discord_role" "moderator" {
server_id = discord_server.community.id
name = "Moderator"
permissions = "268435456"
color = 3447003
hoist = true
mentionable = true
}data "discord_server" "existing" {
id = "123456789012345678"
}
output "server_name" {
value = data.discord_server.existing.name
}See the examples/ directory for more complete usage examples.
mise run buildmise run installTo test the provider locally without publishing it, configure Terraform to use your locally built binary:
mise run dev-setup
# Edit ~/.terraformrc and replace the empty path with your GOBIN directory:
# go env GOBINAlternatively, create ~/.terraformrc manually:
provider_installation {
dev_overrides {
"registry.terraform.io/echohello-dev/discord" = "/Users/YOU/go/bin"
}
direct {}
}Note: When using
dev_overrides, skipterraform init. The provider is loaded directly from the local binary.
# Unit tests
mise run test
# Acceptance tests (requires DISCORD_TOKEN)
mise run testacc
# Run specific tests
mise run test "TestAccResource_server"mise run fmt
mise run vet
mise run lintmise run docOr via go generate:
go generate ./...mise run tidyRun mise run (or mise run h) to see all available tasks.
| Task | Description |
|---|---|
build |
Build the provider binary to .build/ |
install |
Install the provider to the local Terraform plugin directory |
clean |
Remove built artifacts |
fmt |
Format Go and Terraform code |
vet |
Run go vet |
lint |
Run golangci-lint |
test |
Run unit tests |
testacc |
Run acceptance tests |
doc |
Generate provider documentation |
validate |
Run lint + test |
tidy |
Tidy Go modules |
dev-setup |
Create ~/.terraformrc with dev overrides |
Enable debug logging:
TF_LOG=DEBUG terraform planContributions are welcome! Please read our contributing guidelines before submitting PRs.
MIT License - see LICENSE file for details.