Array
Array is a data type used to save lists of data.
💡 Common array usage
The array property type can be used to store any list of data, for example:
- Used packages
- Dependencies
- Badges
In this live demo example, we can see the Monitor Tooling
array property. 🎬
API definition
{
"myArrayProp": {
"title": "My array",
"icon": "My icon",
"description": "My array property",
"type": "array",
"default": [1, 2, 3]
}
}
Check out Port's API reference to learn more.
Terraform definition
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
array_props = {
"myArrayProp" = {
title = "My array"
required = true
}
}
}
}
info
To set the type of an array property, you need to use the <type>_items
property type.
For example, to set an array of strings, you need to use the string_items
property type.
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
array_props = {
"myArrayProp" = {
title = "My array"
required = true
string_items = {} # You can also set here default values
}
}
}
}
We currently support the following types of array items: string_items
, number_items
, boolean_items
, object_items
.
Pulumi definition
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Blueprint,BlueprintPropertiesArgs,BlueprintPropertyArgs
blueprint = Blueprint(
"myBlueprint",
identifier="myBlueprint",
title="My Blueprint",
properties=BlueprintPropertiesArgs(
array_props={
"myArrayProp": BlueprintPropertyArgs(
title="My array", required=True,
)
}
),
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: {
array_props: {
myArrayProp: {
title: "My array",
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: {
array_props: {
myArrayProp: {
title: "My array",
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{
ArrayProps: port.BlueprintPropertiesArrayPropsMap{
"myArrayProp": port.BlueprintPropertyArgs{
Title: pulumi.String("My array"),
Required: pulumi.Bool(true),
},
},
},
})
ctx.Export("blueprint", blueprint.Title)
if err != nil {
return err
}
return nil
})
}
Validate array
Array validations support the following operators:
minItems
maxItems
uniqueItems
tip
Array validations follow the JSON schema model, refer to the JSON schema docs to learn about all of the available validations
- Basic
- Terraform
{
"myArrayProp": {
"title": "My array",
"icon": "My icon",
"description": "My array property",
"type": "array",
"minItems": 0,
"maxItems": 5,
"uniqueItems": false
}
}
resource "port_blueprint" "myBlueprint" {
# ...blueprint properties
properties = {
array_props = {
"myArrayProp" = {
title = "My array"
required = true
min_items = 0
max_items = 5
}
}
}
}