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 Network Peer Network Peers Add [D]: pi_network_peers Update [D]: pi_network, pi_networks Update [R]: pi_network Add require option Add vsn functionality Add comment to docs test fixes Add stop to update Update ibm/service/power/resource_ibm_pi_virtual_serial_number_test.go Co-authored-by: michaelkad <45772690+michaelkad@users.noreply.github.com> Code cleanup fixes from testing doc fixes doc fixes, delete fixes on instance
- Loading branch information
1 parent
03caa9e
commit f5b17b2
Showing
31 changed files
with
1,660 additions
and
28 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
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
Oops, something went wrong.