Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom scorecard levels #165

Merged
merged 14 commits into from
Jul 17, 2024
236 changes: 234 additions & 2 deletions docs/resources/port_scorecard.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
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:
This will create a blueprint with a Scorecard measuring the readiness of a microservice.
```hcl
resource "portblueprint" "microservice" {
title = "microservice"
Expand Down Expand Up @@ -97,6 +97,111 @@ description: |-
portblueprint.microservice
]
}
Example Usage with Levels
This will override the default levels (Basic, Bronze, Silver, Gold) with the provided levels: Not Ready, Partially Ready, Ready.
```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
levels = [
{
color = "red"
title = "No Ready"
},
{
color = "yellow"
title = "Partially Ready"
},
{
color = "green"
title = "Ready"
}
]
rules = [
{
identifier = "hasOwner"
title = "Has Owner"
level = "Ready"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "$team"
operator = "isNotEmpty"
}),
jsonencode({
property = "author",
operator : "=",
value : "myValue"
})
]
}
},
{
identifier = "hasUrl"
title = "Has URL"
level = "Partially Ready"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "url"
operator = "isNotEmpty"
})
]
}
},
{
identifier = "checkSumIfRequired"
title = "Check Sum If Required"
level = "Partially Ready"
query = {
combinator = "or"
conditions = [
jsonencode({
property = "required"
operator : "="
value : false
}),
jsonencode({
property = "sum"
operator : ">"
value : 2
})
]
}
}
]
dependson = [
portblueprint.microservice
]
}
```
---

Expand All @@ -110,7 +215,7 @@ See the [Port documentation](https://docs.getport.io/promote-scorecards/) for mo

## Example Usage

Create a parent blueprint with a child blueprint and an aggregation property to count the parent kids:
This will create a blueprint with a Scorecard measuring the readiness of a microservice.

```hcl

Expand Down Expand Up @@ -204,6 +309,119 @@ resource "port_scorecard" "readiness" {
]
}



## Example Usage with Levels

This will override the default levels (Basic, Bronze, Silver, Gold) with the provided levels: Not Ready, Partially Ready, Ready.


```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
levels = [
{
color = "red"
title = "No Ready"
},
{
color = "yellow"
title = "Partially Ready"
},
{
color = "green"
title = "Ready"
}
]
rules = [
{
identifier = "hasOwner"
title = "Has Owner"
level = "Ready"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "$team"
operator = "isNotEmpty"
}),
jsonencode({
property = "author",
operator : "=",
value : "myValue"
})
]
}
},
{
identifier = "hasUrl"
title = "Has URL"
level = "Partially Ready"
query = {
combinator = "and"
conditions = [
jsonencode({
property = "url"
operator = "isNotEmpty"
})
]
}
},
{
identifier = "checkSumIfRequired"
title = "Check Sum If Required"
level = "Partially Ready"
query = {
combinator = "or"
conditions = [
jsonencode({
property = "required"
operator : "="
value : false
}),
jsonencode({
property = "sum"
operator : ">"
value : 2
})
]
}
}
]
depends_on = [
port_blueprint.microservice
]
}

```


Expand All @@ -218,6 +436,10 @@ resource "port_scorecard" "readiness" {
- `rules` (Attributes List) The rules of the scorecard (see [below for nested schema](#nestedatt--rules))
- `title` (String) The title of the scorecard

### Optional

- `levels` (Attributes List) The levels of the scorecard. This overrides the default levels (Basic, Bronze, Silver, Gold) if provided (see [below for nested schema](#nestedatt--levels))

### Read-Only

- `created_at` (String) The creation date of the scorecard
Expand All @@ -243,3 +465,13 @@ Required:

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



<a id="nestedatt--levels"></a>
### Nested Schema for `levels`

Required:

- `color` (String) The color of the level
- `title` (String) The title of the level
23 changes: 14 additions & 9 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ type (
}

ScorecardRulesModel struct {
Identifier string `tfsdk:"identifier"`
Status string `tfsdk:"status"`
Level string `tfsdk:"level"`
Identifier string `json:"identifier"`
Status string `json:"status"`
Level string `json:"level"`
}

ScorecardModel struct {
Rules []ScorecardRulesModel `tfsdk:"rules"`
Level string `tfsdk:"level"`
Rules []ScorecardRulesModel `json:"rules"`
Level string `json:"level"`
}

Entity struct {
Expand Down Expand Up @@ -326,10 +326,11 @@ type (

Scorecard struct {
Meta
Identifier string `json:"identifier,omitempty"`
Title string `json:"title,omitempty"`
Blueprint string `json:"blueprint,omitempty"`
Rules []Rule `json:"rules,omitempty"`
Identifier string `json:"identifier,omitempty"`
Title string `json:"title,omitempty"`
Blueprint string `json:"blueprint,omitempty"`
Levels []Level `json:"levels,omitempty"`
Rules []Rule `json:"rules,omitempty"`
}

Rule struct {
Expand All @@ -339,6 +340,10 @@ type (
Query Query `json:"query,omitempty"`
}

Level struct {
Title string `json:"title,omitempty"`
Color string `json:"color,omitempty"`
}
Query struct {
Combinator string `json:"combinator,omitempty"`
Conditions []any `json:"conditions,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions port/scorecard/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ type Rule struct {
Query *Query `tfsdk:"query"`
}

type Level struct {
Title types.String `tfsdk:"title"`
Color types.String `tfsdk:"color"`
}

type ScorecardModel struct {
ID types.String `tfsdk:"id"`
Identifier types.String `tfsdk:"identifier"`
Blueprint types.String `tfsdk:"blueprint"`
Title types.String `tfsdk:"title"`
Levels []Level `tfsdk:"levels"`
Rules []Rule `tfsdk:"rules"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
Expand Down
Loading
Loading