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
- Loading branch information
1 parent
d841442
commit cb5111e
Showing
14 changed files
with
436 additions
and
26 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
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
Oops, something went wrong.