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_environmentcontrolplane_projectcontrolplane_teamcontrolplane_agentcontrolplane_skillcontrolplane_policy
Data Source Arguments
All data sources require the resourceid:
Data Source Examples
controlplane_environment
Look up an existing environment by ID:id- Environment IDname- Environment namedisplay_name- Display namedescription- Environment descriptiontags- List of tagsconfiguration- Environment configuration (JSON)execution_environment- Execution settings (JSON)created_at- Creation timestampupdated_at- Last update timestamp
controlplane_project
Look up an existing project:id- Project IDname- Project namekey- Project keydescription- Project descriptiongoals- Project goalsvisibility- Visibility settingmetadata- Project metadata (JSON)created_at- Creation timestampupdated_at- Last update timestamp
controlplane_team
Look up an existing team:id- Team IDname- Team namedescription- Team descriptionruntime- Runtime type (default or claude_code)configuration- Team configuration (JSON)capabilities- List of capabilitiescreated_at- Creation timestampupdated_at- Last update timestamp
controlplane_agent
Look up an existing agent:id- Agent IDname- Agent namedescription- Agent descriptionmodel_id- LLM modelruntime- Runtime typeteam_id- Team IDllm_config- LLM configuration (JSON)configuration- Agent configuration (JSON)capabilities- List of capabilitiesstatus- Agent statuscreated_at- Creation timestampupdated_at- Last update timestamp
controlplane_skill
Look up an existing skill:id- Skill IDname- Skill namedescription- Skill descriptiontype- Skill type (shell, file_system, docker, custom)enabled- Whether skill is enabledconfiguration- Skill configuration (JSON)created_at- Creation timestampupdated_at- Last update timestamp
controlplane_policy
Look up an existing policy:id- Policy IDname- Policy namedescription- Policy descriptionenabled- Whether policy is enabledpolicy_content- OPA Rego policy contenttags- List of tagscreated_at- Creation timestampupdated_at- Last update timestamp
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. Usejsondecode() 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:- Verify the resource ID is correct
- Check that the resource exists in your control plane
- Verify your API key has read permissions
- Ensure you’re connected to the correct control plane (hosted vs self-hosted)
Next Steps
- Resources Documentation - Create and manage resources
- Examples - Complete end-to-end examples
- Provider Configuration - Configuration options