Set up your first Kubiya AI agent with Terraform in minutes - from provider configuration to advanced automation workflows
Transform your infrastructure automation with AI-powered agents managed through Infrastructure as Code. This comprehensive guide will take you from zero to production-ready automation in just a few steps.
Quick Setup
Get your first agent running in under 10 minutes
Production Ready
Learn enterprise patterns and best practices
Event Driven
Build reactive automation with webhooks and triggers
Let’s start by configuring the Kubiya Terraform provider in your project.
1
Initialize Your Project
Create a new directory and initialize your Terraform configuration:
Copy
Ask AI
mkdir kubiya-automationcd kubiya-automation
2
Configure the Provider
Create your main configuration file:
Copy
Ask AI
terraform { required_version = ">= 1.0" required_providers { kubiya = { source = "kubiya-terraform/kubiya" version = "~> 1.0" } }}provider "kubiya" { # API key will be read from KUBIYA_API_KEY environment variable # Optionally specify a custom endpoint if using on-premises # endpoint = "https://your-kubiya-instance.com/api"}
3
Set Your API Key
Generate an API key from your Kubiya dashboard and set it as an environment variable:
Copy
Ask AI
# Set your API key (get this from Admin → Kubiya API Keys in the dashboard)export KUBIYA_API_KEY="kby_your_api_key_here"# Verify it's set correctlyecho "API Key configured: ${KUBIYA_API_KEY:0:10}..."
Never commit API keys to version control. Always use environment variables or secret management systems.
4
Initialize Terraform
Download the provider and initialize your workspace:
Copy
Ask AI
terraform init
You should see output confirming the Kubiya provider was downloaded successfully.
Now let’s build the foundational infrastructure for your AI agents.
1
Set Up a Runner
Runners are the compute environments where your agents execute tasks. Think of them as the “servers” for your AI agents:
Copy
Ask AI
# Create a runner for your agentsresource "kubiya_runner" "main" { name = "primary-runner" description = "Main execution environment for AI agents" type = "vcluster" # or "kubernetes" for existing clusters # Optional: Configure resource limits metadata = { environment = "production" team = "platform" }}
After creating the runner through Terraform, you’ll need to deploy its Helm chart. The Kubiya dashboard will provide the complete deployment instructions.
2
Add Knowledge Sources
Sources provide tools and capabilities to your agents. Every agent must have at least one source - this is mandatory:
Copy
Ask AI
# Basic tooling source (essential for most agents)resource "kubiya_source" "essential_tools" { name = "essential-tools" description = "Core tools for basic agent operations" url = "https://github.com/kubiyabot/community-tools/tree/main/basics" runner = kubiya_runner.main.name}# Infrastructure management toolsresource "kubiya_source" "infrastructure" { name = "infra-tools" description = "Tools for infrastructure management" url = "https://github.com/kubiyabot/community-tools/tree/main/infrastructure" branch = "main" runner = kubiya_runner.main.name # Optional: Sync on a schedule sync_schedule = "0 */4 * * *" # Every 4 hours}# Custom private sourceresource "kubiya_source" "custom_tools" { name = "company-tools" description = "Custom tools for our organization" url = "https://github.com/yourorg/kubiya-tools" branch = "production" runner = kubiya_runner.main.name # For private repositories, you'll need authentication # This will be configured in the Kubiya dashboard}
3
Create Knowledge Resources
Knowledge resources contain information your agents can reference during conversations:
Copy
Ask AI
# Company procedures and FAQsresource "kubiya_knowledge" "company_handbook" { name = "company-handbook" description = "Employee handbook and company procedures" content = file("${path.module}/docs/handbook.md") format = "markdown" # Optional: Specify which agents can access this knowledge labels = ["hr", "onboarding", "policies"]}# Technical documentationresource "kubiya_knowledge" "api_docs" { name = "api-documentation" description = "Internal API documentation and examples" content = file("${path.module}/docs/api-reference.md") format = "markdown" # Restrict to specific agents supported_agents = ["api-assistant", "developer-helper"]}
Now comes the exciting part - creating your first AI agent!
Copy
Ask AI
# Your first AI agentresource "kubiya_agent" "assistant" { name = "platform-assistant" runner = kubiya_runner.main.name description = "Intelligent assistant for platform operations and support" # Sources are REQUIRED - every agent must have at least one sources = [ kubiya_source.essential_tools.name, kubiya_source.infrastructure.name ] # Optional: Add custom instructions to guide the agent's behavior instructions = <<-EOT You are a helpful platform operations assistant. Your role is to: 1. Help with infrastructure monitoring and troubleshooting 2. Assist with deployment and configuration tasks 3. Provide guidance on best practices 4. Always explain your actions clearly and ask for confirmation on destructive operations EOT # Conversation starters to help users get started starters = [ { name = "System Status" command = "Check the current status of our infrastructure" }, { name = "Deploy Application" command = "Help me deploy an application to our staging environment" }, { name = "Troubleshoot Issue" command = "I'm having an issue with a service, can you help troubleshoot?" } ] # Access control - specify who can use this agent users = ["devops-team@company.com", "admin@company.com"] groups = ["Platform Engineering", "DevOps"] # Environment variables the agent can access environment_variables = { DEFAULT_NAMESPACE = "production" LOG_LEVEL = "info" TIMEOUT_MINUTES = "30" }}
Start with basic functionality and gradually add more capabilities as you learn what works best for your team.
Congratulations! You’ve successfully set up your first Kubiya AI agent with Terraform. Your intelligent automation platform is now ready to transform how your team manages infrastructure and operations.Start with simple tasks and gradually build more sophisticated automation as you learn what works best for your organization.