Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Granular CRN for dedicated host resources and data sources #165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.23.4
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.9.0
github.com/IBM-Cloud/power-go-client v1.10.0
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.4.4
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJlMje9Ry6XEY=
github.com/IBM-Cloud/power-go-client v1.9.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/power-go-client v1.10.0 h1:yBUHWwvNBmLkWpbZJQJEXoxBa1Dm+eJgMSbk9ljmXUU=
github.com/IBM-Cloud/power-go-client v1.10.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down 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
Loading