Skip to content

Commit dd8b922

Browse files
authored
Merge pull request #223 from port-labs/PORT-10159-bug-tf-provider-property-enum-color-bug
PORT-10159: Fix enum color bug in action properties
2 parents 401ba21 + 49a6c53 commit dd8b922

File tree

8 files changed

+87
-2
lines changed

8 files changed

+87
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ setup:
4040
acctest:
4141
# TEST_FILTER can be any regex, E.g: .*PageResource.*
4242
# TEST_FILTER='TestAccPortPageResource*' make acctest
43-
TF_ACC=1 PORT_CLIENT_ID=$(PORT_CLIENT_ID) PORT_CLIENT_SECRET=$(PORT_CLIENT_SECRET) PORT_BASE_URL=$(PORT_BASE_URL) go test -timeout 20m -p 1 ./... -run "$(TEST_FILTER)"
43+
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:
4646
tfplugindocs

docs/resources/port_action.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ Optional:
627627
- `depends_on` (List of String) The properties that this property depends on
628628
- `description` (String) The description of the property
629629
- `enum` (List of Number) The enum of the number property
630+
- `enum_colors` (Map of String) The enum colors of the number property
630631
- `enum_jq_query` (String) The enum jq query of the string property
631632
- `icon` (String) The icon of the property
632633
- `maximum` (Number) The min of the number property
@@ -667,6 +668,7 @@ Optional:
667668
- `description` (String) The description of the property
668669
- `encryption` (String) The algorithm to encrypt the property with. Accepted value: `aes256-gcm`
669670
- `enum` (List of String) The enum of the string property
671+
- `enum_colors` (Map of String) The enum colors of the string property
670672
- `enum_jq_query` (String) The enum jq query of the string property
671673
- `format` (String) The format of the string property, Accepted values include `date-time`, `url`, `email`, `ipv4`, `ipv6`, `yaml`, `entity`, `user`, `team`, `proto`, `markdown`
672674
- `icon` (String) The icon of the property

examples/resources/port_action/main.tf

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,34 @@ resource "port_action" "restart_microservice" {
9292
title = "Service"
9393
description = "The service to restart"
9494
format = "entity"
95-
blueprint = "service"
95+
blueprint = "Service"
9696
sort = {
9797
property = "$updatedAt"
9898
order = "DESC"
9999
}
100100
}
101+
testString = {
102+
type = "string"
103+
title = "String enum"
104+
icon = "Terraform"
105+
default = "a"
106+
enum = ["a","b"]
107+
enum_colors = {
108+
a ="darkGray"
109+
b = "turquoise"
110+
}
111+
}
112+
testNumber = {
113+
type = "number"
114+
title = "Number enum"
115+
icon = "Terraform"
116+
default = 1
117+
enum = [1, 2]
118+
enum_colors = {
119+
"1" ="darkGray"
120+
"2" = "turquoise"
121+
}
122+
}
101123
}
102124
}
103125
}

port/action/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type StringPropModel struct {
3737
MinLength types.Int64 `tfsdk:"min_length"`
3838
Pattern types.String `tfsdk:"pattern"`
3939
Enum types.List `tfsdk:"enum"`
40+
EnumColors types.Map `tfsdk:"enum_colors"`
4041
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
4142
Encryption types.String `tfsdk:"encryption"`
4243
Sort *EntitiesSortModel `tfsdk:"sort"`
@@ -191,6 +192,7 @@ type NumberPropModel struct {
191192
Maximum types.Float64 `tfsdk:"maximum"`
192193
Minimum types.Float64 `tfsdk:"minimum"`
193194
Enum types.List `tfsdk:"enum"`
195+
EnumColors types.Map `tfsdk:"enum_colors"`
194196
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
195197
}
196198

port/action/number.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ func numberPropResourceToBody(ctx context.Context, state *SelfServiceTriggerMode
7272
property.Enum = enumJqQueryMap
7373
}
7474

75+
if !prop.EnumColors.IsNull() {
76+
property.EnumColors = map[string]string{}
77+
for k, v := range prop.EnumColors.Elements() {
78+
value, _ := v.ToTerraformValue(ctx)
79+
var keyValue string
80+
err := value.As(&keyValue)
81+
if err != nil {
82+
return err
83+
}
84+
property.EnumColors[k] = keyValue
85+
}
86+
}
87+
7588
if !prop.DependsOn.IsNull() {
7689
dependsOn, err := utils.TerraformListToGoArray(ctx, prop.DependsOn, "string")
7790
if err != nil {
@@ -130,5 +143,11 @@ func addNumberPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *
130143
numberProp.EnumJqQuery = types.StringNull()
131144
}
132145

146+
if v.EnumColors != nil {
147+
numberProp.EnumColors, _ = types.MapValueFrom(ctx, types.StringType, v.EnumColors)
148+
} else {
149+
numberProp.EnumColors = types.MapNull(types.StringType)
150+
}
151+
133152
return numberProp
134153
}

port/action/resource_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func TestAccPortAction(t *testing.T) {
8585
"required" = true
8686
maximum = 100
8787
minimum = 0
88+
enum = [1, 2]
89+
enum_colors = {
90+
"1" = "red"
91+
"2" = "blue"
92+
}
8893
}
8994
}
9095
"boolean_props" = {
@@ -131,6 +136,10 @@ func TestAccPortAction(t *testing.T) {
131136
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.required", "true"),
132137
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.maximum", "100"),
133138
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.minimum", "0"),
139+
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum.0", "1"),
140+
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum.1", "2"),
141+
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum_colors.1", "red"),
142+
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.number_props.myNumberIdentifier.enum_colors.2", "blue"),
134143
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.title", "My Boolean Identifier"),
135144
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.boolean_props.myBooleanIdentifier.required", "true"),
136145
resource.TestCheckResourceAttr("port_action.create_microservice", "self_service_trigger.user_properties.object_props.myObjectIdentifier.title", "My Object Identifier"),

port/action/schema.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ func StringPropertySchema() schema.Attribute {
540540
listvalidator.SizeAtLeast(1),
541541
},
542542
},
543+
"enum_colors": schema.MapAttribute{
544+
MarkdownDescription: "The enum colors of the string property",
545+
Optional: true,
546+
ElementType: types.StringType,
547+
},
543548
"enum_jq_query": schema.StringAttribute{
544549
MarkdownDescription: "The enum jq query of the string property",
545550
Optional: true,
@@ -666,6 +671,11 @@ func NumberPropertySchema() schema.Attribute {
666671
listvalidator.SizeAtLeast(1),
667672
},
668673
},
674+
"enum_colors": schema.MapAttribute{
675+
MarkdownDescription: "The enum colors of the number property",
676+
Optional: true,
677+
ElementType: types.StringType,
678+
},
669679
"enum_jq_query": schema.StringAttribute{
670680
MarkdownDescription: "The enum jq query of the string property",
671681
Optional: true,

port/action/string.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ func stringPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, p
7979
property.Enum = enumList
8080
}
8181

82+
if !prop.EnumColors.IsNull() {
83+
enumColor := map[string]string{}
84+
for k, v := range prop.EnumColors.Elements() {
85+
value, _ := v.ToTerraformValue(ctx)
86+
var keyValue string
87+
err := value.As(&keyValue)
88+
if err != nil {
89+
return err
90+
}
91+
enumColor[k] = keyValue
92+
}
93+
94+
property.EnumColors = enumColor
95+
}
96+
8297
if !prop.EnumJqQuery.IsNull() {
8398
enumJqQueryMap := map[string]string{
8499
"jqQuery": prop.EnumJqQuery.ValueString(),
@@ -164,6 +179,12 @@ func addStringPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *
164179
stringProp.EnumJqQuery = types.StringNull()
165180
}
166181

182+
if v.EnumColors != nil {
183+
stringProp.EnumColors, _ = types.MapValueFrom(ctx, types.StringType, v.EnumColors)
184+
} else {
185+
stringProp.EnumColors = types.MapNull(types.StringType)
186+
}
187+
167188
if v.Sort != nil {
168189
stringProp.Sort = &EntitiesSortModel{
169190
Property: types.StringValue(v.Sort.Property),

0 commit comments

Comments
 (0)