Skip to content

Commit

Permalink
Merge pull request #34 from port-labs/PORT-3431-terraform-provider-ad…
Browse files Browse the repository at this point in the history
…d-support-for-items-in-array-property

Add support for blueprint items in array property
  • Loading branch information
talsabagport authored Apr 13, 2023
2 parents 4e8d5d3 + 7604044 commit debd295
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/resources/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Port action

- `blueprint_identifier` (String) The identifier of the blueprint
- `identifier` (String) The identifier of the action
- `invocation_method` (Block List, Min: 1, Max: 1) The methods the action is dispatched in. Supports WEBHOOK, KAFKA and GITHUB (see [below for nested schema](#nestedblock--invocation_method))
- `invocation_method` (Block List, Min: 1, Max: 1) The methods the action is dispatched in. Supports WEBHOOK, KAFKA, GITHUB and AZURE-DEVOPS (see [below for nested schema](#nestedblock--invocation_method))
- `title` (String) The display name of the action
- `trigger` (String) The type of the action, one of CREATE, DAY-2, DELETE

Expand All @@ -43,12 +43,14 @@ Required:
Optional:

- `agent` (Boolean) Relevant only when selecting type WEBHOOK. The flag that controls if the port execution agent will handle the action
- `azure_org` (String) Required when selecting type AZURE-DEVOPS. The Azure Devops org that the webhook belongs to
- `omit_payload` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to omit Port's payload from workflow's dispatch input
- `omit_user_inputs` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to omit user inputs from workflow's dispatch input
- `org` (String) Required when selecting type GITHUB. The GitHub org that the workflow belongs to
- `repo` (String) Required when selecting type GITHUB. The GitHub repository that the workflow belongs to
- `report_workflow_status` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to report the action status when the workflow completes
- `url` (String) Required when selecting type WEBHOOK. The URL to which the action is dispatched
- `webhook` (String) Required when selecting type AZURE-DEVOPS. The Azure Devops webhook id
- `workflow` (String) Required when selecting type GITHUB. The GitHub workflow id or the workflow file name


Expand Down
3 changes: 2 additions & 1 deletion docs/resources/blueprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Port blueprint

### Optional

- `calculation_properties` (Block Set) A set of properties that are calculated upon Entitys regular properties. (see [below for nested schema](#nestedblock--calculation_properties))
- `calculation_properties` (Block Set) A set of properties that are calculated upon entity's regular properties. (see [below for nested schema](#nestedblock--calculation_properties))
- `changelog_destination` (Block List, Max: 1) Blueprints changelog destination, Supports WEBHOOK and KAFKA (see [below for nested schema](#nestedblock--changelog_destination))
- `data_source` (String, Deprecated) The data source for entities of this blueprint
- `description` (String) The description of the blueprint
Expand Down Expand Up @@ -57,6 +57,7 @@ Optional:
- `enum_colors` (Map of String) A map of colors for the enum values
- `format` (String) The format of the Property
- `icon` (String) The icon of the property
- `items` (Map of String) A metadata of an array's items, in case the type is an array
- `required` (Boolean) Whether or not the property is required
- `spec` (String) The specification of the property, one of "async-api", "open-api", "embedded-url"

Expand Down
2 changes: 1 addition & 1 deletion port/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *PortClient) Authenticate(ctx context.Context, clientID, clientSecret st
url := "v1/auth/access_token"
resp, err := c.Client.R().
SetBody(map[string]interface{}{
"clientId": clientID,
"clientId": clientID,
"clientSecret": clientSecret,
}).
SetContext(ctx).
Expand Down
1 change: 1 addition & 0 deletions port/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type (
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Identifier string `json:"identifier,omitempty"`
Items map[string]any `json:"items,omitempty"`
Default interface{} `json:"default,omitempty"`
Icon string `json:"icon,omitempty"`
Format string `json:"format,omitempty"`
Expand Down
15 changes: 14 additions & 1 deletion port/resource_port_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func newBlueprintResource() *schema.Resource {
Required: true,
Description: "The type of the property",
},
"items": {
Type: schema.TypeMap,
Optional: true,
Description: "A metadata of an array's items, in case the type is an array",
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -186,7 +191,7 @@ func newBlueprintResource() *schema.Resource {
},
"calculation_properties": {
Type: schema.TypeSet,
Description: "A set of properties that are calculated upon Entitys regular properties.",
Description: "A set of properties that are calculated upon entity's regular properties.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Expand Down Expand Up @@ -329,6 +334,7 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
p["identifier"] = k
p["title"] = v.Title
p["type"] = v.Type
p["items"] = v.Items
p["description"] = v.Description
p["format"] = v.Format
p["icon"] = v.Icon
Expand Down Expand Up @@ -456,6 +462,13 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
if d, ok := p["default_items"]; ok && d != nil {
propFields.Default = d
}
if i, ok := p["items"]; ok && i != nil {
items := make(map[string]any)
for key, value := range i.(map[string]any) {
items[key] = value.(string)
}
propFields.Items = items
}
case "object":
if d, ok := p["default"]; ok && d.(string) != "" {
defaultObj := make(map[string]interface{})
Expand Down
12 changes: 9 additions & 3 deletions port/resource_port_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ func TestAccPortBlueprint(t *testing.T) {
properties {
identifier = "array"
type = "array"
items = {
type = "string"
format = "url"
}
title = "array"
default_items = [1, 2, 3]
default_items = ["https://getport.io", "https://app.getport.io"]
}
properties {
identifier = "text"
Expand All @@ -70,8 +74,10 @@ func TestAccPortBlueprint(t *testing.T) {
{
Config: testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.0", "1"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.#", "3"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.0", "https://getport.io"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.#", "2"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.items.type", "string"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.items.format", "url"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.1.default", "1"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.2.identifier", "text"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.2.enum.0", "a"),
Expand Down

0 comments on commit debd295

Please sign in to comment.