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

Refactor datacenter and datacenters data source and documentation #26

Closed
wants to merge 4 commits 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
42 changes: 20 additions & 22 deletions ibm/service/power/data_source_ibm_pi_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,52 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const (
DatacenterRegion = "region"
DatacenterType = "type"
DatacenterUrl = "url"
)

func DataSourceIBMPIDatacenter() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDatacenterRead,
Schema: map[string]*schema.Schema{
// Arguments
Arg_DatacenterZone: {
Type: schema.TypeString,
Description: "Datacenter zone you want to retrieve.",
Optional: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},

// Attributes
Attr_DatacenterCapabilities: {
Type: schema.TypeMap,
Computed: true,
Description: "Datacenter Capabilities",
Description: "Datacenter Capabilities.",
Elem: &schema.Schema{
Type: schema.TypeBool,
},
Type: schema.TypeMap,
},
Attr_DatacenterHref: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter href",
Description: "Datacenter href.",
Type: schema.TypeString,
},
Attr_DatacenterLocation: {
Type: schema.TypeMap,
Computed: true,
Description: "Datacenter location",
Description: "Datacenter location.",
Type: schema.TypeMap,
},
Attr_DatacenterStatus: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter status",
Description: "Datacenter status, active,maintenance or down.",
Type: schema.TypeString,
},
Attr_DatacenterType: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter type",
Description: "Datacenter type, off-premises or on-premises.",
Type: schema.TypeString,
},
},
}
}

func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
// session
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
Expand All @@ -81,14 +79,14 @@ func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData,
d.SetId(genID)
d.Set(Attr_DatacenterCapabilities, dcData.Capabilities)
dclocation := map[string]interface{}{
DatacenterRegion: *dcData.Location.Region,
DatacenterType: *dcData.Location.Type,
DatacenterUrl: *dcData.Location.URL,
Attr_Region: *dcData.Location.Region,
Attr_Type: *dcData.Location.Type,
Attr_URL: *dcData.Location.URL,
}
d.Set(Attr_DatacenterHref, dcData.Href)
d.Set(Attr_DatacenterLocation, flex.Flatten(dclocation))
d.Set(Attr_DatacenterStatus, dcData.Status)
d.Set(Attr_DatacenterType, dcData.Type)
d.Set(Attr_DatacenterHref, dcData.Href)

return nil
}
6 changes: 2 additions & 4 deletions ibm/service/power/data_source_ibm_pi_datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package power_test

import (
"fmt"
"testing"

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

func testAccCheckIBMPIDatacenterDataSourceConfig() string {
return fmt.Sprintf(`
return `
data "ibm_pi_datacenter" "test" {
pi_datacenter_zone = "dal12"
}
`)
}`
}
36 changes: 16 additions & 20 deletions ibm/service/power/data_source_ibm_pi_datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,53 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
Datacenters = "datacenters"
)

func DataSourceIBMPIDatacenters() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDatacentersRead,
Schema: map[string]*schema.Schema{
Datacenters: {
Type: schema.TypeList,
Computed: true,
// Attributes
Attr_Datacenters: {
Type: schema.TypeList,
Computed: true,
Description: "List of Datacenters",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

Attr_DatacenterCapabilities: {
Type: schema.TypeMap,
Computed: true,
Description: "Datacenter Capabilities",
Elem: &schema.Schema{
Type: schema.TypeBool,
},
Type: schema.TypeMap,
},
Attr_DatacenterHref: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter href",
Type: schema.TypeString,
},
Attr_DatacenterLocation: {
Type: schema.TypeMap,
Computed: true,
Description: "Datacenter location",
Type: schema.TypeMap,
},
Attr_DatacenterStatus: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter status",
Type: schema.TypeString,
},
Attr_DatacenterType: {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter type",
Type: schema.TypeString,
},
},
},
},
},
}
}

func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
// session
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
Expand All @@ -77,21 +74,20 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData,
if datacenter != nil {
dc := map[string]interface{}{
Attr_DatacenterCapabilities: datacenter.Capabilities,
Attr_DatacenterHref: datacenter.Href,
Attr_DatacenterLocation: map[string]interface{}{
DatacenterRegion: datacenter.Location.Region,
DatacenterType: datacenter.Location.Type,
DatacenterUrl: datacenter.Location.URL,
Attr_Region: datacenter.Location.Region,
Attr_Type: datacenter.Location.Type,
Attr_URL: datacenter.Location.URL,
},
Attr_DatacenterStatus: datacenter.Status,
Attr_DatacenterType: datacenter.Type,
Attr_DatacenterHref: datacenter.Href,
}
datacenters = append(datacenters, dc)
}

}
var clientgenU, _ = uuid.GenerateUUID()
d.SetId(clientgenU)
d.Set(Datacenters, datacenters)
d.Set(Attr_Datacenters, datacenters)
return nil
}
3 changes: 1 addition & 2 deletions ibm/service/power/data_source_ibm_pi_datacenters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package power_test

import (
"fmt"
"testing"

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

func testAccCheckIBMPIDatacentersDataSourceConfig() string {
return fmt.Sprintf(`data "ibm_pi_datacenters" "test" {}`)
return `data "ibm_pi_datacenters" "test" {}`
}
20 changes: 7 additions & 13 deletions website/docs/d/pi_datacenter.html.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

subcategory: "Power Systems"
layout: "ibm"
page_title: "IBM: pi_datacenter"
Expand All @@ -8,26 +7,22 @@ description: |-
---

# ibm_pi_datacenter

Retrieve information about a Power Systems Datacenter.

## Example usage

```terraform
data "ibm_pi_datacenter" "datacenter" {
pi_datacenter_zone= "dal12"
}
```

## Notes

**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"
Expand All @@ -36,25 +31,24 @@ Example usage:
```

## Argument reference

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

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

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

- `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`.

Some of `pi_datacenter_capabilities` are:
- `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections`

- `pi_datacenter_href` - (String) Datacenter href.
- `pi_datacenter_location` - (Map) Datacenter location.

Nested schema for `pi_datacenter_location`:
- `region` - (String) The Datacenter location region zone.
- `type` - (String) The Datacenter location region type.
- `url`- (String) The Datacenter location region url.
- `pi_datacenter_status` - (String) The Datacenter status, `active`,`maintenance` or `down`.
- `pi_datacenter_type` - (String) The Datacenter type, `off-premises` or `on-premises`.
- `region` - (String) Datacenter location region zone.
- `type` - (String) Datacenter location region type.
- `url`- (String) Datacenter location region url.
- `pi_datacenter_status` - (String) Datacenter status, `active`,`maintenance` or `down`.
- `pi_datacenter_type` - (String) Datacenter type, `off-premises` or `on-premises`.
23 changes: 9 additions & 14 deletions website/docs/d/pi_datacenters.html.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

subcategory: "Power Systems"
layout: "ibm"
page_title: "IBM: pi_datacenters"
Expand All @@ -8,26 +7,22 @@ description: |-
---

# ibm_pi_datacenters

Retrieve information about Power Systems Datacenters.

## Example usage

The following example retrieves information about Power Systems Datacenters.

```terraform
data "ibm_pi_datacenters" "datacenters" {}
```

## Notes

**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"
Expand All @@ -36,22 +31,22 @@ Example usage:
```

## Attribute reference

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

- `datacenters` - List of Datacenters
- `datacenters` - (List) List of Datacenters

Nested schema for `datacenters`
- `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`.

Some of `pi_datacenter_capabilities` are:
- `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections`


- `pi_datacenter_href` - (String) Datacenter href.
- `pi_datacenter_location` - (Map) Datacenter location.

Nested schema for `pi_datacenter_location`:
- `region` - (String) The Datacenter location region zone.
- `type` - (String) The Datacenter location region type.
- `url`- (String) The Datacenter location region url.
- `pi_datacenter_status` - (String) The Datacenter status, `active`,`maintenance` or `down`.
- `pi_datacenter_type` - (String) The Datacenter type, `off-premises` or `on-premises`.
- `region` - (String) Datacenter location region zone.
- `type` - (String) Datacenter location region type.
- `url`- (String) Datacenter location region url.
- `pi_datacenter_status` - (String) Datacenter status, `active`,`maintenance` or `down`.
- `pi_datacenter_type` - (String) Datacenter type, `off-premises` or `on-premises`.
Loading