Skip to content

Commit

Permalink
Merge pull request IBM-Cloud#5234 from powervs-ibm/data-source-storag…
Browse files Browse the repository at this point in the history
…e-type-refactor

Refactor data source storage type
  • Loading branch information
yussufsh authored Apr 24, 2024
2 parents 76eb73d + 6cd8648 commit 6c7c7d9
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 103 deletions.
7 changes: 3 additions & 4 deletions ibm/service/power/data_source_ibm_pi_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"context"
"log"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/go-uuid"
"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"

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

func DataSourceIBMPIKeys() *schema.Resource {
Expand Down Expand Up @@ -65,7 +64,7 @@ func dataSourceIBMPIKeysRead(ctx context.Context, d *schema.ResourceData, meta i

cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)

client := st.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID)
sshKeys, err := client.GetAll()
if err != nil {
log.Printf("[ERROR] get all keys failed %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func testAccCheckIBMPIStoragePoolCapacityDataSourceConfig() string {
data "ibm_pi_storage_pool_capacity" "pool" {
pi_cloud_instance_id = "%s"
pi_storage_pool = "%s"
}
`, acc.Pi_cloud_instance_id, acc.PiStoragePool)
}`, acc.Pi_cloud_instance_id, acc.PiStoragePool)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func DataSourceIBMPIStoragePoolsCapacity() *schema.Resource {
ValidateFunc: validation.NoZeroValues,
},

// Attributes
// Attributes
Attr_MaximumStorageAllocation: {
Computed: true,
Description: "Maximum storage allocation.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ func testAccCheckIBMPIStoragePoolsCapacityDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_storage_pools_capacity" "pools" {
pi_cloud_instance_id = "%s"
}
`, acc.Pi_cloud_instance_id)
}`, acc.Pi_cloud_instance_id)
}
55 changes: 25 additions & 30 deletions ibm/service/power/data_source_ibm_pi_storage_type_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,68 @@ package power
import (
"context"
"fmt"

"log"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"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"

"github.com/IBM-Cloud/power-go-client/helpers"
"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"
)

const (
PITypeName = "pi_storage_type"
)

func DataSourceIBMPIStorageTypeCapacity() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIStorageTypeCapacityRead,
Schema: map[string]*schema.Schema{
helpers.PICloudInstanceId: {
Type: schema.TypeString,
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
PITypeName: {
Type: schema.TypeString,
Arg_StorageType: {
Description: "The storage type name.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
Description: "Storage type name",
},
// Computed Attributes

// Attributes
Attr_MaximumStorageAllocation: {
Type: schema.TypeMap,
Computed: true,
Description: "Maximum storage allocation",
Description: "Maximum storage allocation.",
Type: schema.TypeMap,
},
Attr_StoragePoolsCapacity: {
Type: schema.TypeList,
Computed: true,
Description: "Storage pools capacity",
Description: "List of storage pools capacity.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_MaxAllocationSize: {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum allocation storage size (GB)",
Description: "Maximum allocation storage size (GB).",
Type: schema.TypeInt,
},
Attr_PoolName: {
Type: schema.TypeString,
Computed: true,
Description: "Pool name",
Description: "The pool name",
Type: schema.TypeString,
},
Attr_StorageType: {
Type: schema.TypeString,
Computed: true,
Description: "Storage type of the storage pool",
Description: "Storage type of the storage pool.",
Type: schema.TypeString,
},
Attr_TotalCapacity: {
Type: schema.TypeInt,
Computed: true,
Description: "Total pool capacity (GB)",
Description: "Total pool capacity (GB).",
Type: schema.TypeInt,
},
},
},
Type: schema.TypeList,
},
},
}
Expand All @@ -84,10 +79,10 @@ func dataSourceIBMPIStorageTypeCapacityRead(ctx context.Context, d *schema.Resou
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
storageType := d.Get(PITypeName).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
storageType := d.Get(Arg_StorageType).(string)

client := st.NewIBMPIStorageCapacityClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPIStorageCapacityClient(ctx, sess, cloudInstanceID)
stc, err := client.GetStorageTypeCapacity(storageType)
if err != nil {
log.Printf("[ERROR] get storage type capacity failed %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func testAccCheckIBMPIStorageTypeCapacityDataSourceConfig() string {
data "ibm_pi_storage_type_capacity" "type" {
pi_cloud_instance_id = "%s"
pi_storage_type = "%s"
}
`, acc.Pi_cloud_instance_id, acc.PiStorageType)
}`, acc.Pi_cloud_instance_id, acc.PiStorageType)
}
61 changes: 28 additions & 33 deletions ibm/service/power/data_source_ibm_pi_storage_types_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,79 @@ package power

import (
"context"

"log"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"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"

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/hashicorp/go-uuid"
"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"
)

const (
StorageTypesCapacity = "storage_types_capacity"
)

func DataSourceIBMPIStorageTypesCapacity() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIStorageTypesCapacityRead,
Schema: map[string]*schema.Schema{
helpers.PICloudInstanceId: {
Type: schema.TypeString,
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
// Computed Attributes

// Attributes
Attr_MaximumStorageAllocation: {
Type: schema.TypeMap,
Computed: true,
Description: "Maximum storage allocation",
Description: "Maximum storage allocation.",
Type: schema.TypeMap,
},
StorageTypesCapacity: {
Attr_StorageTypesCapacity: {
Type: schema.TypeList,
Computed: true,
Description: "Storage types capacity",
Description: "List of storage types capacity.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_MaximumStorageAllocation: {
Type: schema.TypeMap,
Computed: true,
Description: "Maximum storage allocation",
Description: "Maximum storage allocation.",
Type: schema.TypeMap,
},
Attr_StoragePoolsCapacity: {
Type: schema.TypeList,
Computed: true,
Description: "Storage pools capacity",
Description: "List of storage types capacity.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_MaxAllocationSize: {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum allocation storage size (GB)",
Description: "Maximum allocation storage size (GB).",
Type: schema.TypeInt,
},
Attr_PoolName: {
Type: schema.TypeString,
Computed: true,
Description: "Pool name",
Description: "The pool name.",
Type: schema.TypeString,
},
Attr_StorageType: {
Type: schema.TypeString,
Computed: true,
Description: "Storage type of the storage pool",
Description: "Storage type of the storage pool.",
Type: schema.TypeString,
},
Attr_TotalCapacity: {
Type: schema.TypeInt,
Computed: true,
Description: "Total pool capacity (GB)",
Description: "Total pool capacity (GB).",
Type: schema.TypeInt,
},
},
},
Type: schema.TypeList,
},
Attr_StorageType: {
Type: schema.TypeString,
Computed: true,
Description: "The storage type",
Description: "The storage type.",
Type: schema.TypeString,
},
},
},
Expand All @@ -97,9 +92,9 @@ func dataSourceIBMPIStorageTypesCapacityRead(ctx context.Context, d *schema.Reso
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)

client := st.NewIBMPIStorageCapacityClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPIStorageCapacityClient(ctx, sess, cloudInstanceID)
stc, err := client.GetAllStorageTypesCapacity()
if err != nil {
log.Printf("[ERROR] get all storage types capacity failed %v", err)
Expand Down Expand Up @@ -145,7 +140,7 @@ func dataSourceIBMPIStorageTypesCapacityRead(ctx context.Context, d *schema.Reso
stcResult = append(stcResult, stResult)
}

d.Set(StorageTypesCapacity, stcResult)
d.Set(Attr_StorageTypesCapacity, stcResult)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ func testAccCheckIBMPIStorageTypesCapacityDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_storage_types_capacity" "types" {
pi_cloud_instance_id = "%s"
}
`, acc.Pi_cloud_instance_id)
}`, acc.Pi_cloud_instance_id)
}
3 changes: 1 addition & 2 deletions ibm/service/power/data_source_ibm_pi_system_pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ func testAccCheckIBMPISystemPoolsDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_system_pools" "pools" {
pi_cloud_instance_id = "%s"
}
`, acc.Pi_cloud_instance_id)
}`, acc.Pi_cloud_instance_id)
}
12 changes: 4 additions & 8 deletions website/docs/d/pi_storage_type_capacity.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

subcategory: "Power Systems"
layout: "ibm"
page_title: "IBM: pi_storage_type_capacity"
Expand All @@ -11,7 +10,6 @@ description: |-
Retrieve information about storages capacity for a storage type in a region. For more information, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started).

## Example usage

```terraform
data "ibm_pi_storage_type_capacity" "type" {
pi_cloud_instance_id = "<value of the cloud_instance_id>"
Expand All @@ -20,14 +18,12 @@ data "ibm_pi_storage_type_capacity" "type" {
```

**Notes**

* Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints.
* If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows:
* `region` - `lon`
* `zone` - `lon04`
- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints.
- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows:
- `region` - `lon`
- `zone` - `lon04`

Example usage:

```terraform
provider "ibm" {
region = "lon"
Expand Down
Loading

0 comments on commit 6c7c7d9

Please sign in to comment.