Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vpc doc fix #398

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.8.3
github.com/IBM-Cloud/power-go-client v1.9.0
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.8.3 h1:QsBuIS6KvKsiEpe0yiHYKhWgXlqkcJ7XqFHtATj8Yh4=
github.com/IBM-Cloud/power-go-client v1.8.3/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJlMje9Ry6XEY=
github.com/IBM-Cloud/power-go-client v1.9.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down
1 change: 1 addition & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ func Provider() *schema.Provider {
"ibm_pi_network_address_groups": power.DataSourceIBMPINetworkAddressGroups(),
"ibm_pi_network_interface": power.DataSourceIBMPINetworkInterface(),
"ibm_pi_network_interfaces": power.DataSourceIBMPINetworkInterfaces(),
"ibm_pi_network_peers": power.DataSourceIBMPINetworkPeers(),
"ibm_pi_network_port": power.DataSourceIBMPINetworkPort(),
"ibm_pi_network_security_group": power.DataSourceIBMPINetworkSecurityGroup(),
"ibm_pi_network_security_groups": power.DataSourceIBMPINetworkSecurityGroups(),
Expand Down
13 changes: 12 additions & 1 deletion ibm/service/power/data_source_ibm_pi_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func DataSourceIBMPIDatacenter() *schema.Resource {
ReadContext: dataSourceIBMPIDatacenterRead,
Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Optional: true,
Type: schema.TypeString,
},
Arg_DatacenterZone: {
Description: "Datacenter zone you want to retrieve.",
Optional: true,
Expand Down Expand Up @@ -180,7 +185,13 @@ func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData,
if region, ok := d.GetOk(Arg_DatacenterZone); ok {
datacenterZone = region.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, "")

cloudInstanceID := ""
if cloudInstance, ok := d.GetOk(Arg_CloudInstanceID); ok {
cloudInstanceID = cloudInstance.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, cloudInstanceID)

dcData, err := client.Get(datacenterZone)
if err != nil {
return diag.FromErr(err)
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package power_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand All @@ -25,9 +26,31 @@ func TestAccIBMPIDatacenterDataSourceBasic(t *testing.T) {
})
}

func TestAccIBMPIDatacenterDataSourcePrivate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIDatacenterDataSourcePrivateConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_datacenter.test", "id"),
),
},
},
})
}

func testAccCheckIBMPIDatacenterDataSourceConfig() string {
return `
data "ibm_pi_datacenter" "test" {
pi_datacenter_zone = "dal12"
}`
}

func testAccCheckIBMPIDatacenterDataSourcePrivateConfig() string {
return fmt.Sprintf(`
data "ibm_pi_datacenter" "test" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
13 changes: 12 additions & 1 deletion ibm/service/power/data_source_ibm_pi_datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func DataSourceIBMPIDatacenters() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMPIDatacentersRead,
Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Optional: true,
Type: schema.TypeString,
},

// Attributes
Attr_Datacenters: {
Type: schema.TypeList,
Expand Down Expand Up @@ -173,7 +180,11 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(err)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, "")
cloudInstanceID := ""
if cloudInstance, ok := d.GetOk(Arg_CloudInstanceID); ok {
cloudInstanceID = cloudInstance.(string)
}
client := instance.NewIBMPIDatacenterClient(ctx, sess, cloudInstanceID)
datacentersData, err := client.GetAll()
if err != nil {
return diag.FromErr(err)
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/power/data_source_ibm_pi_datacenters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package power_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand All @@ -25,6 +26,28 @@ func TestAccIBMPIDatacentersDataSourceBasic(t *testing.T) {
})
}

func TestAccIBMPIDatacentersDataSourcePrivate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIDatacentersDataSourcePrivateConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_datacenters.test", "id"),
),
},
},
})
}

func testAccCheckIBMPIDatacentersDataSourceConfig() string {
return `data "ibm_pi_datacenters" "test" {}`
}

func testAccCheckIBMPIDatacentersDataSourcePrivateConfig() string {
return fmt.Sprintf(`
data "ibm_pi_datacenters" "test" {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
29 changes: 28 additions & 1 deletion ibm/service/power/data_source_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func DataSourceIBMPINetwork() *schema.Resource {
// Attributes
Attr_AccessConfig: {
Computed: true,
Description: "The network communication configuration option of the network (for satellite locations only).",
Deprecated: "This field is deprecated please use peer_id instead.",
Description: "The network communication configuration option of the network (for on prem locations only). Use `peer_id` instead.",
Type: schema.TypeString,
},
Attr_AvailableIPCount: {
Expand Down Expand Up @@ -83,6 +84,25 @@ func DataSourceIBMPINetwork() *schema.Resource {
Description: "The unique identifier or name of a network.",
Type: schema.TypeString,
},
Attr_NetworkAddressTranslation: {
Computed: true,
Description: "Contains the network address translation details (for on prem locations only).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_SourceIP: {
Computed: true,
Description: "source IP address.",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
Attr_PeerID: {
Computed: true,
Description: "Network peer ID (for on prem locations only).",
Type: schema.TypeString,
},
Attr_Type: {
Computed: true,
Description: "The type of network.",
Expand Down Expand Up @@ -153,6 +173,13 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met
if networkdata.Name != nil {
d.Set(Attr_Name, networkdata.Name)
}
networkAddressTranslation := []map[string]interface{}{}
if networkdata.NetworkAddressTranslation != nil {
natMap := networkAddressTranslationToMap(networkdata.NetworkAddressTranslation)
networkAddressTranslation = append(networkAddressTranslation, natMap)
}
d.Set(Attr_NetworkAddressTranslation, networkAddressTranslation)
d.Set(Attr_PeerID, networkdata.PeerID)
if networkdata.Type != nil {
d.Set(Attr_Type, networkdata.Type)
}
Expand Down
109 changes: 109 additions & 0 deletions ibm/service/power/data_source_ibm_pi_network_peers.go
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 ibm/service/power/data_source_ibm_pi_network_peers_test.go
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)
}
9 changes: 8 additions & 1 deletion ibm/service/power/data_source_ibm_pi_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func DataSourceIBMPINetworks() *schema.Resource {
Schema: map[string]*schema.Schema{
Attr_AccessConfig: {
Computed: true,
Description: "The network communication configuration option of the network (for satellite locations only).",
Deprecated: "This field is deprecated please use peer_id instead.",
Description: "The network communication configuration option of the network (for on-prem locations only). Use `peer_id` instead.",
Type: schema.TypeString,
},
Attr_CRN: {
Expand Down Expand Up @@ -70,6 +71,11 @@ func DataSourceIBMPINetworks() *schema.Resource {
Description: "The unique identifier of a network.",
Type: schema.TypeString,
},
Attr_PeerID: {
Computed: true,
Description: "Network Peer ID.",
Type: schema.TypeString,
},
Attr_Type: {
Computed: true,
Description: "The type of network.",
Expand Down Expand Up @@ -126,6 +132,7 @@ func flattenNetworks(list []*models.NetworkReference, meta interface{}) []map[st
Attr_MTU: i.Mtu,
Attr_Name: *i.Name,
Attr_NetworkID: *i.NetworkID,
Attr_PeerID: i.PeerID,
Attr_Type: *i.Type,
Attr_VLanID: *i.VlanID,
}
Expand Down
Loading
Loading