YAML Import
YAML is the recommended format for importing large datasets or initial infrastructure definitions.YAML Structure
Define objects in YAML with their attributes and relationships:Import Command
Useinfrahubctl to import YAML files:
Import Options
| Option | Description |
|---|---|
--branch | Target branch (defaults to main) |
--update | Update existing objects instead of creating new ones |
--validate-only | Validate without importing |
--dry-run | Show what would be imported |
Handling Relationships
You can reference related objects by: Name reference (if unique):Many Relationships
For cardinality MANY relationships, use a list:GraphQL Import
For programmatic imports or integration with external systems, use GraphQL mutations.Single Object Import
Batch Import with Aliases
Import multiple objects in one request using aliases:Variables for Dynamic Import
Use variables for reusable import scripts:Python SDK Import
The Python SDK provides a programmatic interface for importing data from external sources.Basic Import
Import with Relationships
Batch Import with Error Handling
Import from CSV
Import from JSON
Import from External Systems
Import from NetBox
Import from Git Repository
Validation During Import
Infrahub validates all imported data against schema constraints:- Required attributes must have values
- Unique attributes are checked for duplicates
- Regex patterns validate string formats
- Relationship cardinality ensures correct peer counts
- Type validation ensures values match attribute types
Handling Validation Errors
Validation errors include the field path and error message:Performance Tips
- Batch mutations: Use GraphQL aliases to create multiple objects in one request
- Reuse client connections: Don’t create a new client for each object
- Parallel imports: Use
asyncio.gather()for concurrent SDK imports - Use YAML for bulk: YAML import is optimized for large datasets
- Fetch references once: Cache frequently referenced objects (sites, types, etc.)
Next Steps
- Use Resource Manager for IP and VLAN allocation
- Organize objects with Groups
- Apply common settings with Profiles