Skip to content

Commit e9cf5d5

Browse files
authored
PORT-7217-bug-terraform-errors-when-trying-to-conditionally-set-variable-properties (#120)
* added models for validating the action schema * changed the validation logic for the action schema to to parse types differently with the new validation model (to fix a bug where the types convetion failed) * updated the validation for action schema's required-user-property attribute to work with the new typing * added tests for the validation in the use-case that caused the bug mentioned in point 2
1 parent 6898d74 commit e9cf5d5

File tree

3 files changed

+623
-24
lines changed

3 files changed

+623
-24
lines changed

port/action/model.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package action
22

33
import (
44
"github.com/hashicorp/terraform-plugin-framework/types"
5+
"github.com/hashicorp/terraform-plugin-go/tftypes"
56
)
67

78
type WebhookMethodModel struct {
@@ -70,6 +71,141 @@ type StringPropModel struct {
7071
Encryption types.String `tfsdk:"encryption"`
7172
}
7273

74+
// StringPropValidationModel is a model used for the validation of StringPropModel resources
75+
type StringPropValidationModel struct {
76+
Title string
77+
Required *bool
78+
}
79+
80+
func (e *StringPropValidationModel) FromTerraform5Value(val tftypes.Value) error {
81+
v := map[string]tftypes.Value{}
82+
83+
err := val.As(&v)
84+
if err != nil {
85+
return err
86+
}
87+
88+
err = v["title"].As(&e.Title)
89+
if err != nil {
90+
return err
91+
}
92+
93+
err = v["required"].As(&e.Required)
94+
if err != nil {
95+
return err
96+
}
97+
98+
return nil
99+
}
100+
101+
// NumberPropValidationModel is a model used for the validation of StringPropModel resources
102+
type NumberPropValidationModel struct {
103+
Title string
104+
Required *bool
105+
}
106+
107+
func (e *NumberPropValidationModel) FromTerraform5Value(val tftypes.Value) error {
108+
v := map[string]tftypes.Value{}
109+
110+
err := val.As(&v)
111+
if err != nil {
112+
return err
113+
}
114+
115+
err = v["title"].As(&e.Title)
116+
if err != nil {
117+
return err
118+
}
119+
120+
err = v["required"].As(&e.Required)
121+
if err != nil {
122+
return err
123+
}
124+
125+
return nil
126+
}
127+
128+
// BooleanPropValidationModel is a model used for the validation of StringPropModel resources
129+
type BooleanPropValidationModel struct {
130+
Title string
131+
Required *bool
132+
}
133+
134+
func (e *BooleanPropValidationModel) FromTerraform5Value(val tftypes.Value) error {
135+
v := map[string]tftypes.Value{}
136+
137+
err := val.As(&v)
138+
if err != nil {
139+
return err
140+
}
141+
142+
err = v["title"].As(&e.Title)
143+
if err != nil {
144+
return err
145+
}
146+
147+
err = v["required"].As(&e.Required)
148+
if err != nil {
149+
return err
150+
}
151+
152+
return nil
153+
}
154+
155+
// ObjectPropValidationModel is a model used for the validation of StringPropModel resources
156+
type ObjectPropValidationModel struct {
157+
Title string
158+
Required *bool
159+
}
160+
161+
func (e *ObjectPropValidationModel) FromTerraform5Value(val tftypes.Value) error {
162+
v := map[string]tftypes.Value{}
163+
164+
err := val.As(&v)
165+
if err != nil {
166+
return err
167+
}
168+
169+
err = v["title"].As(&e.Title)
170+
if err != nil {
171+
return err
172+
}
173+
174+
err = v["required"].As(&e.Required)
175+
if err != nil {
176+
return err
177+
}
178+
179+
return nil
180+
}
181+
182+
// ArrayPropValidationModel is a model used for the validation of StringPropModel resources
183+
type ArrayPropValidationModel struct {
184+
Title string
185+
Required *bool
186+
}
187+
188+
func (e *ArrayPropValidationModel) FromTerraform5Value(val tftypes.Value) error {
189+
v := map[string]tftypes.Value{}
190+
191+
err := val.As(&v)
192+
if err != nil {
193+
return err
194+
}
195+
196+
err = v["title"].As(&e.Title)
197+
if err != nil {
198+
return err
199+
}
200+
201+
err = v["required"].As(&e.Required)
202+
if err != nil {
203+
return err
204+
}
205+
206+
return nil
207+
}
208+
73209
type NumberPropModel struct {
74210
Title types.String `tfsdk:"title"`
75211
Icon types.String `tfsdk:"icon"`
@@ -188,3 +324,25 @@ type ActionModel struct {
188324
OrderProperties types.List `tfsdk:"order_properties"`
189325
RequiredJqQuery types.String `tfsdk:"required_jq_query"`
190326
}
327+
328+
// ActionValidationModel is a model used for the validation of ActionModel resources
329+
type ActionValidationModel struct {
330+
ID types.String `tfsdk:"id"`
331+
Identifier types.String `tfsdk:"identifier"`
332+
Blueprint types.String `tfsdk:"blueprint"`
333+
Title types.String `tfsdk:"title"`
334+
Icon types.String `tfsdk:"icon"`
335+
Description types.String `tfsdk:"description"`
336+
RequiredApproval types.Bool `tfsdk:"required_approval"`
337+
Trigger types.String `tfsdk:"trigger"`
338+
KafkaMethod types.Object `tfsdk:"kafka_method"`
339+
WebhookMethod types.Object `tfsdk:"webhook_method"`
340+
GithubMethod types.Object `tfsdk:"github_method"`
341+
AzureMethod types.Object `tfsdk:"azure_method"`
342+
GitlabMethod types.Object `tfsdk:"gitlab_method"`
343+
UserProperties types.Object `tfsdk:"user_properties"`
344+
ApprovalWebhookNotification types.Object `tfsdk:"approval_webhook_notification"`
345+
ApprovalEmailNotification types.Object `tfsdk:"approval_email_notification"`
346+
OrderProperties types.List `tfsdk:"order_properties"`
347+
RequiredJqQuery types.String `tfsdk:"required_jq_query"`
348+
}

0 commit comments

Comments
 (0)