Skip to main content

Terraform Data Sources

Data sources allow you to query existing Kubiya Control Plane resources and use their attributes in your Terraform configurations.

Why Use Data Sources?

  • Reference Existing Resources: Look up resources created outside Terraform
  • Cross-Stack References: Reference resources from other Terraform configurations
  • Dynamic Configuration: Build configurations based on existing infrastructure
  • Read-Only Access: Query resources without managing them

Available Data Sources

All managed resources have corresponding data sources:
  • controlplane_environment - Look up a single environment by ID
  • controlplane_project - Look up a single project by ID
  • controlplane_team - Look up a single team by ID
  • controlplane_agent - Look up a single agent by ID
  • controlplane_skill - Look up a single skill by ID
  • controlplane_policy - Look up a single policy by ID
  • controlplane_job - Look up a single job by ID
  • controlplane_jobs - List all jobs
  • controlplane_worker_queue - Look up a single worker queue by ID
  • controlplane_worker_queues - List all worker queues in an environment

Data Source Arguments

All data sources require the resource id:

Data Source Examples

controlplane_environment

Look up an existing environment by ID:
Exported Attributes:
  • id - Environment ID
  • name - Environment name
  • display_name - Display name
  • description - Environment description
  • tags - List of tags
  • configuration - Environment configuration (JSON)
  • execution_environment - Execution settings (JSON)
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_project

Look up an existing project:
Exported Attributes:
  • id - Project ID
  • name - Project name
  • key - Project key
  • description - Project description
  • goals - Project goals
  • visibility - Visibility setting
  • metadata - Project metadata (JSON)
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_team

Look up an existing team:
Exported Attributes:
  • id - Team ID
  • name - Team name
  • description - Team description
  • runtime - Runtime type (default or claude_code)
  • configuration - Team configuration (JSON)
  • capabilities - List of capabilities
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_agent

Look up an existing agent:
Exported Attributes:
  • id - Agent ID
  • name - Agent name
  • description - Agent description
  • model_id - LLM model
  • runtime - Runtime type
  • team_id - Team ID
  • llm_config - LLM configuration (JSON)
  • configuration - Agent configuration (JSON)
  • capabilities - List of capabilities
  • status - Agent status
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_skill

Look up an existing skill:
Exported Attributes:
  • id - Skill ID
  • name - Skill name
  • description - Skill description
  • type - Skill type (shell, file_system, docker, custom)
  • enabled - Whether skill is enabled
  • configuration - Skill configuration (JSON)
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_policy

Look up an existing policy:
Exported Attributes:
  • id - Policy ID
  • name - Policy name
  • description - Policy description
  • enabled - Whether policy is enabled
  • policy_content - OPA Rego policy content
  • tags - List of tags
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_job

Look up an existing job:
Exported Attributes:
  • id - Job ID
  • name - Job name
  • description - Job description
  • enabled - Whether job is enabled
  • status - Job status
  • trigger_type - Trigger type (cron, webhook, manual)
  • cron_schedule - Cron expression
  • cron_timezone - Timezone for cron schedule
  • webhook_url - Full webhook URL (for webhook triggers)
  • planning_mode - Planning mode
  • entity_type - Entity type (agent, team, workflow)
  • entity_id - Entity ID
  • prompt_template - Prompt template
  • system_prompt - System prompt
  • executor_type - Executor routing type
  • worker_queue_name - Worker queue name
  • environment_name - Environment name
  • created_at - Creation timestamp
  • updated_at - Last update timestamp

controlplane_jobs

List all jobs in the control plane:
Exported Attributes:
  • jobs - List of all jobs, each with the same attributes as controlplane_job data source

controlplane_worker_queue

Look up an existing worker queue:
Exported Attributes:
  • id - Worker Queue ID
  • environment_id - Environment ID
  • name - Worker queue name
  • display_name - Display name
  • description - Queue description
  • status - Worker queue status
  • max_workers - Maximum workers allowed
  • heartbeat_interval - Seconds between heartbeats
  • tags - List of tags
  • settings - Additional settings as map
  • created_at - Creation timestamp
  • updated_at - Last update timestamp
  • active_workers - Number of active workers
  • task_queue_name - Task queue name for Temporal

controlplane_worker_queues

List all worker queues in an environment:
Exported Attributes:
  • environment_id - Environment ID (input)
  • queues - List of worker queues, each with the same attributes as controlplane_worker_queue data source

Common Use Cases

Use Case 1: Cross-Stack References

Reference resources from a different Terraform state:

Use Case 2: Dynamic Agent Creation

Create agents based on existing team configuration:

Use Case 3: Configuration Validation

Validate that resources exist before creating dependencies:

Use Case 4: Import Existing Resources

Find existing resources to import into Terraform:

Use Case 5: Clone Configurations

Clone existing resources with modifications:

Working with JSON Attributes

Many data source attributes return JSON strings. Use jsondecode() to parse them:

Best Practices

1. Use Variables for IDs

Don’t hardcode resource IDs:

2. Validate Data Source Results

Check that required data exists:

3. Document Data Source Usage

Add clear comments:

4. Use Outputs for Debugging

Output data source attributes for troubleshooting:

Error Handling

If a data source can’t find a resource:
Solutions:
  1. Verify the resource ID is correct
  2. Check that the resource exists in your control plane
  3. Verify your API key has read permissions
  4. Ensure you’re connected to the correct control plane (hosted vs self-hosted)

Next Steps