Skip to content

Commit

Permalink
taking the first element in the array of teams (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsinai authored Jan 24, 2023
1 parent d3803f1 commit 8a32e84
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 95 deletions.
15 changes: 0 additions & 15 deletions docs/resources/blueprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Port blueprint
- `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
- `formula_properties` (Block Set) A property that is calculated by a formula (see [below for nested schema](#nestedblock--formula_properties))
- `mirror_properties` (Block Set) When two Blueprints are connected via a Relation, a new set of properties becomes available to Entities in the source Blueprint. (see [below for nested schema](#nestedblock--mirror_properties))
- `relations` (Block Set) The blueprints that are connected to this blueprint (see [below for nested schema](#nestedblock--relations))

Expand Down Expand Up @@ -71,20 +70,6 @@ Optional:

- `url` (String) Required when selecting type WEBHOOK. The URL to which the changelog is dispatched


<a id="nestedblock--formula_properties"></a>
### Nested Schema for `formula_properties`

Required:

- `formula` (String) The path of the realtions towards the property
- `identifier` (String) The identifier of the property

Optional:

- `title` (String) The name of this property


<a id="nestedblock--mirror_properties"></a>
### Nested Schema for `mirror_properties`

Expand Down
25 changes: 9 additions & 16 deletions port/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
Identifier string `json:"identifier,omitempty"`
Title string `json:"title"`
Blueprint string `json:"blueprint"`
Team string `json:"team,omitempty"`
Team []string `json:"team,omitempty"`
Properties map[string]interface{} `json:"properties"`
Relations map[string]string `json:"relations"`
// TODO: add the rest of the fields.
Expand All @@ -48,12 +48,6 @@ type (
Path string `json:"path,omitempty"`
}

BlueprintFormulaProperty struct {
Identifier string `json:"identifier,omitempty"`
Title string `json:"title,omitempty"`
Formula string `json:"formula,omitempty"`
}

BlueprintSchema struct {
Properties map[string]BlueprintProperty `json:"properties"`
Required []string `json:"required,omitempty"`
Expand All @@ -73,15 +67,14 @@ type (

Blueprint struct {
Meta
Identifier string `json:"identifier,omitempty"`
Title string `json:"title"`
Icon string `json:"icon"`
Description string `json:"description"`
Schema BlueprintSchema `json:"schema"`
FormulaProperties map[string]BlueprintFormulaProperty `json:"formulaProperties"`
MirrorProperties map[string]BlueprintMirrorProperty `json:"mirrorProperties"`
ChangelogDestination *ChangelogDestination `json:"changelogDestination,omitempty"`
Relations map[string]Relation `json:"relations"`
Identifier string `json:"identifier,omitempty"`
Title string `json:"title"`
Icon string `json:"icon"`
Description string `json:"description"`
Schema BlueprintSchema `json:"schema"`
MirrorProperties map[string]BlueprintMirrorProperty `json:"mirrorProperties"`
ChangelogDestination *ChangelogDestination `json:"changelogDestination,omitempty"`
Relations map[string]Relation `json:"relations"`
}

Action struct {
Expand Down
53 changes: 1 addition & 52 deletions port/resource_port_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,6 @@ func newBlueprintResource() *schema.Resource {
},
Optional: true,
},
"formula_properties": {
Type: schema.TypeSet,
Description: "A property that is calculated by a formula",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Type: schema.TypeString,
Required: true,
Description: "The identifier of the property",
},
"title": {
Type: schema.TypeString,
Optional: true,
Description: "The name of this property",
},
"formula": {
Type: schema.TypeString,
Required: true,
Description: "The path of the realtions towards the property",
},
},
},
Optional: true,
},
"changelog_destination": {
Type: schema.TypeList,
MinItems: 1,
Expand Down Expand Up @@ -279,10 +255,7 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
id := (i.(map[string]interface{}))["identifier"].(string)
return schema.HashString(id)
}}
formula_properties := schema.Set{F: func(i interface{}) int {
id := (i.(map[string]interface{}))["identifier"].(string)
return schema.HashString(id)
}}

mirror_properties := schema.Set{F: func(i interface{}) int {
id := (i.(map[string]interface{}))["identifier"].(string)
return schema.HashString(id)
Expand Down Expand Up @@ -334,17 +307,8 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) {
mirror_properties.Add(p)
}

for k, v := range b.FormulaProperties {
p := map[string]interface{}{}
p["identifier"] = k
p["title"] = v.Title
p["formula"] = v.Formula
formula_properties.Add(p)
}

d.Set("properties", &properties)
d.Set("mirror_properties", &mirror_properties)
d.Set("formula_properties", &formula_properties)
}

func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
Expand All @@ -362,7 +326,6 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
b.Description = d.Get("description").(string)
props := d.Get("properties").(*schema.Set)
mirror_props := d.Get("mirror_properties").(*schema.Set)
formula_props := d.Get("formula_properties").(*schema.Set)

if changelogDestination, ok := d.GetOk("changelog_destination"); ok {
if b.ChangelogDestination == nil {
Expand Down Expand Up @@ -461,19 +424,6 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {
mirror_properties[p["identifier"].(string)] = propFields
}

formula_properties := make(map[string]cli.BlueprintFormulaProperty, formula_props.Len())
for _, prop := range formula_props.List() {
p := prop.(map[string]interface{})
propFields := cli.BlueprintFormulaProperty{}
if t, ok := p["title"]; ok && t != "" {
propFields.Title = t.(string)
}
if f, ok := p["formula"]; ok && f != "" {
propFields.Formula = f.(string)
}
formula_properties[p["identifier"].(string)] = propFields
}

rels := d.Get("relations").(*schema.Set)
relations := make(map[string]cli.Relation, props.Len())
for _, rel := range rels.List() {
Expand All @@ -497,7 +447,6 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) {

b.Schema = cli.BlueprintSchema{Properties: properties, Required: required}
b.Relations = relations
b.FormulaProperties = formula_properties
b.MirrorProperties = mirror_properties
return b, nil
}
Expand Down
10 changes: 0 additions & 10 deletions port/resource_port_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ func TestAccPortBlueprintUpdate(t *testing.T) {
b = "blue"
}
}
formula_properties {
identifier = "formula_id"
formula = "{{$identifier}}formula"
}
}
`, identifier)
var testAccActionConfigUpdate = fmt.Sprintf(`
Expand All @@ -203,10 +199,6 @@ func TestAccPortBlueprintUpdate(t *testing.T) {
type = "number"
title = "num"
}
formula_properties {
identifier = "formula_id"
formula = "{{$identifier}}formula-updated"
}
}
`, identifier)
var testAccActionConfigUpdateAgain = fmt.Sprintf(`
Expand All @@ -233,7 +225,6 @@ func TestAccPortBlueprintUpdate(t *testing.T) {
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.0.title", "text"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.0.required", "true"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.0.icon", "Terraform"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "formula_properties.0.formula", "{{$identifier}}formula"),
),
},
{
Expand All @@ -243,7 +234,6 @@ func TestAccPortBlueprintUpdate(t *testing.T) {
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.0.title", "num"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.1.title", "text"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "properties.1.required", "false"),
resource.TestCheckResourceAttr("port-labs_blueprint.microservice1", "formula_properties.0.formula", "{{$identifier}}formula-updated"),
),
},
{
Expand Down
7 changes: 5 additions & 2 deletions port/resource_port_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ func entityResourceToBody(d *schema.ResourceData, bp *cli.Blueprint) (*cli.Entit
e.Title = d.Get("title").(string)
e.Blueprint = d.Get("blueprint").(string)
if team, ok := d.GetOk("team"); ok {
e.Team = team.(string)
teams := []string{team.(string)}
e.Team = teams
}
rels := d.Get("relations").(*schema.Set)
relations := make(map[string]string)
Expand Down Expand Up @@ -199,7 +200,9 @@ func writeEntityComputedFieldsToResource(d *schema.ResourceData, e *cli.Entity)
func writeEntityFieldsToResource(d *schema.ResourceData, e *cli.Entity) {
d.SetId(e.Identifier)
d.Set("title", e.Title)
d.Set("team", e.Team)
if len(e.Team) > 0 {
d.Set("team", e.Team[0])
}
d.Set("created_at", e.CreatedAt.String())
d.Set("created_by", e.CreatedBy)
d.Set("updated_at", e.UpdatedAt.String())
Expand Down

0 comments on commit 8a32e84

Please sign in to comment.