Skip to content

Commit

Permalink
Catalog-refactor public network-pvm instance snapshot data source and…
Browse files Browse the repository at this point in the history
… documentation
  • Loading branch information
Diptipowervs committed Dec 28, 2023
1 parent e1a16c2 commit d751593
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 112 deletions.
49 changes: 25 additions & 24 deletions ibm/service/power/data_source_ibm_pi_public_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@
package power

import (
//"fmt"
"context"

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

return &schema.Resource{
ReadContext: dataSourceIBMPIPublicNetworkRead,
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
"name": {
Type: schema.TypeString,
Computed: true,
// Attributes
Attr_Name: {
Computed: true,
Description: "The name of the network.",
Type: schema.TypeString,
},
"type": {
Type: schema.TypeString,
Computed: true,
Attr_Type: {
Computed: true,
Description: "The type of VLAN that the network is connected to.",
Type: schema.TypeString,
},
"vlan_id": {
Type: schema.TypeInt,
Computed: true,
Attr_VLanID: {
Computed: true,
Description: "The ID of the VLAN that the network is connected to.",
Type: schema.TypeInt,
},
},
}
Expand All @@ -50,7 +51,7 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(err)
}

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

networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID)
networkdata, err := networkC.GetAllPublic()
Expand All @@ -62,14 +63,14 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat
}

d.SetId(*networkdata.Networks[0].NetworkID)
if networkdata.Networks[0].Type != nil {
d.Set("type", networkdata.Networks[0].Type)
}
if networkdata.Networks[0].Name != nil {
d.Set("name", networkdata.Networks[0].Name)
d.Set(Attr_Name, networkdata.Networks[0].Name)
}
if networkdata.Networks[0].Type != nil {
d.Set(Attr_Type, networkdata.Networks[0].Type)
}
if networkdata.Networks[0].VlanID != nil {
d.Set("vlan_id", networkdata.Networks[0].VlanID)
d.Set(Attr_VLanID, networkdata.Networks[0].VlanID)
}

return nil
Expand Down
7 changes: 3 additions & 4 deletions ibm/service/power/data_source_ibm_pi_public_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func TestAccIBMPIPublicNetworkDataSource_basic(t *testing.T) {

func testAccCheckIBMPIPublicNetworkDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_public_network" "testacc_ds_public_network" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)

data "ibm_pi_public_network" "testacc_ds_public_network" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
113 changes: 58 additions & 55 deletions ibm/service/power/data_source_ibm_pi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/go-uuid"
Expand All @@ -18,65 +17,73 @@ import (
)

func DataSourceIBMPISnapshot() *schema.Resource {

return &schema.Resource{
ReadContext: dataSourceIBMPISnapshotRead,
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,
},

helpers.PIInstanceName: {
Type: schema.TypeString,
Arg_InstanceName: {
Description: "The unique identifier or name of the instance.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
//Computed Attributes

"pvm_snapshots": {
// Attributes
Attr_PVMSnapshots: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Attr_Action: {
Computed: true,
Description: "Action performed on the instance snapshot.",
Type: schema.TypeString,
},
"name": {
Type: schema.TypeString,
Computed: true,
Attr_CreationDate: {
Computed: true,
Description: "Date of snapshot creation.",
Type: schema.TypeString,
},
"percent_complete": {
Type: schema.TypeInt,
Computed: true,
Attr_Description: {
Computed: true,
Description: "The description of the snapshot.",
Type: schema.TypeString,
},

"description": {
Type: schema.TypeString,
Computed: true,
Attr_ID: {
Computed: true,
Description: "The unique identifier of the Power Virtual Machine instance snapshot.",
Type: schema.TypeString,
},
"action": {
Type: schema.TypeString,
Computed: true,
Attr_LastUpdatedDate: {
Computed: true,
Description: "Date of last update.",
Type: schema.TypeString,
},
"status": {
Type: schema.TypeString,
Computed: true,
Attr_Name: {
Computed: true,
Description: "The name of the Power Virtual Machine instance snapshot.",
Type: schema.TypeString,
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Attr_PercentComplete: {
Computed: true,
Description: "The snapshot completion percentage.",
Type: schema.TypeInt,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
Attr_Status: {
Computed: true,
Description: "The status of the Power Virtual Machine instance snapshot.",
Type: schema.TypeString,
},
"volume_snapshots": {
Type: schema.TypeMap,
Computed: true,
Attr_VolumeSnapshots: {
Computed: true,
Description: "A map of volume snapshots included in the Power Virtual Machine instance snapshot.",
Type: schema.TypeMap,
},
},
},
Expand All @@ -86,14 +93,13 @@ func DataSourceIBMPISnapshot() *schema.Resource {
}

func dataSourceIBMPISnapshotRead(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(helpers.PICloudInstanceId).(string)
powerinstancename := d.Get(helpers.PIInstanceName).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
powerinstancename := d.Get(Arg_InstanceName).(string)
snapshot := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)
snapshotData, err := snapshot.GetSnapShotVM(powerinstancename)

Expand All @@ -103,30 +109,27 @@ func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, me

var clientgenU, _ = uuid.GenerateUUID()
d.SetId(clientgenU)
d.Set("pvm_snapshots", flattenPVMSnapshotInstances(snapshotData.Snapshots))
d.Set(Attr_PVMSnapshots, flattenPVMSnapshotInstances(snapshotData.Snapshots))

return nil

}

func flattenPVMSnapshotInstances(list []*models.Snapshot) []map[string]interface{} {
log.Printf("Calling the flattensnapshotinstances call with list %d", len(list))
log.Printf("Calling the flattenPVMSnapshotInstances call with list %d", len(list))
result := make([]map[string]interface{}, 0, len(list))
for _, i := range list {
l := map[string]interface{}{
"id": *i.SnapshotID,
"name": *i.Name,
"description": i.Description,
"creation_date": i.CreationDate.String(),
"last_updated_date": i.LastUpdateDate.String(),
"action": i.Action,
"percent_complete": i.PercentComplete,
"status": i.Status,
"volume_snapshots": i.VolumeSnapshots,
Attr_Action: i.Action,
Attr_CreationDate: i.CreationDate.String(),
Attr_Description: i.Description,
Attr_ID: *i.SnapshotID,
Attr_LastUpdatedDate: i.LastUpdateDate.String(),
Attr_Name: *i.Name,
Attr_PercentComplete: i.PercentComplete,
Attr_Status: i.Status,
Attr_VolumeSnapshots: i.VolumeSnapshots,
}

result = append(result, l)
}

return result
}
10 changes: 4 additions & 6 deletions ibm/service/power/data_source_ibm_pi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func TestAccIBMPISnapshotDataSource_basic(t *testing.T) {

func testAccCheckIBMPISnapshotDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_pvm_snapshots" "testacc_pi_snapshots" {
pi_instance_name = "%s"
pi_cloud_instance_id = "%s"
}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id)

data "ibm_pi_pvm_snapshots" "testacc_pi_snapshots" {
pi_instance_name = "%s"
pi_cloud_instance_id = "%s"
}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id)
}
16 changes: 6 additions & 10 deletions website/docs/d/pi_public_network.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_public_network"
Expand All @@ -8,32 +7,29 @@ description: |-
---

# ibm_pi_public_network
Retrieve the details about a public network that is used for your Power Systems Virtual Server instance. For more information, about public network in IBM power virutal server, see [adding or removing a public network
Retrieve the details about a public network that is used for your Power Systems Virtual Server instance. For more information, about public network in IBM power virtual server, see [adding or removing a public network
](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-modifying-server#adding-removing-network).

## Example usage

```terraform
data "ibm_pi_public_network" "ds_public_network" {
pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b"
}
```

**Note**
* 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`
**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.
Expand Down
Loading

0 comments on commit d751593

Please sign in to comment.