You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/python-sdk/topics/object_file.mdx
+37-22Lines changed: 37 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
title: Manage data with Object Files
3
3
---
4
4
5
-
# Manage data with Object filess
5
+
# Manage data with Object files
6
6
7
7
## Introduction
8
8
9
-
An Object file is a YAML file that allows you to manage data to be loaded in Infrahub based on your own custom schema.
9
+
An Object file is a YAML file that allows you to manage data to be loaded in Infrahub based on your own custom schema. It provides a declarative way to define and manage resources in your Infrahub instance.
10
10
11
-
Object files work well for models that don't change too often and/or that needs to be tracked in Git: Examples: Groups, tags, Users etc ..
11
+
Object files work well for models that don't change too often and/or that need to be tracked in Git. Examples include: Groups, tags, Users, etc.
12
12
Below is an example of an Object file that defines tags (`BuiltinTag`).
13
13
14
14
```yaml
@@ -23,22 +23,22 @@ spec:
23
23
- name: Red
24
24
```
25
25
26
-
Object files are meant to be used in an idempotent way and as such they would work better for models with a Human Friendly ID (hfid) defined.
26
+
Object files are meant to be used in an idempotent way and as such they work better for models with a Human Friendly ID (HFID) defined. An HFID is a unique identifier that makes it easier to reference objects across different files and operations.
27
27
28
28
## Load Object files into Infrahub
29
29
30
-
Object files can be loaded into Infrahub using the `infrahub load object` command.
30
+
Object files can be loaded into Infrahub using the `infrahub object load` command.
31
31
32
32
```bash
33
33
infrahub object load <path_to_object_file>
34
34
```
35
35
36
36
Multiple object files can be loaded at once by specifying the path to multiple files or by specifying a directory.
37
37
38
-
The object `object load` command will create/update the objects using an `Upsert` operation. All objects previously loaded will NOT be deleted in the Infrahub instance.
39
-
Also, if some objects present in different files are identical are dependent on each other, the `object load` command will NOT calculate the dependencies between the objects and as such it's the reponsability of the users to execute the command in the right order.
38
+
The `object load` command will create/update the objects using an `Upsert` operation. All objects previously loaded will NOT be deleted in the Infrahub instance.
39
+
Also, if some objects present in different files are identical and dependent on each other, the `object load` command will NOT calculate the dependencies between the objects and as such it's the responsibility of the users to execute the command in the right order.
40
40
41
-
### Validate the format of the object facilitates
41
+
### Validate the format of object files
42
42
43
43
The object file can be validated using the `infrahub object validate` command.
All object files must start with the following format, all other format will be automatically ignored
51
+
All object files must start with the following format, all other formats will be automatically ignored.
52
52
Each file is intended for one specific top level kind, but one file can include multiple nested objects of any kind.
53
-
The kind of the top level object must be defined in spec/kind
53
+
The kind of the top level object must be defined in spec/kind.
54
54
55
55
```yaml
56
56
---
@@ -62,12 +62,12 @@ spec:
62
62
- [...]
63
63
```
64
64
65
-
> Multiple documents in a single Yaml file are also supported, each document will be loaded as a separately. Documents are separated by `---`
65
+
> Multiple documents in a single YAML file are also supported, each document will be loaded separately. Documents are separated by `---`
66
66
67
67
### Relationship of cardinality One
68
68
69
69
A relationship of cardinality one can either reference an existing node via its HFID or create a new node if it doesn't exist.
70
-
In the example below, both `site` and `primary_ip` are relationship of cardinality one.
70
+
In the example below, both `site` and `primary_ip` are relationships of cardinality one.
71
71
72
72
```yaml
73
73
---
@@ -85,12 +85,12 @@ spec:
85
85
86
86
### Relationship of cardinality Many
87
87
88
-
A relationship of cardinality many can reference existing nodes via their HFID or define nested objects
88
+
A relationship of cardinality many can reference existing nodes via their HFID or define nested objects.
89
89
90
90
#### Existing nodes referenced by their HFID
91
91
92
92
Existing nodes can be referenced by their HFID in string format or in list format.
93
-
In the example below, both `best_friends` and `tags` are relationship of cardinality many.
93
+
In the example below, both `best_friends` and `tags` are relationships of cardinality many.
94
94
95
95
> An HFID is composed of a single value, it's possible to use a string instead of a list
96
96
@@ -103,7 +103,7 @@ spec:
103
103
data:
104
104
- name: Mike Johnson
105
105
height: 175
106
-
best_friends: # Relationship of cardinality many that referenced existing nodes based on their HFID
106
+
best_friends: # Relationship of cardinality many that references existing nodes based on their HFID
107
107
- [Jane Smith, Max]
108
108
- [Sarah Williams, Charlie]
109
109
tags:
@@ -113,17 +113,17 @@ spec:
113
113
114
114
#### Nested Objects
115
115
116
-
When defining nested objects, the node will be automatically created if it doesn't exist and if their relationship between the parent object and the nested object it will be automatically inserted.
117
-
For example, in the example below, the `owner` of a `TestingDog` doesn't need to be specify because it will be automatically inserted.
116
+
When defining nested objects, the node will be automatically created if it doesn't exist and if the relationship between the parent object and the nested object exists, it will be automatically inserted.
117
+
For example, in the example below, the `owner` of a `TestingDog` doesn't need to be specified because it will be automatically inserted.
118
118
119
-
For 2 different syntaxes are supported:
119
+
Two different syntax are supported:
120
120
121
-
- A dictionnary with multiple value under data
121
+
- A dictionary with multiple values under data
122
122
- A list of objects
123
123
124
124
##### Nested objects as a dictionary
125
125
126
-
In the example below, `tags` is a relationship of cardinality many that is defined as a dictionnary with multiple values under data.
126
+
In the example below, `tags` is a relationship of cardinality many that is defined as a dictionary with multiple values under data.
127
127
128
128
> The kind is optional here because there is only one option possible (not a generic)
129
129
@@ -149,7 +149,7 @@ For more complex cases, the list of objects format is more flexible.
149
149
##### Nested objects as a list of objects
150
150
151
151
In the example below, `animals` is a relationship of cardinality many that is defined as a list of objects.
152
-
Each object must contains a `data` key and each object can also define a specific `kind`.
152
+
Each object must contain a `data` key and each object can also define a specific `kind`.
153
153
154
154
> If the kind is not specified, it will be inferred from schema
155
155
@@ -177,4 +177,19 @@ spec:
177
177
178
178
### Support for Metadata
179
179
180
-
Please stay tuned, the Object file does not support metadata yet, neither on attribute or relationship.
180
+
Metadata support is planned for future releases. Currently, the Object file does not support metadata on attributes or relationships.
181
+
182
+
## Troubleshooting
183
+
184
+
### Common Issues
185
+
186
+
1. **Objects not being created**: Ensure that the YAML syntax is correct and that the file follows the required format.
187
+
2. **Dependency errors**: When objects depend on each other, load them in the correct order (dependencies first).
188
+
3. **Validation errors**: Use the `infrahub object validate` command to check for syntax errors before loading.
189
+
190
+
### Best Practices
191
+
192
+
1. Use Human Friendly IDs (HFIDs) for all objects to ensure consistent referencing.
193
+
2. Keep object files organized by model type or purpose.
194
+
3. Validate object files before loading them into production environments.
195
+
4. Use comments in your YAML files to document complex relationships or dependencies.
0 commit comments