forked from IBM-Cloud/terraform-provider-ibm
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add [D]: pi_network_peers Update [D]: pi_network, pi_networks Update [R]: pi_network Add require option Add v1.9.0 fix spacing in cst file Co-authored-by: michaelkad <michaelkadiayi@gmail.com>
- Loading branch information
Showing
10 changed files
with
276 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright IBM Corp. 2024 All Rights Reserved. | ||
// Licensed under the Mozilla Public License v2.0 | ||
|
||
package power | ||
|
||
import ( | ||
"context" | ||
|
||
"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/power/models" | ||
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" | ||
) | ||
|
||
func DataSourceIBMPINetworkPeers() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceIBMPINetworkPeersRead, | ||
|
||
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_NetworkPeers: { | ||
Computed: true, | ||
Description: "List of network peers.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
Attr_Description: { | ||
Computed: true, | ||
Description: "Description of the network peer.", | ||
Type: schema.TypeString, | ||
}, | ||
Attr_ID: { | ||
Computed: true, | ||
Description: "ID of the network peer.", | ||
Type: schema.TypeString, | ||
}, | ||
Attr_Name: { | ||
Computed: true, | ||
Description: "Name of the network peer.", | ||
Type: schema.TypeString, | ||
}, | ||
Attr_Type: { | ||
Computed: true, | ||
Description: "Type of the network peer.", | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
Type: schema.TypeList, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceIBMPINetworkPeersRead(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) | ||
|
||
networkC := instance.NewIBMPINetworkPeerClient(ctx, sess, cloudInstanceID) | ||
networkdata, err := networkC.GetNetworkPeers() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
var clientgenU, _ = uuid.GenerateUUID() | ||
d.SetId(clientgenU) | ||
|
||
networkPeers := []map[string]interface{}{} | ||
if networkdata.NetworkPeers != nil { | ||
for _, np := range networkdata.NetworkPeers { | ||
npMap := dataSourceIBMPINetworkPeersNetworkPeerToMap(np) | ||
|
||
networkPeers = append(networkPeers, npMap) | ||
} | ||
} | ||
d.Set(Attr_NetworkPeers, networkPeers) | ||
|
||
return nil | ||
} | ||
|
||
func dataSourceIBMPINetworkPeersNetworkPeerToMap(np *models.NetworkPeer) map[string]interface{} { | ||
npMap := make(map[string]interface{}) | ||
if np.Description != nil { | ||
npMap[Attr_Description] = np.Description | ||
} | ||
if np.ID != nil { | ||
npMap[Attr_ID] = np.ID | ||
} | ||
if np.Name != nil { | ||
npMap[Attr_Name] = np.Name | ||
} | ||
if np.Type != nil { | ||
npMap[Attr_Type] = np.Type | ||
} | ||
return npMap | ||
} |
37 changes: 37 additions & 0 deletions
37
ibm/service/power/data_source_ibm_pi_network_peers_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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 TestAccIBMPINetworkPeersDataSourceBasic(t *testing.T) { | ||
networksResData := "data.ibm_pi_network_peers.network_peers" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
Providers: acc.TestAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckIBMPINetworkPeersDataSourceConfigBasic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(networksResData, "id"), | ||
resource.TestCheckResourceAttrSet(networksResData, "network_peers.#"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckIBMPINetworkPeersDataSourceConfigBasic() string { | ||
return fmt.Sprintf(` | ||
data "ibm_pi_network_peers" "network_peers" { | ||
pi_cloud_instance_id = "%s" | ||
}`, acc.Pi_cloud_instance_id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
subcategory: "Power Systems" | ||
layout: "ibm" | ||
page_title: "IBM : ibm_pi_network_peers" | ||
description: |- | ||
Get information about IBM Power Virtual Server cloud network peers. | ||
--- | ||
|
||
# ibm_pi_network_peers | ||
|
||
Provides a read-only data source to retrieve information about pi_network_peers for on-prem locations. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "ibm_pi_network_peers" "pi_network_peers" { | ||
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` | ||
|
||
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 pi_network_peers. | ||
- `network_peers` - (List) List of network peers. | ||
|
||
Nested schema for `network_peers`: | ||
- `description` - (String) Description of the network peer. | ||
- `id` - (String) ID of the network peer. | ||
- `name` - (String) Name of the network peer. | ||
- `type` - (String) Type of the network peer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters