Skip to content

Commit ecaaa72

Browse files
committed
Add NetworkID
1 parent 9c48db3 commit ecaaa72

File tree

6 files changed

+56
-22
lines changed

6 files changed

+56
-22
lines changed

ibm/service/power/data_source_ibm_pi_network.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/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
@@ -140,9 +150,15 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met
140150
}
141151

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

144160
networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID)
145-
networkdata, err := networkC.Get(d.Get(helpers.PINetworkName).(string))
161+
networkdata, err := networkC.Get(networkID)
146162
if err != nil || networkdata == nil {
147163
return diag.FromErr(err)
148164
}

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: 3 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 name of the network. Please use `pi_network_id` instead.
4445

4546
## Attribute Reference
4647

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)