Skip to content

Commit

Permalink
add team field to entity (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedwigz authored Sep 5, 2022
1 parent 306ed4d commit 259d816
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ description: |-
<!-- schema generated by tfplugindocs -->
## Schema

### Optional
### Required

- `base_url` (String)
- `client_id` (String)
- `secret` (String, Sensitive)

### Optional

- `base_url` (String)
- `token` (String, Sensitive)
1 change: 1 addition & 0 deletions docs/resources/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Port entity

- `identifier` (String) The identifier of the entity
- `relations` (Block Set) The other entities that are connected (see [below for nested schema](#nestedblock--relations))
- `team` (String) The team related to the entity

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions port/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
Identifier string `json:"identifier,omitempty"`
Title string `json:"title"`
Blueprint string `json:"blueprint"`
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 Down
9 changes: 9 additions & 0 deletions port/resource_port_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func newEntityResource() *schema.Resource {
Description: "The display name of the entity",
Required: true,
},
"team": {
Type: schema.TypeString,
Description: "The team related to the entity",
Optional: true,
},
"blueprint": {
Type: schema.TypeString,
Description: "The blueprint identifier the entity relates to",
Expand Down Expand Up @@ -154,6 +159,9 @@ 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)
}
rels := d.Get("relations").(*schema.Set)
relations := make(map[string]string)
for _, rel := range rels.List() {
Expand Down Expand Up @@ -186,6 +194,7 @@ 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)
d.Set("created_at", e.CreatedAt.String())
d.Set("created_by", e.CreatedBy)
d.Set("updated_at", e.UpdatedAt.String())
Expand Down
17 changes: 16 additions & 1 deletion port/resource_port_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccPortEntityUpdateProp(t *testing.T) {
resource "port-labs_entity" "microservice" {
title = "monolith"
blueprint = port-labs_blueprint.tf_bp.id
team = "Everyone"
properties {
name = "text"
value = "hedwig"
Expand All @@ -45,6 +46,7 @@ func TestAccPortEntityUpdateProp(t *testing.T) {
}
resource "port-labs_entity" "microservice" {
title = "monolith"
team = "Everyone"
blueprint = port-labs_blueprint.tf_bp.id
properties {
name = "text"
Expand All @@ -59,10 +61,23 @@ func TestAccPortEntityUpdateProp(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port-labs_entity.microservice", "title", "monolith"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "team", "Everyone"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "properties.0.name", "text"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "properties.0.value", "hedwig"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "blueprint", identifier),
),
},
{
Config: testAccActionConfigUpdate,
Check: resource.TestCheckResourceAttr("port-labs_entity.microservice", "properties.0.value", "hedwig2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port-labs_entity.microservice", "title", "monolith"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "team", "Everyone"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "properties.0.name", "text"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "properties.0.value", "hedwig2"),
resource.TestCheckResourceAttr("port-labs_entity.microservice", "blueprint", identifier),
),
},
},
})
Expand Down

0 comments on commit 259d816

Please sign in to comment.