Skip to content

Commit

Permalink
add description prop to relation model (#179)
Browse files Browse the repository at this point in the history
* add description prop to relation model
  • Loading branch information
itamar-smirra-port authored Sep 1, 2024
1 parent 757b655 commit f12ec6b
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 43 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Setting up your developer workspace:

* Have [golang](https://go.dev/doc/install) installed
* Have `wget` installed
* Run `make dev-setup`

## Verifying your contribution:
Expand All @@ -28,7 +29,7 @@ Expose the following environment variables:

`PORT_CLIENT_SECRET`

`PORT_BASE_URL` - Optional
`PORT_BASE_URL` - Optional, Port API url

Then run:

Expand Down
2 changes: 0 additions & 2 deletions docs/data-sources/port_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,3 @@ Read-Only:
- `identifier` (String)
- `level` (String)
- `status` (String)


11 changes: 9 additions & 2 deletions docs/resources/port_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ Optional:
- `entity_deleted_event` (Attributes) Entity deleted event trigger (see [below for nested schema](#nestedatt--automation_trigger--entity_deleted_event))
- `entity_updated_event` (Attributes) Entity updated event trigger (see [below for nested schema](#nestedatt--automation_trigger--entity_updated_event))
- `jq_condition` (Attributes) JQ condition for automation trigger (see [below for nested schema](#nestedatt--automation_trigger--jq_condition))
- `run_updated_event` (Attributes) Run updated event trigger (see [below for nested schema](#nestedatt--automation_trigger--run_updated_event))
- `timer_property_expired_event` (Attributes) Timer property expired event trigger (see [below for nested schema](#nestedatt--automation_trigger--timer_property_expired_event))

<a id="nestedatt--automation_trigger--any_entity_change_event"></a>
Expand Down Expand Up @@ -389,6 +390,14 @@ Optional:
- `combinator` (String) The combinator of the condition


<a id="nestedatt--automation_trigger--run_updated_event"></a>
### Nested Schema for `automation_trigger.run_updated_event`

Required:

- `action_identifier` (String) The action identifier of the updated run


<a id="nestedatt--automation_trigger--timer_property_expired_event"></a>
### Nested Schema for `automation_trigger.timer_property_expired_event`

Expand Down Expand Up @@ -685,5 +694,3 @@ Optional:
- `headers` (Map of String) The HTTP headers for invoking the action. They should be encoded as a key-value object to a string using [jsonencode](https://developer.hashicorp.com/terraform/language/functions/jsonencode). Learn about how to [define the action payload](https://docs.getport.io/create-self-service-experiences/setup-backend/#define-the-actions-payload).
- `method` (String) The HTTP method to invoke the action
- `synchronized` (String) Synchronize the action


2 changes: 0 additions & 2 deletions docs/resources/port_action_permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,3 @@ Optional:
- `roles` (List of String) The roles with execution permission
- `teams` (List of String) The teams with execution permission
- `users` (List of String) The users with execution permission


2 changes: 0 additions & 2 deletions docs/resources/port_aggregation_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,5 +645,3 @@ Optional:

- `average_of` (String) The time periods to calculate the average of, e.g. hour, day, week, month
- `measure_time_by` (String) The property name on which to calculate the the time periods, e.g. $createdAt, $updated_at or any other date property


3 changes: 1 addition & 2 deletions docs/resources/port_blueprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ Required:

Optional:

- `description` (String) The description of the relation
- `many` (Boolean) The many of the relation
- `required` (Boolean) The required of the relation
- `title` (String) The title of the relation
Expand All @@ -499,5 +500,3 @@ Required:
Optional:

- `agent` (Boolean) The agent of the webhook changelog destination


2 changes: 0 additions & 2 deletions docs/resources/port_blueprint_permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,3 @@ Optional:
- `roles` (List of String) Roles with update specific relation permissions
- `teams` (List of String) Teams with update specific relation permissions
- `users` (List of String) Users with update specific relation permissions


2 changes: 0 additions & 2 deletions docs/resources/port_entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ Optional:

- `many_relations` (Map of List of String) The many relation of the entity
- `single_relations` (Map of String) The single relation of the entity


2 changes: 0 additions & 2 deletions docs/resources/port_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,3 @@ Required:
Optional:

- `agent` (Boolean) The agent of the webhook changelog destination


2 changes: 0 additions & 2 deletions docs/resources/port_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,3 @@ terraform import port_page.home_page "\$home"
- `id` (String) The ID of this resource.
- `updated_at` (String) The last update date of the page
- `updated_by` (String) The last updater of the page


2 changes: 0 additions & 2 deletions docs/resources/port_page_permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,3 @@ Optional:
- `roles` (List of String) The roles with read permission
- `teams` (List of String) The teams with read permission
- `users` (List of String) The users with read permission


2 changes: 0 additions & 2 deletions docs/resources/port_scorecard.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,3 @@ Required:

- `color` (String) The color of the level
- `title` (String) The title of the level


2 changes: 0 additions & 2 deletions docs/resources/port_team.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ Team resource
- `id` (String) The ID of this resource.
- `provider_name` (String) The provider of the team
- `updated_at` (String) The last update date of the team


2 changes: 0 additions & 2 deletions docs/resources/port_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ Optional:
- `signature_algorithm` (String) The signature algorithm of the webhook
- `signature_header_name` (String) The signature header name of the webhook
- `signature_prefix` (String) The signature prefix of the webhook


11 changes: 6 additions & 5 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,12 @@ type (
}

Relation struct {
Identifier *string `json:"identifier,omitempty"`
Title *string `json:"title,omitempty"`
Target *string `json:"target,omitempty"`
Required *bool `json:"required,omitempty"`
Many *bool `json:"many,omitempty"`
Identifier *string `json:"identifier,omitempty"`
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
Target *string `json:"target,omitempty"`
Required *bool `json:"required,omitempty"`
Many *bool `json:"many,omitempty"`
}

Scorecard struct {
Expand Down
9 changes: 5 additions & 4 deletions port/blueprint/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ type PropertiesModel struct {
}

type RelationModel struct {
Target types.String `tfsdk:"target"`
Title types.String `tfsdk:"title"`
Required types.Bool `tfsdk:"required"`
Many types.Bool `tfsdk:"many"`
Target types.String `tfsdk:"target"`
Title types.String `tfsdk:"title"`
Description types.String `tfsdk:"description"`
Required types.Bool `tfsdk:"required"`
Many types.Bool `tfsdk:"many"`
}

type MirrorPropertyModel struct {
Expand Down
6 changes: 6 additions & 0 deletions port/blueprint/readStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blueprint

import (
"context"

"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"
)

Expand Down Expand Up @@ -62,6 +63,11 @@ func relationsResourceToBody(state *BlueprintModel) map[string]cli.Relation {
relationProp.Required = &required
}

if !prop.Description.IsNull() {
description := prop.Description.ValueString()
relationProp.Description = &description
}

relations[identifier] = relationProp
}

Expand Down
11 changes: 8 additions & 3 deletions port/blueprint/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package blueprint_test
import (
"context"
"fmt"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/consts"
"github.com/port-labs/terraform-provider-port-labs/v2/version"
"net/http"
"os"
"regexp"
"strconv"
"testing"
"time"

"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/consts"
"github.com/port-labs/terraform-provider-port-labs/v2/version"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/acctest"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
Expand Down Expand Up @@ -409,12 +410,14 @@ func TestAccPortBlueprintWithRelation(t *testing.T) {
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice1", "title", "TF Provider Test BP2"),
resource.TestCheckNoResourceAttr("port_blueprint.microservice1", "description"),
resource.TestCheckResourceAttr("port_blueprint.microservice1", "identifier", identifier1),
resource.TestCheckResourceAttr("port_blueprint.microservice1", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "title", "TF Provider Test BP3"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "identifier", identifier2),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "relations.test-rel.title", "Test Relation"),
resource.TestCheckNoResourceAttr("port_blueprint.microservice2", "description"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "relations.test-rel.target", identifier1),
),
},
Expand Down Expand Up @@ -625,6 +628,7 @@ func TestAccPortBlueprintWithMirrorProperty(t *testing.T) {
relations = {
"test-rel" = {
title = "Test Relation"
description = "Test Relation"
target = port_blueprint.microservice1.identifier
}
}
Expand All @@ -638,6 +642,7 @@ func TestAccPortBlueprintWithMirrorProperty(t *testing.T) {
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice2", "relations.test-rel.title", "Test Relation"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "relations.test-rel.description", "Test Relation"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "relations.test-rel.target", identifier1),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "mirror_properties.mirror-for-microservice1.title", "Mirror for microservice1"),
resource.TestCheckResourceAttr("port_blueprint.microservice2", "mirror_properties.mirror-for-microservice1.path", "test-rel.$identifier"),
Expand Down
4 changes: 4 additions & 0 deletions port/blueprint/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func BlueprintSchema() map[string]schema.Attribute {
MarkdownDescription: "The title of the relation",
Optional: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "The description of the relation",
Optional: true,
},
"target": schema.StringAttribute{
MarkdownDescription: "The target of the relation",
Required: true,
Expand Down
9 changes: 5 additions & 4 deletions port/blueprint/updatePropertiesToState.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ func addRelationsToState(b *cli.Blueprint, bm *BlueprintModel) {
}

relationModel := &RelationModel{
Target: types.StringValue(*v.Target),
Title: flex.GoStringToFramework(v.Title),
Many: flex.GoBoolToFramework(v.Many),
Required: flex.GoBoolToFramework(v.Required),
Target: types.StringValue(*v.Target),
Title: flex.GoStringToFramework(v.Title),
Description: flex.GoStringToFramework(v.Description),
Many: flex.GoBoolToFramework(v.Many),
Required: flex.GoBoolToFramework(v.Required),
}

bm.Relations[k] = *relationModel
Expand Down

0 comments on commit f12ec6b

Please sign in to comment.