Skip to content

Commit a4bdf40

Browse files
compute: added network_id to google_compute_network (#12504) (#20698)
[upstream:219edef6198ad089672bcea662015ea5a3e3594a] Signed-off-by: Modular Magician <[email protected]>
1 parent da264d3 commit a4bdf40

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

.changelog/12504.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added `network_id` (integer) to `google_compute_network` resource and data source
3+
```
4+
```release-note: deprecation
5+
compute: deprecated `numeric_id` (string) field in `google_compute_network` resource. Use the new `network_id` (integer) field instead
6+
```

google/services/compute/data_source_google_compute_network.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ func DataSourceGoogleComputeNetwork() *schema.Resource {
2626
Computed: true,
2727
},
2828

29-
// TODO: this should eventually be TypeInt, but leaving as
30-
// string for now to match the resource and to avoid a
31-
// breaking change.
32-
"numeric_id": {
33-
Type: schema.TypeString,
29+
"network_id": {
30+
Type: schema.TypeInt,
3431
Computed: true,
3532
},
3633

34+
// Deprecated in favor of network_id
35+
"numeric_id": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
Deprecated: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.",
39+
},
40+
3741
"gateway_ipv4": {
3842
Type: schema.TypeString,
3943
Computed: true,
@@ -94,6 +98,9 @@ func dataSourceGoogleComputeNetworkRead(d *schema.ResourceData, meta interface{}
9498
if err := d.Set("description", network.Description); err != nil {
9599
return fmt.Errorf("Error setting description: %s", err)
96100
}
101+
if err := d.Set("network_id", network.Id); err != nil {
102+
return fmt.Errorf("Error setting network_id: %s", err)
103+
}
97104
if err := d.Set("numeric_id", strconv.Itoa(int(network.Id))); err != nil {
98105
return fmt.Errorf("Error setting numeric_id: %s", err)
99106
}

google/services/compute/data_source_google_compute_network_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func testAccDataSourceGoogleNetworkCheck(data_source_name string, resource_name
4747
network_attrs_to_test := []string{
4848
"id",
4949
"name",
50+
"network_id",
5051
"numeric_id",
5152
"description",
5253
"internal_ipv6_range",

google/services/compute/resource_compute_network.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,15 @@ subnetworks of this network, across regions. Possible values: ["REGIONAL", "GLOB
142142
Description: `The gateway address for default routing out of the network. This value
143143
is selected by GCP.`,
144144
},
145+
"network_id": {
146+
Type: schema.TypeString,
147+
Computed: true,
148+
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
149+
},
145150
"numeric_id": {
146151
Type: schema.TypeString,
147152
Computed: true,
153+
Deprecated: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.",
148154
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
149155
},
150156
"delete_default_routes_on_create": {
@@ -388,6 +394,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
388394
if err := d.Set("name", flattenComputeNetworkName(res["name"], d, config)); err != nil {
389395
return fmt.Errorf("Error reading Network: %s", err)
390396
}
397+
if err := d.Set("network_id", flattenComputeNetworkNetworkId(res["id"], d, config)); err != nil {
398+
return fmt.Errorf("Error reading Network: %s", err)
399+
}
391400
if err := d.Set("numeric_id", flattenComputeNetworkNumericId(res["numericId"], d, config)); err != nil {
392401
return fmt.Errorf("Error reading Network: %s", err)
393402
}
@@ -600,6 +609,10 @@ func flattenComputeNetworkName(v interface{}, d *schema.ResourceData, config *tr
600609
return v
601610
}
602611

612+
func flattenComputeNetworkNetworkId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
613+
return v
614+
}
615+
603616
func flattenComputeNetworkNumericId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
604617
return v
605618
}

google/services/compute/resource_compute_network_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
125125
{
126126
Config: testAccComputeNetwork_basic(networkName),
127127
Check: resource.ComposeTestCheckFunc(
128+
resource.TestMatchResourceAttr("google_compute_network.bar", "network_id", regexp.MustCompile("^\\d{16,48}$")),
128129
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{16,48}$")),
129130
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
130131
),

website/docs/d/compute_network.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ In addition to the arguments listed above, the following attributes are exported
3636

3737
* `description` - Description of this network.
3838

39-
* `numeric_id` - The numeric unique identifier for the resource.
39+
* `network_id` - The numeric unique identifier for the resource.
40+
41+
* `numeric_id` - (Deprecated) The numeric unique identifier for the resource. `numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.
4042

4143
* `gateway_ipv4` - The IP address of the gateway.
4244

website/docs/r/compute_network.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,14 @@ In addition to the arguments listed above, the following computed attributes are
209209
The gateway address for default routing out of the network. This value
210210
is selected by GCP.
211211

212+
* `network_id` -
213+
The unique identifier for the resource. This identifier is defined by the server.
214+
212215
* `numeric_id` -
216+
(Deprecated)
213217
The unique identifier for the resource. This identifier is defined by the server.
218+
219+
~> **Warning:** `numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.
214220
* `self_link` - The URI of the created resource.
215221

216222

0 commit comments

Comments
 (0)