Skip to content

Commit

Permalink
[Datasource] Add power private datacenter capabilities (#5833)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita authored Dec 4, 2024
1 parent d841442 commit e5a83f2
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 5 deletions.
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.22.5
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.8.3
github.com/IBM-Cloud/power-go-client v1.9.0
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,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.8.3 h1:QsBuIS6KvKsiEpe0yiHYKhWgXlqkcJ7XqFHtATj8Yh4=
github.com/IBM-Cloud/power-go-client v1.8.3/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
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/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
13 changes: 12 additions & 1 deletion ibm/service/power/data_source_ibm_pi_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func DataSourceIBMPIDatacenter() *schema.Resource {
ReadContext: dataSourceIBMPIDatacenterRead,
Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Optional: true,
Type: schema.TypeString,
},
Arg_DatacenterZone: {
Description: "Datacenter zone you want to retrieve.",
Optional: true,
Expand Down Expand Up @@ -180,7 +185,13 @@ func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData,
if region, ok := d.GetOk(Arg_DatacenterZone); ok {
datacenterZone = region.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, "")

cloudInstanceID := ""
if cloudInstance, ok := d.GetOk(Arg_CloudInstanceID); ok {
cloudInstanceID = cloudInstance.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, cloudInstanceID)

dcData, err := client.Get(datacenterZone)
if err != nil {
return diag.FromErr(err)
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package power_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand All @@ -25,9 +26,31 @@ func TestAccIBMPIDatacenterDataSourceBasic(t *testing.T) {
})
}

func TestAccIBMPIDatacenterDataSourcePrivate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIDatacenterDataSourcePrivateConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_datacenter.test", "id"),
),
},
},
})
}

func testAccCheckIBMPIDatacenterDataSourceConfig() string {
return `
data "ibm_pi_datacenter" "test" {
pi_datacenter_zone = "dal12"
}`
}

func testAccCheckIBMPIDatacenterDataSourcePrivateConfig() string {
return fmt.Sprintf(`
data "ibm_pi_datacenter" "test" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
13 changes: 12 additions & 1 deletion ibm/service/power/data_source_ibm_pi_datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func DataSourceIBMPIDatacenters() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDatacentersRead,
Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Optional: true,
Type: schema.TypeString,
},

// Attributes
Attr_Datacenters: {
Type: schema.TypeList,
Expand Down Expand Up @@ -173,7 +180,11 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(err)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, "")
cloudInstanceID := ""
if cloudInstance, ok := d.GetOk(Arg_CloudInstanceID); ok {
cloudInstanceID = cloudInstance.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, cloudInstanceID)
datacentersData, err := client.GetAll()
if err != nil {
return diag.FromErr(err)
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package power_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand All @@ -25,6 +26,28 @@ func TestAccIBMPIDatacentersDataSourceBasic(t *testing.T) {
})
}

func TestAccIBMPIDatacentersDataSourcePrivate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIDatacentersDataSourcePrivateConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_datacenters.test", "id"),
),
},
},
})
}

func testAccCheckIBMPIDatacentersDataSourceConfig() string {
return `data "ibm_pi_datacenters" "test" {}`
}

func testAccCheckIBMPIDatacentersDataSourcePrivateConfig() string {
return fmt.Sprintf(`
data "ibm_pi_datacenters" "test" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
1 change: 1 addition & 0 deletions website/docs/d/pi_datacenter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Example usage:

Review the argument references that you can specify for your data source.

- `pi_cloud_instance_id` - (Optional, String) The GUID of the service instance associated with an account. Required if private datacenter.
- `pi_datacenter_zone` - (Optional, String) Datacenter zone you want to retrieve. If no value is supplied, the `zone` configured within the IBM provider will be utilized.

## Attribute reference
Expand Down
6 changes: 6 additions & 0 deletions website/docs/d/pi_datacenters.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Example usage:
}
```

## Argument reference

Review the argument references that you can specify for your data source.

- `pi_cloud_instance_id` - (Optional, String) The GUID of the service instance associated with an account. Required if private datacenter.

## Attribute reference
In addition to all argument reference list, you can access the following attribute references after your data source is created.

Expand Down

0 comments on commit e5a83f2

Please sign in to comment.