Pulumi
通过我们与Pulumi 的集成,您可以将基础设施的状态与 Port 中代表它们的实体结合起来。
通过使用 Port 的 Providers,您可以轻松地将 Port 与现有的 IaC 定义集成,Pulumi 提供的每个资源也可以使用相同的定义文件报告给软件目录。
💡 Pulumi Providers 常见用例
例如,我们的 Providers 可以轻松地将 IaC 定义中的数据直接填入软件目录:
- 报告云账户;
- 报告数据库;
- 报告lambdas和托管 Kubernetes 服务(EKS、AKS、GKE 等);
- 等等。
安装
To install and use Port's Pulumi provider, you will need to install the Pulumi CLI
To install the Pulumi provider, use your preferred method of installing Pulumi providers.
- Pip
- Yarn
- NPM
- GO
pip install port_pulumi
yarn add @port-labs/port
npm install @port-labs/port
go get github.com/port-labs/pulumi-port/sdk
Configuration
Please make sure to configure the clientId and secret to Port using the commands
Get your Port credentials
To get your Port API credentials go to your Port application, click on the ...
button in the top right corner, and select Credentials
. Here you can view and copy your CLIENT_ID
and CLIENT_SECRET
:
pulumi config set port:clientId <clientId>
pulumi config set port:secret <clientSecret> --secret
Pulumi 定义结构
Port 的 Pulumi Providers 支持以下资源将数据摄取到目录中:
`实体
实体 "资源定义了一个基本实体:
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Entity,BlueprintPropertiesArgs
entity = Entity(
"myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=BlueprintPropertiesArgs(),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {},
});
exports.title = entity.title;
// A Go Pulumi program
package main
import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/port-labs/pulumi-port/sdk/go/port"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
entity, err := port_pulumi.NewEntity(ctx, "myEntity", &port_pulumi.EntityArgs{
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{},
Relations: port.EntityRelations{},
})
if err != nil {
return err
}
ctx.Export("entityId", entity.ID())
return nil
})
}
以下参数是必需的:
- blueprint` - 据以创建此实体的蓝图的标识符;
- title: 实体的标题;
- 一个或多个
properties
模式定义。
还可以指定以下参数作为 port_entity
资源的一部分:
identifier
- 实体的标识符;- 如果没有 Provider,则会自动生成一个标识符。
team
- 拥有该实体的团队;teams
- 拥有该实体的团队的数组;run_id
- 创建实体的操作的运行 ID。
属性
模式
属性 "模式为实体的一个属性指定一个值。
定义
- String
- Number
- Boolean
- Object
- Array
- URL
- User
- Team
- Datetime
- Timer
- YAML
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myStringProp": "My string"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myStringProp: {
title: "My string",
required: false
}
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new port.Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myStringProp: {
title: "My string",
required: false
}
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myStringProp": pulumi.String("myStringValue"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
number_props={
"myNumberProp": 7,
}
),
relations=[])
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
numberProps: {
"myNumberProp": 7
}
},
relations: {}
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
numberProps: {
"myNumberProp": 7
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
NumberProps: pulumi.Float64Map{
"myNumberProp": pulumi.Float64(7),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
boolean_props={
"myBooleanProp": True
},
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
booleanProps: {
"myBooleanProp": true
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
booleanProps: {
"myBooleanProp": 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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
BooleanProps: pulumi.BoolMap{
"myBooleanProp": pulumi.Bool(true),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
object_props={
"myObjectProp": json.dumps({"hello": "world"})
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
objectProps: {
"myObjectProp": JSON.stringify({hello: "world"})
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
objectProps: {
"myObjectProp": JSON.stringify({hello: "world"})
}
},
relations: {},
});
exports.title = entity.title;
package main
import (
"encoding/json"
"github.com/port-labs/pulumi-port/sdk/go/port"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
obj := map[string]string{"hello": "world"}
objStr, err := json.Marshal(obj)
if err != nil {
panic(err)
}
pulumi.Run(func(ctx *pulumi.Context) error {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
ObjectProps: pulumi.StringMap{
"myObjectProperty": pulumi.String(objStr),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
array_props={
"myArrayProp": ["hello", "world"]
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
arrayProps: {
stringItems: {
"myArrayProp": ["a", "b", "c"]
}
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
arrayProps: {
stringItems: {
"myArrayProp": ["a", "b", "c"]
}
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
ArrayProps: port.EntityPropertiesArrayPropsArgs{
StringItems: pulumi.StringArrayMap{
"myArrayProp": pulumi.StringArray{
pulumi.String("hello"),
pulumi.String("world"),
pulumi.String("!"),
},
},
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myUrlProp": "https://example.com"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myUrlProp: "https://example.com",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myUrlProp: "https://example.com",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myUrlProp": pulumi.String("https://example.com"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myEmailProp": "[email protected]"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myEmailProp: "[email protected]",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myEmailProp: "[email protected]",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myEmailProp": pulumi.String("[email protected]"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myUserProp": "argo-admin"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myUserProp: "argo-admin",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myUserProp: "argo-admin",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myUserProp": pulumi.String("argo-admin"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myTeamProp": "My string"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myTeamProp: "argo-admins",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myTeamProp: "argo-admins",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myTeamProp": pulumi.String("argo-admins"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=port.EntityPropertiesArgs(
string_props={
"myDatetimeProp": "2022-04-18T11:44:15.345Z"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myDatetimeProp: "2022-04-18T11:44:15.345Z",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myDatetimeProp: "2022-04-18T11:44:15.345Z",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myDatetimeProp": pulumi.String("2022-04-18T11:44:15.345Z"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myTimerProp": "2022-04-18T11:44:15.345Z"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myTimerProp: "2022-04-18T11:44:15.345Z",
}
},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myTimerProp: "2022-04-18T11:44:15.345Z",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myTimerProp": pulumi.String("2022-04-18T11:44:15.345Z"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityPropertiesArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties=EntityPropertiesArgs(
string_props={
"myYAMLProp": "my: yaml"
}
),
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myYAMLProp: "my: yaml",
}
},
relations: [],
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {
stringProps: {
myYAMLProp: "my: yaml",
}
},
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{
StringProps: pulumi.StringMap{
"myYAMLProp": pulumi.String("my: yaml"),
},
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
以下参数是必需的:
name
-blueprint definition 中的属性名称;values
- 属性的值(用于非数组属性);items
- 属性值数组(用于数组属性)。
relations
模式
关系 "模式将目标实体映射到源实体定义:
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import json
import pulumi
from port_pulumi import Entity,EntityRelationsArgs
entity = Entity(
"myEntity",
identifier="myEntity",
title="My Entity",
blueprint="myBlueprint",
properties={},
relations=EntityRelationsArgs(
many_relations={
"myManyRelation": ["myTargetEntityIdentifier", "myTargetEntityIdentifier2"]
},
single_relations={
"mySingleRelation": "myTargetEntityIdentifier"
},
),
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {
singleRelations: {
myRelation: "myTargetEntityIdentifier"
},
manyRelations: {
myRelation: ["myTargetEntityIdentifier", "myTargetEntityIdentifier2"]
}
},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
identifier: "myEntity",
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {
singleRelations: {
myRelation: "myTargetEntityIdentifier"
},
manyRelations: {
myRelation: ["myTargetEntityIdentifier", "myTargetEntityIdentifier2"]
}
},
});
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 {
entity, err := port.NewEntity(ctx, "entity", &port.EntityArgs{
Identifier: pulumi.String("myEntity"),
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Relations: port.EntityRelationsArgs{
SingleRelations: pulumi.StringMap{
"mySingleRelation": pulumi.String("myTargetEntityIdentifier"),
},
ManyRelations: pulumi.StringArrayMap{
"myManyRelation": pulumi.StringArray{
pulumi.String("myTargetEntityIdentifier"),
pulumi.String("myTargetEntityIdentifier2"),
},
},
},
Properties: port.EntityPropertiesArgs{
// ..properties
},
})
ctx.Export("entity", entity.Title)
if err != nil {
return err
}
return nil
})
}
以下参数是必需的:
name
-relation 在蓝图定义中的名称;identifier
- 目标实体的标识符。
使用 Providers 被用于数据
要使用 Provider 将数据引用到软件目录,您需要用首选语言创建一个 port.Entity
资源实例:
- Create
- Update
- Delete
要使用 Pulumi 创建实体,请用您喜欢的语言创建一个文件,并插入以下内容:
- Python
- TypeScript
- JavaScript
- GO
"""A Python Pulumi program"""
import pulumi
from port_pulumi import Entity
entity = Entity(
"myEntity",
title="My Entity",
blueprint="myBlueprint",
properties={},
relations={}
)
import * as pulumi from "@pulumi/pulumi";
import { Entity } from "@port-labs/port";
export const entity = new Entity("myEntity", {
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {},
});
"use strict";
const pulumi = require("@pulumi/pulumi");
const port = require("@port-labs/port");
const entity = new Entity("myEntity", {
title: "My Entity",
blueprint: "myBlueprint",
properties: {},
relations: {},
});
exports.title = entity.title;
// A Go Pulumi program
package main
import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/port-labs/pulumi-port/sdk/go/port"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
entity, err := port_pulumi.NewEntity(ctx, "myEntity", &port_pulumi.EntityArgs{
Title: pulumi.String("My Entity"),
Blueprint: pulumi.String("myBlueprint"),
Properties: port.EntityPropertiesArgs{},
Relations: port.EntityRelationsArgs{},
})
if err != nil {
return err
}
ctx.Export("entityId", entity.ID())
return nil
})
}
然后运行以下命令应用更改并更新目录:
pulumi up -y
运行这些命令后,您将看到目录已更新为新实体。
要使用 Pulumi 更新实体,请更新代码文件中现有的 port.Entity
资源,然后运行 pulumi up -y
。
也可以使用 Port 的 Provider 开始管理现有实体,要开始管理现有实体,请在代码文件中添加新的 port.Entity
资源,并进行所需的更改
关于向 Providers 添加现有实体的重要说明:
- 指定实体的 "标识符 "非常重要,否则 Pulumi 将创建一个带有自动生成的标识符的新实体。
- Port 的 Pulumi Providers 使用create/override 策略,这意味着对于现有实 体,资源定义中未定义的任何属性都将被空值覆盖。
要使用 Pulumi 删除实体,只需删除代码文件中定义的 port.Entity
资源,然后运行 pulumi up -y
。