Skip to content

Commit bf62f56

Browse files
committed
Add NetworkID
Add network name Update doc sync master
1 parent 1f2bcf1 commit bf62f56

File tree

7 files changed

+58
-26
lines changed

7 files changed

+58
-26
lines changed

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3bt
125125
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
126126
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
127127
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
128-
github.com/IBM/go-sdk-core/v5 v5.20.1 h1:dzeyifh1kfRLw8VfAIIS5okZYuqLTqplPZP/Kcsgdlo=
129-
github.com/IBM/go-sdk-core/v5 v5.20.1/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw=
130128
github.com/IBM/go-sdk-core/v5 v5.21.0 h1:DUnYhvC4SoC8T84rx5omnhY3+xcQg/Whyoa3mDPIMkk=
131129
github.com/IBM/go-sdk-core/v5 v5.21.0/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw=
132130
github.com/IBM/ibm-backup-recovery-sdk-go v1.0.3 h1:9TZHocmCfgmF8TGVrpP1kFyQbjcqLNW7+bM07lefpKQ=

ibm/service/power/data_source_ibm_pi_network.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"log"
99

1010
"github.com/IBM-Cloud/power-go-client/clients/instance"
11-
"github.com/IBM-Cloud/power-go-client/helpers"
1211
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
1312
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
1413
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -27,11 +26,22 @@ func DataSourceIBMPINetwork() *schema.Resource {
2726
Type: schema.TypeString,
2827
ValidateFunc: validation.NoZeroValues,
2928
},
29+
Arg_NetworkID: {
30+
AtLeastOneOf: []string{Arg_NetworkID, Arg_NetworkName},
31+
ConflictsWith: []string{Arg_NetworkName},
32+
Description: "The network ID.",
33+
Optional: true,
34+
Type: schema.TypeString,
35+
ValidateFunc: validation.NoZeroValues,
36+
},
3037
Arg_NetworkName: {
31-
Description: "The unique identifier or name of a network.",
32-
Required: true,
33-
Type: schema.TypeString,
34-
ValidateFunc: validation.NoZeroValues,
38+
AtLeastOneOf: []string{Arg_NetworkID, Arg_NetworkName},
39+
ConflictsWith: []string{Arg_NetworkID},
40+
Deprecated: "The pi_network_name field is deprecated. Please use pi_network_id instead",
41+
Description: "The unique identifier or name of a network.",
42+
Optional: true,
43+
Type: schema.TypeString,
44+
ValidateFunc: validation.NoZeroValues,
3545
},
3646

3747
// Attributes
@@ -78,8 +88,7 @@ func DataSourceIBMPINetwork() *schema.Resource {
7888
},
7989
Attr_Name: {
8090
Computed: true,
81-
Deprecated: "This field is deprecated, use pi_network_name instead.",
82-
Description: "The unique identifier or name of a network.",
91+
Description: "The name of the network.",
8392
Type: schema.TypeString,
8493
},
8594
Attr_NetworkAddressTranslation: {
@@ -140,9 +149,15 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met
140149
}
141150

142151
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
152+
var networkID string
153+
if v, ok := d.GetOk(Arg_NetworkID); ok {
154+
networkID = v.(string)
155+
} else if v, ok := d.GetOk(Arg_NetworkName); ok {
156+
networkID = v.(string)
157+
}
143158

144159
networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID)
145-
networkdata, err := networkC.Get(d.Get(helpers.PINetworkName).(string))
160+
networkdata, err := networkC.Get(networkID)
146161
if err != nil || networkdata == nil {
147162
return diag.FromErr(err)
148163
}

ibm/service/power/data_source_ibm_pi_network_port.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"log"
99

1010
"github.com/IBM-Cloud/power-go-client/clients/instance"
11-
"github.com/IBM-Cloud/power-go-client/helpers"
1211
"github.com/IBM-Cloud/power-go-client/power/models"
1312
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
1413
"github.com/hashicorp/go-uuid"
@@ -28,11 +27,22 @@ func DataSourceIBMPINetworkPort() *schema.Resource {
2827
Type: schema.TypeString,
2928
ValidateFunc: validation.NoZeroValues,
3029
},
30+
Arg_NetworkID: {
31+
AtLeastOneOf: []string{Arg_NetworkID, Arg_NetworkName},
32+
ConflictsWith: []string{Arg_NetworkName},
33+
Description: "The network ID.",
34+
Optional: true,
35+
Type: schema.TypeString,
36+
ValidateFunc: validation.NoZeroValues,
37+
},
3138
Arg_NetworkName: {
32-
Description: "The unique identifier or name of a network.",
33-
Required: true,
34-
Type: schema.TypeString,
35-
ValidateFunc: validation.NoZeroValues,
39+
AtLeastOneOf: []string{Arg_NetworkID, Arg_NetworkName},
40+
ConflictsWith: []string{Arg_NetworkID},
41+
Deprecated: "The pi_network_name field is deprecated. Please use pi_network_id instead",
42+
Description: "The unique identifier or name of a network.",
43+
Optional: true,
44+
Type: schema.TypeString,
45+
ValidateFunc: validation.NoZeroValues,
3646
},
3747

3848
// Attributes
@@ -97,9 +107,15 @@ func dataSourceIBMPINetworkPortsRead(ctx context.Context, d *schema.ResourceData
97107
}
98108

99109
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
110+
var networkID string
111+
if v, ok := d.GetOk(Arg_NetworkID); ok {
112+
networkID = v.(string)
113+
} else if v, ok := d.GetOk(Arg_NetworkName); ok {
114+
networkID = v.(string)
115+
}
100116

101117
networkportC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID)
102-
networkportdata, err := networkportC.GetAllPorts(d.Get(helpers.PINetworkName).(string))
118+
networkportdata, err := networkportC.GetAllPorts(networkID)
103119
if err != nil {
104120
return diag.FromErr(err)
105121
}

ibm/service/power/data_source_ibm_pi_network_port_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAccIBMPINetworkPortDataSource_basic(t *testing.T) {
3030
func testAccCheckIBMPINetworkPortDataSourceConfig() string {
3131
return fmt.Sprintf(`
3232
data "ibm_pi_network_port" "testacc_ds_network_port" {
33-
pi_network_name = "%s"
34-
pi_cloud_instance_id = "%s"
35-
}`, acc.Pi_network_name, acc.Pi_cloud_instance_id)
33+
pi_cloud_instance_id = "%[2]s"
34+
pi_network_id = "%[1]s"
35+
}`, acc.Pi_network_id, acc.Pi_cloud_instance_id)
3636
}

ibm/service/power/data_source_ibm_pi_network_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAccIBMPINetworkDataSource_basic(t *testing.T) {
3131
func testAccCheckIBMPINetworkDataSourceConfig() string {
3232
return fmt.Sprintf(`
3333
data "ibm_pi_network" "testacc_ds_network" {
34-
pi_network_name = "%s"
35-
pi_cloud_instance_id = "%s"
36-
}`, acc.Pi_network_name, acc.Pi_cloud_instance_id)
34+
pi_cloud_instance_id = "%[2]s"
35+
pi_network_id = "%[1]s"
36+
}`, acc.Pi_network_id, acc.Pi_cloud_instance_id)
3737
}

website/docs/d/pi_network.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Retrieve information about the network that your Power Systems Virtual Server in
1414

1515
```terraform
1616
data "ibm_pi_network" "ds_network" {
17-
pi_network_name = "APP"
1817
pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b"
18+
pi_network_id = "7f8e2a9d-3b4c-4e4f-8e8d-f7e7e1e23456"
1919
}
2020
```
2121

@@ -40,7 +40,8 @@ Example usage:
4040
Review the argument references that you can specify for your data source.
4141

4242
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
43-
- `pi_network_name` - (Required, String) The name of the network.
43+
- `pi_network_id` - (Optional, String) The network ID.
44+
- `pi_network_name` - (Deprecated, Optional, String) The unique identifier or name of the network. Passing the name of the instance could fail or fetch stale data. Please pass an id and use `pi_network_id` instead.
4445

4546
## Attribute Reference
4647

@@ -54,6 +55,7 @@ In addition to all argument reference list, you can access the following attribu
5455
- `dns`- (Set) The DNS Servers for the network.
5556
- `gateway` - (String) The network gateway that is attached to your network.
5657
- `id` - (String) The ID of the network.
58+
- `name` - (String) The name of the network.
5759
- `mtu` - (Boolean) Maximum Transmission Unit option of the network.
5860
- `network_address_translation` - (Deprecated, List) Contains the network address translation details (for on-prem locations only).
5961

website/docs/d/pi_network_port.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Retrieve information about a network port in the Power Virtual Server Cloud. For
1616

1717
```terraform
1818
data "ibm_pi_network_port" "test-network-port" {
19-
pi_network_name = "Zone1-CFN"
2019
pi_cloud_instance_id = "51e1879c-bcbe-4ee1-a008-49cdba0eaf60"
20+
pi_network_id = "7e1c3b2a-9f0d-4e5f-a1bc-def012345678"
2121
}
2222
```
2323

@@ -42,7 +42,8 @@ Example usage:
4242
Review the argument references that you can specify for your data source.
4343

4444
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
45-
- `pi_network_name` - (Required, String) The unique identifier or name of a network.
45+
- `pi_network_id` - (Optional, String) The network ID.
46+
- `pi_network_name` - (Deprecated, Optional, String) The unique identifier or name of a network. Please use `pi_network_id` instead.
4647

4748
## Attribute Reference
4849

0 commit comments

Comments
 (0)