Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions docs/docs/python-sdk/topics/object_file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ apiVersion: infrahub.app/v1
kind: Object
spec:
kind: <NamespaceName>
strategy: <normal|range_expand> # Optional, defaults to normal
parameters:
expand_range: <boolean> # Optional, defaults to false
data:
- [...]
```

> Multiple documents in a single YAML file are also supported, each document will be loaded separately. Documents are separated by `---`

### Data Processing Strategies
### Data Processing Parameters

The `strategy` field controls how the data in the object file is processed before loading into Infrahub:
The `parameters` field controls how the data in the object file is processed before loading into Infrahub:

| Strategy | Description | Default |
|----------|-------------|---------|
| `normal` | No data manipulation is performed. Objects are loaded as-is. | Yes |
| `range_expand` | Range patterns (e.g., `[1-5]`) in string fields are expanded into multiple objects. | No |
| Parameter | Description | Default |
|-----------|-------------|---------|
| `expand_range` | When set to `true`, range patterns (e.g., `[1-5]`) in string fields are expanded into multiple objects. | `false` |

When `strategy` is not specified, it defaults to `normal`.
When `expand_range` is not specified, it defaults to `false`.

### Relationship of cardinality one

Expand Down Expand Up @@ -210,15 +210,16 @@ Metadata support is planned for future releases. Currently, the Object file does

## Range Expansion in Object Files

The Infrahub Python SDK supports **range expansion** for string fields in object files when the `strategy` is set to `range_expand`. This feature allows you to specify a range pattern (e.g., `[1-5]`) in any string value, and the SDK will automatically expand it into multiple objects during validation and processing.
The Infrahub Python SDK supports **range expansion** for string fields in object files when the `parameters > expand_range` is set to `true`. This feature allows you to specify a range pattern (e.g., `[1-5]`) in any string value, and the SDK will automatically expand it into multiple objects during validation and processing.

```yaml
---
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: BuiltinLocation
strategy: range_expand # Enable range expansion
parameters:
expand_range: true # Enable range expansion
data:
- name: AMS[1-3]
type: Country
Expand All @@ -237,7 +238,8 @@ spec:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
type: Country
Expand All @@ -259,7 +261,8 @@ This will expand to:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
description: Datacenter [A-C]
Expand Down Expand Up @@ -287,7 +290,8 @@ If you use ranges of different lengths in multiple fields:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
description: "Datacenter [10-15]"
Expand Down
7 changes: 7 additions & 0 deletions infrahub_sdk/spec/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

from pydantic import BaseModel


class InfrahubObjectParameters(BaseModel):
expand_range: bool = False
Loading