Skip to content

Commit

Permalink
[Datasource] Storage tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad committed Sep 19, 2024
1 parent 2aa2176 commit a91f788
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 7 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-20240719075425-078fcb3a55be
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.7.0
github.com/IBM-Cloud/power-go-client v1.8.1
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
8 changes: 2 additions & 6 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-20240719075425-078fcb3a55be/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.7.0 h1:/GuGwPMTKoCZACfnwt7b6wKr4v32q1VO1AMFGNETRN4=
github.com/IBM-Cloud/power-go-client v1.7.0/go.mod h1:9izycYAmNQ+NAdVPXDC3fHYxqWLjlR2YiwqKYveMv5Y=
github.com/IBM-Cloud/power-go-client v1.8.1 h1:tx1aPJmIQrNru1MD1VHGNasGx3eRIs0zzPZ0KvdFQrg=
github.com/IBM-Cloud/power-go-client v1.8.1/go.mod h1:N4RxrsMUvBQjSQ/qPk0iMZ8zK+fZPRTnHi/gTaASw0g=
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 All @@ -138,8 +138,6 @@ github.com/IBM/container-registry-go-sdk v1.1.0 h1:sYyknIod8R4RJZQqAheiduP6wbSTp
github.com/IBM/container-registry-go-sdk v1.1.0/go.mod h1:4TwsCnQtVfZ4Vkapy/KPvQBKFc3VOyUZYkwRU4FTPrs=
github.com/IBM/continuous-delivery-go-sdk v1.6.0 h1:eAL/jIWHrDFlWDF+Qd9Y5UN99Pr5Mjd/H/bvTbXUbz4=
github.com/IBM/continuous-delivery-go-sdk v1.6.0/go.mod h1:nZdKUnubXNLo+zo28R4Rd+TGDqiJ/xoE8WO/A3kLw1E=
github.com/IBM/event-notifications-go-admin-sdk v0.8.0 h1:xk2CYTayQtKi6LSgGGFRxFJfWUxyM5SY8Rs64ducAhw=
github.com/IBM/event-notifications-go-admin-sdk v0.8.0/go.mod h1:OByvqfrNVxs7G6ggv8pwQCEVw10/TBJCLh7NM3z707w=
github.com/IBM/event-notifications-go-admin-sdk v0.9.0 h1:eaCd+GkxhNyot+8rA9WkAQdlVYrRD20LYiXjEytFO6M=
github.com/IBM/event-notifications-go-admin-sdk v0.9.0/go.mod h1:OByvqfrNVxs7G6ggv8pwQCEVw10/TBJCLh7NM3z707w=
github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM=
Expand Down Expand Up @@ -187,8 +185,6 @@ github.com/IBM/scc-go-sdk/v5 v5.4.1 h1:RXIuxOo9/hxkWyHCI69ae+KIJgSbXcAkJwTEl+fO3
github.com/IBM/scc-go-sdk/v5 v5.4.1/go.mod h1:2xQTDgNXG5QMEfQxBDKB067z+5ha6OgcaKCTcdGDAo8=
github.com/IBM/schematics-go-sdk v0.2.3 h1:lgTt0Sbudii3cuSk1YSQgrtiZAXDbBABAoVj3eQuBrU=
github.com/IBM/schematics-go-sdk v0.2.3/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5 h1:VMc/Zd6RzB8j60CqZekkwYT2wQsCfrkGV2n01Gviuaw=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5/go.mod h1:5kUgJ1dG9cdiAcPDqVz46m362bPnoqZQSth24NiowSg=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6 h1:bF6bAdI4wDZSje6+Yx1mJxvirboxO+uMuKhzgfRCNxE=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6/go.mod h1:XWYnbcc5vN1RnKwk/fCzfD8aZd7At/Y1/b6c+oDyliU=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
Expand Down
1 change: 1 addition & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ func Provider() *schema.Provider {
"ibm_pi_spp_placement_groups": power.DataSourceIBMPISPPPlacementGroups(),
"ibm_pi_storage_pool_capacity": power.DataSourceIBMPIStoragePoolCapacity(),
"ibm_pi_storage_pools_capacity": power.DataSourceIBMPIStoragePoolsCapacity(),
"ibm_pi_storage_tiers": power.DataSourceIBMPIStorageTiers(),
"ibm_pi_storage_type_capacity": power.DataSourceIBMPIStorageTypeCapacity(),
"ibm_pi_storage_types_capacity": power.DataSourceIBMPIStorageTypesCapacity(),
"ibm_pi_system_pools": power.DataSourceIBMPISystemPools(),
Expand Down
100 changes: 100 additions & 0 deletions ibm/service/power/data_source_ibm_pi_storage_tiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package power

import (
"context"

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

func DataSourceIBMPIStorageTiers() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIStorageTiersRead,

Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
// Attributes
Attr_RegionStorageTiers: {
Computed: true,
Description: "An array of of storage tiers supported in a region.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_Description: {
Computed: true,
Description: "Description, storage tier label.",
Type: schema.TypeString,
},
Attr_Name: {
Computed: true,
Description: "Name of the storage tier.",
Type: schema.TypeString,
},
Attr_State: {
Computed: true,
Description: "State of the storage tier (active or inactive).",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
},
}
}

func dataSourceIBMPIStorageTiersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
}

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

client := instance.NewIBMPIStorageTierClient(ctx, sess, cloudInstanceID)
rst, err := client.GetAll()
if err != nil {
return diag.FromErr(err)
}
var genID, _ = uuid.GenerateUUID()
d.SetId(genID)

regionStorageTiers := []map[string]interface{}{}
if len(rst) > 0 {
for _, storageTier := range rst {
regionStorageTier := storageTierToMap(storageTier)
regionStorageTiers = append(regionStorageTiers, regionStorageTier)
}
}
d.Set(Attr_RegionStorageTiers, regionStorageTiers)

return nil
}

func storageTierToMap(storageTier *models.StorageTier) map[string]interface{} {
storageTierMap := make(map[string]interface{})
if storageTier.Description != "" {
storageTierMap[Attr_Description] = storageTier.Description
}
if storageTier.Name != "" {
storageTierMap[Attr_Name] = storageTier.Name
}
if storageTier.State != nil {
storageTierMap[Attr_State] = storageTier.State
}
return storageTierMap
}
35 changes: 35 additions & 0 deletions ibm/service/power/data_source_ibm_pi_storage_tiers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package power_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMPIStorageTiersDataSourceBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIStorageTiersDataSourceConfigBasic(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_storage_tiers.storage_tiers", "id"),
),
},
},
})
}

func testAccCheckIBMPIStorageTiersDataSourceConfigBasic() string {
return fmt.Sprintf(`
data "ibm_pi_storage_tiers" "storage_tiers" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const (
Attr_PVMInstances = "pvm_instances"
Attr_PVMSnapshots = "pvm_snapshots"
Attr_Region = "region"
Attr_RegionStorageTiers = "region_storage_tiers"
Attr_RemoteCopyID = "remote_copy_id"
Attr_RemoteCopyRelationshipNames = "remote_copy_relationship_names"
Attr_RemoteCopyRelationships = "remote_copy_relationships"
Expand Down
52 changes: 52 additions & 0 deletions website/docs/d/pi_storage_tiers.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
layout: "ibm"
page_title: "IBM : ibm_pi_storage_tiers"
description: |-
Get information about a storage tiers for a pi cloud instance.
subcategory: "Power Systems"
---

# ibm_pi_storage_tiers

Retrieve information about supported storage tiers for a pi cloud instance. For more information, see [storage tiers docs](https://cloud.ibm.com/apidocs/power-cloud#pcloud-cloudinstances-storagetiers-getall).

## Example Usage

```terraform
data "ibm_pi_storage_tiers" "pi_storage_tiers" {
pi_cloud_instance_id = "<value of the cloud_instance_id>"
}
```

### 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`

Example usage:

```terraform
provider "ibm" {
region = "lon"
zone = "lon04"
}
```

## Argument Reference

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

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

## Attribute Reference

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

- `id` - (String) The unique identifier of the storage tiers.
- `region_storage_tiers` - (List) An array of of storage tiers supported in a region.
Nested schema for `region_storage_tiers`:
- `description` - (String) Description, storage tier label.
- `name` - (String) Name of the storage tier.
- `state` - (String) State of the storage tier, `active` or `inactive`.

0 comments on commit a91f788

Please sign in to comment.