Skip to content

Commit b1f48f6

Browse files
Port 16366 bug spec is not included in calculation properties for blueprints in tf provider (#293)
* add dynamic unknown fields to the blueprint property types * add support for spec in calculation properties * add docs * gen docs
1 parent afda9fa commit b1f48f6

File tree

10 files changed

+119
-18
lines changed

10 files changed

+119
-18
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ acctest:
4343
TF_ACC=1 PORT_CLIENT_ID=$(PORT_CLIENT_ID) PORT_CLIENT_SECRET=$(PORT_CLIENT_SECRET) PORT_BASE_URL=$(PORT_BASE_URL) go test -timeout 40m -p 1 ./... -run "$(TEST_FILTER)"
4444

4545
gen-docs:
46+
@echo "Generating documentation..."
47+
@if [ ! -f "./terraform-provider-port-labs" ]; then \
48+
echo "Provider binary not found. Building..."; \
49+
go build -o terraform-provider-port-labs; \
50+
fi
4651
tfplugindocs
52+
@echo "Documentation generated successfully!"
4753

4854
lint: build
4955
# https://golangci-lint.run/welcome/install/#local-installation

docs/resources/port_blueprint.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,20 @@ Optional:
313313
- `description` (String) The description of the calculation property
314314
- `format` (String) The format of the calculation property
315315
- `icon` (String) The icon of the calculation property
316+
- `spec` (String) The spec of the calculation property
317+
- `spec_authentication` (Attributes) The spec authentication of the calculation property (see [below for nested schema](#nestedatt--calculation_properties--spec_authentication))
316318
- `title` (String) The title of the calculation property
317319

320+
<a id="nestedatt--calculation_properties--spec_authentication"></a>
321+
### Nested Schema for `calculation_properties.spec_authentication`
322+
323+
Required:
324+
325+
- `authorization_url` (String) The authorizationUrl of the spec authentication
326+
- `client_id` (String) The clientId of the spec authentication
327+
- `token_url` (String) The tokenUrl of the spec authentication
328+
329+
318330

319331
<a id="nestedatt--kafka_changelog_destination"></a>
320332
### Nested Schema for `kafka_changelog_destination`

docs/resources/port_system_blueprint.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,20 @@ Optional:
4545
- `description` (String) The description of the calculation property
4646
- `format` (String) The format of the calculation property
4747
- `icon` (String) The icon of the calculation property
48+
- `spec` (String) The spec of the calculation property
49+
- `spec_authentication` (Attributes) The spec authentication of the calculation property (see [below for nested schema](#nestedatt--calculation_properties--spec_authentication))
4850
- `title` (String) The title of the calculation property
4951

52+
<a id="nestedatt--calculation_properties--spec_authentication"></a>
53+
### Nested Schema for `calculation_properties.spec_authentication`
54+
55+
Required:
56+
57+
- `authorization_url` (String) The authorizationUrl of the spec authentication
58+
- `client_id` (String) The clientId of the spec authentication
59+
- `token_url` (String) The tokenUrl of the spec authentication
60+
61+
5062

5163
<a id="nestedatt--mirror_properties"></a>
5264
### Nested Schema for `mirror_properties`

examples/resources/port_blueprint/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ resource "port_blueprint" "microservice" {
9797
}
9898
}
9999

100+
calculation_properties = {
101+
"spec-calculation" = {
102+
title = "Spec Calculation"
103+
calculation = "@blueprint/environment.properties.name"
104+
type = "string"
105+
spec = "embedded-url"
106+
spec_authentication = {
107+
client_id = "my-client-id"
108+
token_url = "https://example.com/token"
109+
authorization_url = "https://example.com/auth"
110+
}
111+
}
112+
"simple-calculation" = {
113+
title = "Simple Calculation"
114+
calculation = "1 + 1"
115+
type = "number"
116+
description = "A simple calculation without spec"
117+
}
118+
}
119+
100120
relations = {
101121
"environment" = {
102122
title = "Test Relation"

internal/cli/models.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,18 @@ type (
133133
}
134134

135135
BlueprintCalculationProperty struct {
136-
Type string `json:"type,omitempty"`
137-
Title *string `json:"title,omitempty"`
138-
Identifier string `json:"identifier,omitempty"`
139-
Calculation string `json:"calculation,omitempty"`
140-
Default any `json:"default,omitempty"`
141-
Icon *string `json:"icon,omitempty"`
142-
Format *string `json:"format,omitempty"`
143-
Description *string `json:"description,omitempty"`
144-
Colorized *bool `json:"colorized,omitempty"`
145-
Colors map[string]string `json:"colors,omitempty"`
136+
Type string `json:"type,omitempty"`
137+
Title *string `json:"title,omitempty"`
138+
Identifier string `json:"identifier,omitempty"`
139+
Calculation string `json:"calculation,omitempty"`
140+
Default any `json:"default,omitempty"`
141+
Icon *string `json:"icon,omitempty"`
142+
Format *string `json:"format,omitempty"`
143+
Description *string `json:"description,omitempty"`
144+
Colorized *bool `json:"colorized,omitempty"`
145+
Colors map[string]string `json:"colors,omitempty"`
146+
Spec *string `json:"spec,omitempty"`
147+
SpecAuthentication *SpecAuthentication `json:"specAuthentication,omitempty"`
146148
}
147149

148150
BlueprintAggregationProperty struct {

port/aggregation-properties/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aggregation_properties
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-framework/path"
67
"github.com/hashicorp/terraform-plugin-framework/resource"
78
"github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"

port/blueprint/model.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,16 @@ type MirrorPropertyModel struct {
124124
}
125125

126126
type CalculationPropertyModel struct {
127-
Calculation types.String `tfsdk:"calculation"`
128-
Title types.String `tfsdk:"title"`
129-
Format types.String `tfsdk:"format"`
130-
Icon types.String `tfsdk:"icon"`
131-
Description types.String `tfsdk:"description"`
132-
Type types.String `tfsdk:"type"`
133-
Colorized types.Bool `tfsdk:"colorized"`
134-
Colors types.Map `tfsdk:"colors"`
127+
Calculation types.String `tfsdk:"calculation"`
128+
Title types.String `tfsdk:"title"`
129+
Format types.String `tfsdk:"format"`
130+
Icon types.String `tfsdk:"icon"`
131+
Description types.String `tfsdk:"description"`
132+
Type types.String `tfsdk:"type"`
133+
Colorized types.Bool `tfsdk:"colorized"`
134+
Colors types.Map `tfsdk:"colors"`
135+
Spec types.String `tfsdk:"spec"`
136+
SpecAuthentication *SpecAuthenticationModel `tfsdk:"spec_authentication"`
135137
}
136138

137139
type AverageEntitiesModel struct {

port/blueprint/readStateToPortBody.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ func CalculationPropertiesToBody(ctx context.Context, state map[string]Calculati
139139
calculationProp.Colors = colors
140140
}
141141

142+
if !prop.Spec.IsNull() {
143+
spec := prop.Spec.ValueString()
144+
calculationProp.Spec = &spec
145+
}
146+
147+
if prop.SpecAuthentication != nil {
148+
specAuth := &cli.SpecAuthentication{
149+
AuthorizationUrl: prop.SpecAuthentication.AuthorizationUrl.ValueString(),
150+
TokenUrl: prop.SpecAuthentication.TokenUrl.ValueString(),
151+
ClientId: prop.SpecAuthentication.ClientId.ValueString(),
152+
}
153+
calculationProp.SpecAuthentication = specAuth
154+
}
155+
142156
calculationProperties[identifier] = calculationProp
143157
}
144158

port/blueprint/schema.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,29 @@ func BlueprintSchema() map[string]schema.Attribute {
498498
Optional: true,
499499
ElementType: types.StringType,
500500
},
501+
"spec": schema.StringAttribute{
502+
MarkdownDescription: "The spec of the calculation property",
503+
Optional: true,
504+
Validators: []validator.String{stringvalidator.OneOf("open-api", "async-api", "embedded-url")},
505+
},
506+
"spec_authentication": schema.SingleNestedAttribute{
507+
MarkdownDescription: "The spec authentication of the calculation property",
508+
Optional: true,
509+
Attributes: map[string]schema.Attribute{
510+
"client_id": schema.StringAttribute{
511+
MarkdownDescription: "The clientId of the spec authentication",
512+
Required: true,
513+
},
514+
"token_url": schema.StringAttribute{
515+
MarkdownDescription: "The tokenUrl of the spec authentication",
516+
Required: true,
517+
},
518+
"authorization_url": schema.StringAttribute{
519+
MarkdownDescription: "The authorizationUrl of the spec authentication",
520+
Required: true,
521+
},
522+
},
523+
},
501524
},
502525
},
503526
},

port/blueprint/updatePropertiesToState.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ func addCalculationPropertiesToState(ctx context.Context, b *cli.Blueprint, bm *
219219
Description: flex.GoStringToFramework(v.Description),
220220
Format: flex.GoStringToFramework(v.Format),
221221
Colorized: flex.GoBoolToFramework(v.Colorized),
222+
Spec: flex.GoStringToFramework(v.Spec),
222223
}
223224

224225
if v.Colors != nil {
@@ -227,6 +228,14 @@ func addCalculationPropertiesToState(ctx context.Context, b *cli.Blueprint, bm *
227228
calculationPropertyModel.Colors = types.MapNull(types.StringType)
228229
}
229230

231+
if v.SpecAuthentication != nil {
232+
calculationPropertyModel.SpecAuthentication = &SpecAuthenticationModel{
233+
AuthorizationUrl: types.StringValue(v.SpecAuthentication.AuthorizationUrl),
234+
TokenUrl: types.StringValue(v.SpecAuthentication.TokenUrl),
235+
ClientId: types.StringValue(v.SpecAuthentication.ClientId),
236+
}
237+
}
238+
230239
bm.CalculationProperties[k] = *calculationPropertyModel
231240

232241
}

0 commit comments

Comments
 (0)