The ChatBotKit Terraform Provider enables you to manage your AI chatbot infrastructure using Terraform. Define bots, datasets, skillsets, integrations, and more through declarative configuration files, enabling version control, automated deployments, and infrastructure consistency across environments.
Key Features
- Infrastructure as Code: Manage ChatBotKit resources declaratively
- Full Resource Coverage: Support for bots, datasets, skillsets, integrations, and more
- Data Sources: Read existing resources for reference in configurations
- Import Support: Bring existing resources under Terraform management
- State Management: Track resource changes and drift detection
- CI/CD Integration: Automate deployments through pipelines
Installation
From Terraform Registry
Add the provider to your Terraform configuration:
terraform { required_providers { chatbotkit = { source = "chatbotkit/chatbotkit" version = "~> 1.0" } } } provider "chatbotkit" { # API key can be set here or via CHATBOTKIT_API_KEY env var }hcl
Then initialize Terraform:
terraform initbash
Requirements
- Terraform 1.0 or higher
- A ChatBotKit API key from the Dashboard
Authentication
Configure authentication using either method:
Environment Variable (Recommended for CI/CD):
export CHATBOTKIT_API_KEY="your-api-key"bash
Provider Configuration:
provider "chatbotkit" { api_key = var.chatbotkit_api_key } variable "chatbotkit_api_key" { type = string sensitive = true }hcl
Quick Start
Here's a complete example that creates a knowledge-based support bot:
terraform { required_providers { chatbotkit = { source = "chatbotkit/chatbotkit" version = "~> 1.0" } } } provider "chatbotkit" {} # Create a knowledge base resource "chatbotkit_dataset" "knowledge" { name = "Product Knowledge Base" description = "Contains product documentation and FAQs" } # Create a skillset for tools resource "chatbotkit_skillset" "tools" { name = "Support Tools" description = "Tools for customer support operations" } # Add an ability to the skillset resource "chatbotkit_skillset_ability" "ticket_lookup" { skillset_id = chatbotkit_skillset.tools.id name = "lookup_ticket" description = "Look up a support ticket by ID" instruction = "Use this to find ticket details when a customer asks about their ticket status." } # Create the bot resource "chatbotkit_bot" "support" { name = "Customer Support Bot" description = "Handles customer inquiries" backstory = "You are a helpful customer support agent for our company. Be friendly, professional, and always try to resolve issues on the first interaction." model = "gpt-4" dataset_id = chatbotkit_dataset.knowledge.id skillset_id = chatbotkit_skillset.tools.id moderation = true privacy = true } # Deploy to Slack resource "chatbotkit_slack_integration" "support_slack" { name = "Support Slack Bot" bot_id = chatbotkit_bot.support.id } # Output the bot ID output "bot_id" { value = chatbotkit_bot.support.id }hcl
Deploy with:
terraform plan # Preview changes terraform apply # Apply changesbash
Resources
The provider supports the following resources for creating and managing ChatBotKit entities:
Core Resources
| Resource | Description |
|---|---|
chatbotkit_bot | AI chatbot agents with configurable models and behaviors |
chatbotkit_dataset | Knowledge bases for retrieval-augmented generation |
chatbotkit_skillset | Collections of abilities (tools) for bots |
chatbotkit_skillset_ability | Individual abilities within a skillset |
chatbotkit_blueprint | Reusable templates for bot configurations |
chatbotkit_secret | Secure credential storage |
chatbotkit_file | File uploads for datasets and other uses |
chatbotkit_portal | Customer-facing portal configurations |
Integration Resources
| Resource | Description |
|---|---|
chatbotkit_discord_integration | Discord bot deployment |
chatbotkit_slack_integration | Slack workspace integration |
chatbotkit_telegram_integration | Telegram bot deployment |
chatbotkit_whatsapp_integration | WhatsApp Business integration |
chatbotkit_messenger_integration | Facebook Messenger integration |
chatbotkit_email_integration | Email-based interactions |
chatbotkit_twilio_integration | Twilio SMS/voice integration |
chatbotkit_widget_integration | Embeddable chat widget |
chatbotkit_notion_integration | Notion workspace sync |
chatbotkit_sitemap_integration | Website content ingestion |
chatbotkit_trigger_integration | Event-based triggers |
chatbotkit_extract_integration | Data extraction pipelines |
chatbotkit_mcpserver_integration | MCP server connections |
Data Sources
Read existing resources without managing them:
# Reference an existing bot data "chatbotkit_bot" "existing" { id = "bot_abc123" } # Use its properties output "existing_bot_name" { value = data.chatbotkit_bot.existing.name }hcl
Available data sources:
chatbotkit_botchatbotkit_datasetchatbotkit_blueprintchatbotkit_skillset
Resource Examples
Bot with Full Configuration
resource "chatbotkit_bot" "advanced" { name = "Enterprise Assistant" description = "Multi-purpose enterprise bot" backstory = <<-EOT You are an enterprise assistant with access to company knowledge and various tools. Always be professional and helpful. Key guidelines: - Verify user identity for sensitive operations - Escalate complex issues to human agents - Log all significant interactions EOT model = "gpt-4" dataset_id = chatbotkit_dataset.knowledge.id skillset_id = chatbotkit_skillset.tools.id moderation = true privacy = true visibility = "private" meta = { environment = "production" team = "customer-success" version = "2.0" } }hcl
Dataset with Records
resource "chatbotkit_dataset" "faq" { name = "FAQ Database" description = "Frequently asked questions" meta = { source = "zendesk" sync_daily = "true" } }hcl
Skillset with Multiple Abilities
resource "chatbotkit_skillset" "crm_tools" { name = "CRM Tools" description = "Customer relationship management tools" } resource "chatbotkit_skillset_ability" "create_ticket" { skillset_id = chatbotkit_skillset.crm_tools.id name = "create_support_ticket" description = "Create a new support ticket" instruction = "Use this when a customer needs to file a new support request." } resource "chatbotkit_skillset_ability" "update_contact" { skillset_id = chatbotkit_skillset.crm_tools.id name = "update_contact_info" description = "Update customer contact information" instruction = "Use this when a customer wants to update their email, phone, or address." }hcl
Multi-Channel Deployment
resource "chatbotkit_bot" "omnichannel" { name = "Omnichannel Support" backstory = "You are a support agent available across all channels." model = "gpt-4" } resource "chatbotkit_slack_integration" "slack" { name = "Slack Support" bot_id = chatbotkit_bot.omnichannel.id } resource "chatbotkit_discord_integration" "discord" { name = "Discord Support" bot_id = chatbotkit_bot.omnichannel.id } resource "chatbotkit_telegram_integration" "telegram" { name = "Telegram Support" bot_id = chatbotkit_bot.omnichannel.id }hcl
Importing Existing Resources
Bring existing resources under Terraform management:
# Import a bot terraform import chatbotkit_bot.my_bot bot_abc123def456 # Import a dataset terraform import chatbotkit_dataset.my_dataset dataset_xyz789 # Import an integration terraform import chatbotkit_slack_integration.my_slack slack_integration_123bash
After importing, add the resource to your configuration to prevent Terraform from trying to delete it.
State Management
Remote State
For team collaboration, use remote state backends:
terraform { backend "s3" { bucket = "my-terraform-state" key = "chatbotkit/terraform.tfstate" region = "us-east-1" } }hcl
Workspaces
Manage multiple environments with workspaces:
terraform workspace new staging terraform workspace new production terraform workspace select productionbash
resource "chatbotkit_bot" "support" { name = "Support Bot - ${terraform.workspace}" # ... other configuration }hcl
CI/CD Integration
GitHub Actions Example
name: Deploy ChatBotKit Infrastructure on: push: branches: [main] paths: ['terraform/**'] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: hashicorp/setup-terraform@v3 with: terraform_version: 1.6.0 - name: Terraform Init run: terraform init working-directory: terraform - name: Terraform Plan run: terraform plan -out=tfplan working-directory: terraform env: CHATBOTKIT_API_KEY: ${{ secrets.CHATBOTKIT_API_KEY }} - name: Terraform Apply run: terraform apply -auto-approve tfplan working-directory: terraform env: CHATBOTKIT_API_KEY: ${{ secrets.CHATBOTKIT_API_KEY }}yaml
Best Practices
Use Variables for Reusability
variable "environment" { type = string default = "development" } variable "bot_model" { type = string default = "gpt-4" } resource "chatbotkit_bot" "support" { name = "Support Bot - ${var.environment}" model = var.bot_model }hcl
Organize with Modules
terraform/
├── main.tf
├── variables.tf
├── outputs.tf
└── modules/
├── support-bot/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf
└── sales-bot/
└── ...
Use Lifecycle Rules
resource "chatbotkit_bot" "critical" { name = "Critical Production Bot" lifecycle { prevent_destroy = true } }hcl
Tag Resources with Metadata
locals { common_meta = { managed_by = "terraform" environment = var.environment team = var.team } } resource "chatbotkit_bot" "support" { name = "Support Bot" meta = local.common_meta }hcl
Troubleshooting
Common Issues
Authentication Errors:
Error: 401 Unauthorized
Verify your API key is set correctly via environment variable or provider configuration.
Resource Not Found:
Error: Resource not found
The resource may have been deleted outside of Terraform. Remove it from state with:
terraform state rm chatbotkit_bot.my_botbash
State Drift:
~ resource "chatbotkit_bot" "support" {
~ name = "Old Name" -> "New Name"
}
Someone modified the resource outside Terraform. Run terraform apply to reconcile or update your configuration to match.
Debug Logging
Enable detailed logging:
export TF_LOG=DEBUG terraform planbash