Object
Object is a data type used to save object definitions in JSON.
๐ก Common object usageโ
The object property type can be used to store any key/value based data, for example:
- Configurations.
- Tags.
- HTTP responses.
- Dictionaries/Hash maps.
In this live demo example, we can see the Tags
object property. ๐ฌ
API definitionโ
- Basic
- Array
{
"myObjectProp": {
"title": "My object",
"icon": "My icon",
"description": "My object property",
"type": "object",
"default": {
"myKey": "myValue"
}
}
}
{
"myObjectArray": {
"title": "My object array",
"icon": "My icon",
"description": "My object array",
"type": "array",
"items": {
"type": "object"
}
}
}
Check out Port's API reference to learn more.
Terraform definitionโ
- Basic
- Array
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
object_props = {
"myObjectProp" = {
title = "My object"
icon = "My icon"
description = "My object property"
default = jsonencode({"myKey" = "myValue"})
}
}
}
}
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties {
identifier = "myObjectArray"
title = "My object array"
required = false
type = "array"
items = {
type = "object"
}
}
}
Pulumi definitionโ
- Basic
- Array - coming soon
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Blueprint,BlueprintPropertiesArgs,BlueprintPropertiesObjectPropsArgs
blueprint = Blueprint(
"myBlueprint",
identifier="myBlueprint",
title="My Blueprint",
properties=BlueprintPropertiesArgs(
object_props=BlueprintPropertiesObjectPropsArgs(
title="My object", required=False
)
),
relations={},
)
import * as pulumi from "@pulumi/pulumi";
import * as port from "@port-labs/port";
export const blueprint = new port.Blueprint("myBlueprint", {
identifier: "myBlueprint",
title: "My Blueprint",
properties: {
objectProps: {
myObjectProp: {
title: "My object",
required: true,
},
},
},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new port.Blueprint("myBlueprint", {
title: "My Blueprint",
identifier: "myBlueprint",
properties: {
objectProps: {
myObjectProp: {
title: "My object",
required: true,
},
},
},
relations: {},
});
exports.title = entity.title;
package main
import (
"github.com/port-labs/pulumi-port/sdk/go/port"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
blueprint, err := port.NewBlueprint(ctx, "myBlueprint", &port.BlueprintArgs{
Identifier: pulumi.String("myBlueprint"),
Title: pulumi.String("My Blueprint"),
Properties: port.BlueprintPropertiesArgs{
ObjectProps: port.BlueprintPropertiesObjectPropsMap{
"myObjectProp": port.BlueprintPropertiesObjectPropsArgs{
Title: pulumi.String("My object"),
Required: pulumi.Bool(false),
},
},
},
})
ctx.Export("blueprint", blueprint.Title)
if err != nil {
return err
}
return nil
})
}
Validate objectโ
Object validations support the following operators:
properties
- which keys must appear and what their type should be;additionalProperties
- are keys not defined inproperties
allowed and what their type should be;patternProperties
- which regex pattern should properties follow
tip
Object validations follow the JSON schema model, refer to the JSON schema docs to learn about all of the available validations
- Basic
- Array
- Terraform - coming soon
{
"myObjectProp": {
"title": "My object",
"icon": "My icon",
"description": "My object property",
"type": "object",
"properties": {
"myRequiredProp": { "type": "number" }
},
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "number" }
},
"additionalProperties": true
}
}
{
"myObjectArray": {
"title": "My object array",
"icon": "My icon",
"description": "My object array",
"type": "array",
"items": {
"type": "object",
"properties": {
"myRequiredProp": { "type": "number" }
},
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "number" }
},
"additionalProperties": true
}
}
}