Skip to content

Commit

Permalink
Granular CRN for dedicated hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita committed Feb 5, 2025
1 parent 13dbdb2 commit 9fdea73
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 59 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ github.com/IBM/keyprotect-go-client v0.15.1 h1:m4qzqF5zOumRxKZ8s7vtK7A/UV/D278L8
github.com/IBM/keyprotect-go-client v0.15.1/go.mod h1:asXtHwL/4uCHA221Vd/7SkXEi2pcRHDzPyyksc1DthE=
github.com/IBM/logs-go-sdk v0.4.0 h1:CyUjm19EUtcJjf4mxsj6Rc7gkZDT8JEY5rLUIz8Eoag=
github.com/IBM/logs-go-sdk v0.4.0/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
github.com/IBM/logs-router-go-sdk v1.0.5 h1:r0kC1+HfmSeQCD6zQTUp4PDI/zp4Ueo1Zo19ipHuNlw=
github.com/IBM/logs-router-go-sdk v1.0.5/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
github.com/IBM/logs-router-go-sdk v1.0.7 h1:uQjQAAcQdo3XvhY6MC7HakhZaXIUsGfUmKj2d5vkjnY=
github.com/IBM/logs-router-go-sdk v1.0.7/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo5HU=
Expand Down
22 changes: 22 additions & 0 deletions ibm/service/power/data_source_ibm_pi_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ package power

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
)

func DataSourceIBMPIHost() *schema.Resource {
Expand Down Expand Up @@ -84,6 +86,11 @@ func DataSourceIBMPIHost() *schema.Resource {
},
Type: schema.TypeList,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_DisplayName: {
Computed: true,
Description: "Name of the host (chosen by the user).",
Expand Down Expand Up @@ -114,6 +121,13 @@ func DataSourceIBMPIHost() *schema.Resource {
Description: "System type.",
Type: schema.TypeString,
},
Attr_UserTags: {
Computed: true,
Description: "List of user tags attached to the resource.",
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Type: schema.TypeSet,
},
},
}
}
Expand All @@ -136,6 +150,14 @@ func dataSourceIBMPIHostRead(ctx context.Context, d *schema.ResourceData, meta i
if host.Capacity != nil {
d.Set(Attr_Capacity, hostCapacityToMap(host.Capacity))
}
if host.Crn != "" {
d.Set(Attr_CRN, host.Crn)
tags, err := flex.GetGlobalTagsUsingCRN(meta, string(host.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on get of pi host (%s) user_tags: %s", hostID, err)
}
d.Set(Attr_UserTags, tags)
}
if host.DisplayName != "" {
d.Set(Attr_DisplayName, host.DisplayName)
}
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/data_source_ibm_pi_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

func TestAccIBMPIHostDataSourceBasic(t *testing.T) {
hostResData := "data.ibm_pi_host.pi_host_instance"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIHostDataSourceConfigBasic(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_host.pi_host_instance", "id"),
resource.TestCheckResourceAttrSet(hostResData, "id"),
),
},
},
Expand Down
22 changes: 22 additions & 0 deletions ibm/service/power/data_source_ibm_pi_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package power

import (
"context"
"log"

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -13,6 +14,7 @@ import (

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
)

func DataSourceIBMPIHosts() *schema.Resource {
Expand Down Expand Up @@ -82,6 +84,11 @@ func DataSourceIBMPIHosts() *schema.Resource {
},
Type: schema.TypeList,
},
Attr_CRN: {
Computed: true,
Description: "The CRN of this resource.",
Type: schema.TypeString,
},
Attr_DisplayName: {
Computed: true,
Description: "Name of the host (chosen by the user).",
Expand Down Expand Up @@ -117,6 +124,13 @@ func DataSourceIBMPIHosts() *schema.Resource {
Description: "System type.",
Type: schema.TypeString,
},
Attr_UserTags: {
Computed: true,
Description: "List of user tags attached to the resource.",
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Type: schema.TypeSet,
},
},
},
Type: schema.TypeList,
Expand Down Expand Up @@ -147,6 +161,14 @@ func dataSourceIBMPIHostsRead(ctx context.Context, d *schema.ResourceData, meta
if host.Capacity != nil {
hs[Attr_Capacity] = hostCapacityToMap(host.Capacity)
}
if host.Crn != "" {
hs[Attr_CRN] = host.Crn
tags, err := flex.GetTagsUsingCRN(meta, string(host.Crn))
if err != nil {
log.Printf("Error on get of pi host (%s) user_tags: %s", host.ID, err)
}
hs[Attr_UserTags] = tags
}
if host.DisplayName != "" {
hs[Attr_DisplayName] = host.DisplayName
}
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/data_source_ibm_pi_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

func TestAccIBMPIHostsDataSourceBasic(t *testing.T) {
hostsResData := "data.ibm_pi_hosts.pi_hosts_instance"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIHostsDataSourceConfigBasic(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_hosts.pi_hosts_instance", "id"),
resource.TestCheckResourceAttrSet(hostsResData, "id"),
),
},
},
Expand Down
Loading

0 comments on commit 9fdea73

Please sign in to comment.