Skip to main content

Getting Started with Kubiya Terraform Provider

This guide will walk you through setting up and using the Kubiya Control Plane Terraform Provider to manage your AI agent infrastructure as code.

Prerequisites

Before you begin, ensure you have:
  • Terraform >= 1.0 installed (Download)
  • Kubiya Control Plane Access (hosted or self-hosted)
  • API Key from your Kubiya Control Plane

Step 1: Obtain Your API Key

For Hosted Control Plane (SaaS)

  1. Navigate to https://compose.kubiya.ai
  2. Go to SettingsAPI Keys
  3. Click Generate New API Key
  4. Copy and securely store your API key

For Self-Hosted Control Plane

  1. Access your self-hosted control plane dashboard
  2. Navigate to SettingsAPI Keys
  3. Generate and copy your API key
  4. Note your control plane base URL (e.g., https://control-plane.your-company.com)

Step 2: Configure Environment Variables

Set up your authentication credentials:

Hosted Control Plane

Self-Hosted Control Plane

For production environments, consider using a secrets management solution like HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault instead of environment variables.

Step 3: Create Your First Configuration

Create a new directory for your Terraform configuration:
Create a file named main.tf:

Step 4: Initialize Terraform

Initialize your Terraform working directory:
Expected output:

Step 5: Plan Your Changes

Preview what Terraform will create:
Review the planned changes carefully. You should see:
  • 1 environment to create
  • 1 team to create
  • 1 agent to create

Step 6: Apply Your Configuration

Create the resources:
Type yes when prompted to confirm. Expected output:

Step 7: Verify Your Resources

Check the created resources:
You can also verify the resources in your Kubiya Control Plane dashboard.

Step 8: Make Changes

Update your configuration in main.tf. For example, change the agent description:
Apply the changes:

Using Data Sources

Look up existing resources using data sources. Create a file named data.tf:

Best Practices for Operators

1. Use Variables

Create variables.tf:
Create terraform.tfvars:

2. Use Remote State

Configure remote state storage in backend.tf:

3. Organize with Modules

Create reusable modules:

4. Use Workspaces

Manage multiple environments:

Cleanup

When you’re done experimenting, destroy the resources:
Type yes when prompted.
Be careful with terraform destroy in production environments. Consider using -target to destroy specific resources or implement lifecycle rules to prevent accidental deletion.

Troubleshooting

Authentication Errors

If you see authentication errors:

Provider Not Found

If Terraform can’t find the provider:

Resource Already Exists

If resources already exist:

Next Steps

Now that you have a basic configuration running:
  1. Configure Provider Options - Learn about advanced configuration
  2. Explore Resources - Detailed documentation for all resources
  3. Review Examples - End-to-end examples for operators
  4. Explore Modules - Use pre-built modules for common patterns
  5. Learn About Policies - Implement governance with OPA Rego
  6. Set Up Jobs - Automate workflows with scheduled jobs

Additional Resources