From 7a4cf3e756136caff537a010f32f0952a6e0cf60 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Fri, 15 Nov 2024 11:26:37 -0600 Subject: [PATCH] Fix tags attribute, fix tests --- ibm/service/power/resource_ibm_pi_host.go | 13 ++++++------- ibm/service/power/resource_ibm_pi_host_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_host.go b/ibm/service/power/resource_ibm_pi_host.go index 5615b94e55..8e045f35fd 100644 --- a/ibm/service/power/resource_ibm_pi_host.go +++ b/ibm/service/power/resource_ibm_pi_host.go @@ -174,8 +174,7 @@ func ResourceIBMPIHost() *schema.Resource { Computed: true, Description: "List of user tags attached to resource.", Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - Type: schema.TypeSet, + Type: schema.TypeList, }, }, } @@ -258,7 +257,7 @@ func resourceIBMPIHostRead(ctx context.Context, d *schema.ResourceData, meta int if err != nil { log.Printf("Error on get of pi host (%s) user_tags: %s", host.ID, err) } - d.Set(Attr_UserTags, tags) + d.Set(Attr_UserTags, tags.List()) } if host.DisplayName != "" { d.Set(Attr_DisplayName, host.DisplayName) @@ -443,10 +442,6 @@ func isIBMPIHostRefreshFunc(client *instance.IBMPIHostGroupsClient, id string) r func flattenHostArgumentToList(d *schema.ResourceData, meta interface{}) []map[string]interface{} { hostListType := make([]map[string]interface{}, 0) h := map[string]interface{}{} - if v, ok := d.GetOk(Attr_UserTags); ok { - tags := v.(*schema.Set) - h[Attr_UserTags] = tags - } if v, ok := d.GetOk(Attr_DisplayName); ok { displayName := v.(string) h[Attr_DisplayName] = displayName @@ -455,6 +450,10 @@ func flattenHostArgumentToList(d *schema.ResourceData, meta interface{}) []map[s sysType := v.(string) h[Attr_SysType] = sysType } + if v, ok := d.GetOk(Attr_UserTags); ok { + tags := v.([]interface{}) + h[Attr_UserTags] = tags + } hostListType = append(hostListType, h) return hostListType } diff --git a/ibm/service/power/resource_ibm_pi_host_test.go b/ibm/service/power/resource_ibm_pi_host_test.go index 616de63319..746195bc33 100644 --- a/ibm/service/power/resource_ibm_pi_host_test.go +++ b/ibm/service/power/resource_ibm_pi_host_test.go @@ -69,8 +69,8 @@ func TestAccIBMIHostUserTags(t *testing.T) { testAccCheckIBMPIHostExists(hostRes), resource.TestCheckResourceAttr(hostRes, "display_name", displayName), resource.TestCheckResourceAttr(hostRes, "user_tags.#", "2"), - resource.TestCheckResourceAttr(hostRes, "user_tags.*", "env:dev"), - resource.TestCheckResourceAttr(hostRes, "user_tags.*", "test_tag1"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "test_tag1"), ), }, { @@ -79,9 +79,9 @@ func TestAccIBMIHostUserTags(t *testing.T) { testAccCheckIBMPIHostExists(hostRes), resource.TestCheckResourceAttr(hostRes, "display_name", displayName), resource.TestCheckResourceAttr(hostRes, "user_tags.#", "3"), - resource.TestCheckResourceAttr(hostRes, "user_tags.*", "env:dev"), - resource.TestCheckResourceAttr(hostRes, "user_tags.*", "test_tag1"), - resource.TestCheckResourceAttr(hostRes, "user_tags.*", "ibm"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "test_tag1"), + resource.TestCheckTypeSetElemAttr(hostRes, "user_tags.*", "ibm"), ), }, },