Skip to content

Commit

Permalink
Catalog-refactor disaster recovery location data source and documenta…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Diptipowervs committed Dec 28, 2023
1 parent 87cfb7c commit d113b02
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 71 deletions.
51 changes: 27 additions & 24 deletions ibm/service/power/data_source_ibm_pi_disaster_recovery_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,50 @@ package power
import (
"context"

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

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

func DataSourceIBMPIDisasterRecoveryLocation() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDisasterRecoveryLocation,
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
PIDRLocation: {
Type: schema.TypeString,
// Attributes
Attr_Location: {
Computed: true,
Description: "RegionZone of a site",
Description: "The region zone of a site.",
Type: schema.TypeString,
},
"replication_sites": {
Type: schema.TypeList,
Computed: true,
Attr_ReplicationSites: {
Computed: true,
Description: "List of replication sites.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_active": {
Type: schema.TypeBool,
Computed: true,
Attr_IsActive: {
Computed: true,
Description: "Indicates the location is active or not, true if location is active , otherwise it is false.",
Type: schema.TypeBool,
},
PIDRLocation: {
Type: schema.TypeString,
Computed: true,
Attr_Location: {
Computed: true,
Description: "The region zone of the location.",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
},
}
Expand All @@ -58,7 +61,7 @@ func dataSourceIBMPIDisasterRecoveryLocation(ctx context.Context, d *schema.Reso
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
drClient := instance.NewIBMPIDisasterRecoveryLocationClient(ctx, sess, cloudInstanceID)
drLocationSite, err := drClient.Get()
if err != nil {
Expand All @@ -69,17 +72,17 @@ func dataSourceIBMPIDisasterRecoveryLocation(ctx context.Context, d *schema.Reso
for _, i := range drLocationSite.ReplicationSites {
if i != nil {
l := map[string]interface{}{
"is_active": i.IsActive,
PIDRLocation: i.Location,
Attr_IsActive: i.IsActive,
Attr_Location: i.Location,
}
result = append(result, l)
}
}

var clientgenU, _ = uuid.GenerateUUID()
d.SetId(clientgenU)
d.Set(PIDRLocation, drLocationSite.Location)
d.Set("replication_sites", result)
d.Set(Attr_Location, drLocationSite.Location)
d.Set(Attr_ReplicationSites, result)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestAccIBMPIDisasterRecoveryLocationDataSourceBasic(t *testing.T) {

func testAccCheckIBMPIDisasterRecoveryLocationDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_disaster_recovery_location" "testacc_disaster_recovery_location" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)

data "ibm_pi_disaster_recovery_location" "testacc_disaster_recovery_location" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
47 changes: 24 additions & 23 deletions ibm/service/power/data_source_ibm_pi_disaster_recovery_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,46 @@ package power
import (
"context"

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

func DataSourceIBMPIDisasterRecoveryLocations() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDisasterRecoveryLocations,
Schema: map[string]*schema.Schema{

// Computed Attributes
"disaster_recovery_locations": {
// Attributes
Attr_DisasterRecoveryLocations: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
PIDRLocation: {
Type: schema.TypeString,
Attr_Location: {
Computed: true,
Description: "RegionZone of a site",
Description: "The region zone of a site.",
Type: schema.TypeString,
},
"replication_sites": {
Type: schema.TypeList,
Computed: true,
Attr_ReplicationSites: {
Computed: true,
Description: "List of Replication Sites.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_active": {
Type: schema.TypeBool,
Computed: true,
Attr_IsActive: {
Computed: true,
Description: "Indicates the location is active or not, true if location is active, otherwise it is false.",
Type: schema.TypeBool,
},
PIDRLocation: {
Type: schema.TypeString,
Computed: true,
Attr_Location: {
Computed: true,
Description: "The region zone of the location.",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
},
},
Expand Down Expand Up @@ -72,23 +73,23 @@ func dataSourceIBMPIDisasterRecoveryLocations(ctx context.Context, d *schema.Res
for _, j := range i.ReplicationSites {
if j != nil {
r := map[string]interface{}{
"is_active": j.IsActive,
PIDRLocation: j.Location,
Attr_IsActive: j.IsActive,
Attr_Location: j.Location,
}
replicationSites = append(replicationSites, r)
}
}
l := map[string]interface{}{
"location": i.Location,
"replication_sites": replicationSites,
Attr_Location: i.Location,
Attr_ReplicationSites: replicationSites,
}
results = append(results, l)
}
}

var clientgenU, _ = uuid.GenerateUUID()
d.SetId(clientgenU)
d.Set("disaster_recovery_locations", results)
d.Set(Attr_DisasterRecoveryLocations, results)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func TestAccIBMPIDisasterRecoveryLocationsDataSourceBasic(t *testing.T) {
}

func testAccCheckIBMPIDisasterRecoveryLocationsDataSourceConfig() string {
return "data \"ibm_pi_disaster_recovery_locations\" \"testacc_disaster_recovery_locations\" {}"
return `data "ibm_pi_disaster_recovery_locations" "testacc_disaster_recovery_locations" {}`
}
20 changes: 10 additions & 10 deletions website/docs/d/pi_disaster_recovery_location.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_disaster_recovery_location"
Expand All @@ -18,20 +17,21 @@ data "ibm_pi_disaster_recovery_location" "ds_disaster_recovery_location" {
pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b"
}
```

**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:
Example usage:
```terraform
provider "ibm" {
region = "lon"
zone = "lon04"
}
```

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

Expand All @@ -41,8 +41,8 @@ Review the argument references that you can specify for your data source.
In addition to all argument reference list, you can access the following attribute references after your data source is created.

- `location` - (String) The region zone of a site.
- `replication_sites` - List of replication sites.
- `replication_sites` - (List) List of replication sites.

Nested scheme for `replication_sites`:
- `is_active` - (Boolean) Indicates the location is active or not, `true` if location is active , otherwise it is `false`.
- `location` - (String) The region zone of the location.
- `is_active` - (Bool) Indicates the location is active or not, `true` if location is active , otherwise it is `false`.
- `location` - (String) The region zone of the location.
18 changes: 9 additions & 9 deletions website/docs/d/pi_disaster_recovery_locations.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_disaster_recovery_locations"
Expand All @@ -16,13 +15,14 @@ The following example retrieves information about the disaster recovery location
```terraform
data "ibm_pi_disaster_recovery_locations" "ds_disaster_recovery_locations" {}
```

**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:
Example usage:
```terraform
provider "ibm" {
region = "lon"
Expand All @@ -39,6 +39,6 @@ In addition to all argument reference list, you can access the following attribu
- `location` - (String) The region zone of a site.
- `replication_sites` - List of Replication Sites.

Nested scheme for `replication_sites`:
- `is_active` - (Boolean) Indicates the location is active or not, `true` if location is active, otherwise it is `false`.
- `location` - (String) The region zone of the location.
Nested scheme for `replication_sites`:
- `is_active` - (Bool) Indicates the location is active or not, `true` if location is active, otherwise it is `false`.
- `location` - (String) The region zone of the location.

0 comments on commit d113b02

Please sign in to comment.