Skip to content

Commit 8b4f177

Browse files
authored
[Entity] Handle undefined array type as string (#159)
1 parent 30dc7bc commit 8b4f177

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

port/entity/refreshEntityToState.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func refreshArrayEntityState(ctx context.Context, state *EntityModel, arrayPrope
2525
for k, t := range arrayProperties {
2626

2727
switch blueprint.Schema.Properties[k].Items["type"] {
28-
case "string":
28+
// array without items type is array of string by default
29+
case "string", nil:
2930
if t != nil {
3031
for _, item := range t {
3132
stringItem := item.(string)
@@ -80,7 +81,6 @@ func refreshArrayEntityState(ctx context.Context, state *EntityModel, arrayPrope
8081
mapObjectItems[k] = nil
8182
}
8283
state.Properties.ArrayProps.ObjectItems, _ = types.MapValueFrom(ctx, types.ListType{ElemType: types.StringType}, mapObjectItems)
83-
8484
}
8585
}
8686
}

port/entity/resource_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,5 +769,60 @@ func TestAccPortEntityUpdateBlueprintIdentifier(t *testing.T) {
769769
},
770770
},
771771
})
772+
}
772773

774+
func TestAccPortEntityWithDefaultArrayProp(t *testing.T) {
775+
identifier := utils.GenID()
776+
entityIdentifier := utils.GenID()
777+
var testAccActionConfigCreate = fmt.Sprintf(`
778+
resource "port_blueprint" "microservice" {
779+
title = "TF Provider Test BP0"
780+
icon = "Terraform"
781+
identifier = "%s"
782+
properties = {
783+
"array_props" = {
784+
"myArrayIdentifier" = {
785+
"title" = "My Array Identifier"
786+
}
787+
}
788+
}
789+
}
790+
resource "port_entity" "microservice" {
791+
title = "TF Provider Test Entity0"
792+
blueprint = port_blueprint.microservice.identifier
793+
identifier = "%s"
794+
properties = {
795+
array_props = {
796+
string_items = {
797+
"myArrayIdentifier" = ["My Array Value", "My Array Value2"]
798+
}
799+
}
800+
}
801+
}`, identifier, entityIdentifier)
802+
803+
resource.Test(t, resource.TestCase{
804+
PreCheck: func() { acctest.TestAccPreCheck(t) },
805+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
806+
807+
Steps: []resource.TestStep{
808+
{
809+
Config: acctest.ProviderConfig + testAccActionConfigCreate,
810+
Check: resource.ComposeTestCheckFunc(
811+
resource.TestCheckResourceAttr("port_entity.microservice", "title", "TF Provider Test Entity0"),
812+
resource.TestCheckResourceAttr("port_entity.microservice", "blueprint", identifier),
813+
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.0", "My Array Value"),
814+
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.1", "My Array Value2"),
815+
),
816+
},
817+
{
818+
Config: acctest.ProviderConfig + testAccActionConfigCreate,
819+
Check: resource.ComposeTestCheckFunc(
820+
resource.TestCheckResourceAttr("port_entity.microservice", "title", "TF Provider Test Entity0"),
821+
resource.TestCheckResourceAttr("port_entity.microservice", "blueprint", identifier),
822+
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.0", "My Array Value"),
823+
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.1", "My Array Value2"),
824+
),
825+
},
826+
},
827+
})
773828
}

0 commit comments

Comments
 (0)