Skip to content

Commit

Permalink
Fix tags attribute, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita committed Nov 18, 2024
1 parent e9c5bd9 commit 7a4cf3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
13 changes: 6 additions & 7 deletions ibm/service/power/resource_ibm_pi_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions ibm/service/power/resource_ibm_pi_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down

0 comments on commit 7a4cf3e

Please sign in to comment.