Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
talsabagport committed Jan 25, 2024
2 parents ca5f140 + 1947767 commit 9ab053d
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 143 deletions.
210 changes: 195 additions & 15 deletions docs/resources/port_scorecard.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,204 @@
page_title: "port_scorecard Resource - terraform-provider-port-labs"
subcategory: ""
description: |-
scorecard resource
Scorecard
This resource allows you to manage a scorecard.
See the Port documentation https://docs.getport.io/promote-scorecards/ for more information about scorecards.
Example Usage
Create a parent blueprint with a child blueprint and an aggregation property to count the parent kids:
```hcl
resource "portblueprint" "microservice" {
title = "microservice"
icon = "Terraform"
identifier = "microservice"
properties = {
stringprops = {
"author" = {
title = "Author"
}
"url" = {
title = "URL"
}
}
booleanprops = {
"required" = {
type = "boolean"
}
}
numberprops = {
"sum" = {
type = "number"
}
}
}
}
resource "portscorecard" "readiness" {
identifier = "Readiness"
title = "Readiness"
blueprint = portblueprint.microservice.identifier
rules = [
{
identifier = "hasOwner"
title = "Has Owner"
level = "Gold"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "$team"
operator = "isNotEmpty"
}),
jsonencode({
property = "author",
operator : "=",
value : "myValue"
})
]
}
},
{
identifier = "hasUrl"
title = "Has URL"
level = "Silver"
query = {
combinator = "and"
conditions = [jsonencode({
property = "url"
operator = "isNotEmpty"
})]
}
},
{
identifier = "checkSumIfRequired"
title = "Check Sum If Required"
level = "Bronze"
query = {
combinator = "or"
conditions = [
jsonencode({
property = "required"
operator : "="
value : false
}),
jsonencode({
property = "sum"
operator : ">"
value : 2
})
]
}
}
]
dependson = [
portblueprint.microservice
]
}
```
---

# port_scorecard (Resource)

scorecard resource
# Scorecard

This resource allows you to manage a scorecard.

See the [Port documentation](https://docs.getport.io/promote-scorecards/) for more information about scorecards.

## Example Usage

Create a parent blueprint with a child blueprint and an aggregation property to count the parent kids:

```hcl
resource "port_blueprint" "microservice" {
title = "microservice"
icon = "Terraform"
identifier = "microservice"
properties = {
string_props = {
"author" = {
title = "Author"
}
"url" = {
title = "URL"
}
}
boolean_props = {
"required" = {
type = "boolean"
}
}
number_props = {
"sum" = {
type = "number"
}
}
}
}
resource "port_scorecard" "readiness" {
identifier = "Readiness"
title = "Readiness"
blueprint = port_blueprint.microservice.identifier
rules = [
{
identifier = "hasOwner"
title = "Has Owner"
level = "Gold"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "$team"
operator = "isNotEmpty"
}),
jsonencode({
property = "author",
operator : "=",
value : "myValue"
})
]
}
},
{
identifier = "hasUrl"
title = "Has URL"
level = "Silver"
query = {
combinator = "and"
conditions = [jsonencode({
property = "url"
operator = "isNotEmpty"
})]
}
},
{
identifier = "checkSumIfRequired"
title = "Check Sum If Required"
level = "Bronze"
query = {
combinator = "or"
conditions = [
jsonencode({
property = "required"
operator : "="
value : false
}),
jsonencode({
property = "sum"
operator : ">"
value : 2
})
]
}
}
]
depends_on = [
port_blueprint.microservice
]
}
```



Expand Down Expand Up @@ -46,18 +238,6 @@ Required:
Required:

- `combinator` (String) The combinator of the query
- `conditions` (Attributes List) The conditions of the query (see [below for nested schema](#nestedatt--rules--query--conditions))

<a id="nestedatt--rules--query--conditions"></a>
### Nested Schema for `rules.query.conditions`

Required:

- `operator` (String) The operator of the condition
- `property` (String) The property of the condition

Optional:

- `value` (String) The value of the condition
- `conditions` (List of String) The conditions of the query. Each condition object should be encoded to a string


10 changes: 2 additions & 8 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,8 @@ type (
}

Query struct {
Combinator string `json:"combinator,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}

Condition struct {
Property string `json:"property,omitempty"`
Operator string `json:"operator,omitempty"`
Value *string `json:"value,omitempty"`
Combinator string `json:"combinator,omitempty"`
Conditions []any `json:"conditions,omitempty"`
}

Webhook struct {
Expand Down
10 changes: 2 additions & 8 deletions port/scorecard/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type Condition struct {
Operator types.String `tfsdk:"operator"`
Property types.String `tfsdk:"property"`
Value types.String `tfsdk:"value"`
}

type Query struct {
Combinator types.String `tfsdk:"combinator"`
Conditions []Condition `tfsdk:"conditions"`
Combinator types.String `tfsdk:"combinator"`
Conditions []types.String `tfsdk:"conditions"`
}

type Rule struct {
Expand Down
16 changes: 6 additions & 10 deletions port/scorecard/refreshScorecardState.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package scorecard
import (
"context"
"fmt"
"github.com/port-labs/terraform-provider-port-labs/internal/utils"

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/port-labs/terraform-provider-port-labs/internal/cli"
"github.com/port-labs/terraform-provider-port-labs/internal/flex"
)

func refreshScorecardState(ctx context.Context, state *ScorecardModel, s *cli.Scorecard, blueprintIdentifier string) {
Expand All @@ -29,16 +29,12 @@ func refreshScorecardState(ctx context.Context, state *ScorecardModel, s *cli.Sc
stateQuery := &Query{
Combinator: types.StringValue(rule.Query.Combinator),
}
stateConditions := []Condition{}
for _, condition := range rule.Query.Conditions {
stateCondition := &Condition{
Operator: types.StringValue(condition.Operator),
Property: types.StringValue(condition.Property),
Value: flex.GoStringToFramework(condition.Value),
}
stateConditions = append(stateConditions, *stateCondition)

stateQuery.Conditions = make([]types.String, len(rule.Query.Conditions))
for i, u := range rule.Query.Conditions {
cond, _ := utils.GoObjectToTerraformString(u)
stateQuery.Conditions[i] = cond
}
stateQuery.Conditions = stateConditions

stateRule.Query = stateQuery

Expand Down
File renamed without changes.
Loading

0 comments on commit 9ab053d

Please sign in to comment.