Skip to content

Commit b3a1598

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

7 files changed

+42
-6
lines changed

.changelog/12504.txt

+6
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-beta/services/compute/data_source_google_compute_network.go

+12-5
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,
@@ -101,6 +105,9 @@ func dataSourceGoogleComputeNetworkRead(d *schema.ResourceData, meta interface{}
101105
if err := d.Set("description", network.Description); err != nil {
102106
return fmt.Errorf("Error setting description: %s", err)
103107
}
108+
if err := d.Set("network_id", network.Id); err != nil {
109+
return fmt.Errorf("Error setting network_id: %s", err)
110+
}
104111
if err := d.Set("numeric_id", strconv.Itoa(int(network.Id))); err != nil {
105112
return fmt.Errorf("Error setting numeric_id: %s", err)
106113
}

google-beta/services/compute/data_source_google_compute_network_test.go

+1
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-beta/services/compute/resource_compute_network.go

+13
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,15 @@ subnetworks of this network, across regions. Possible values: ["REGIONAL", "GLOB
173173
Description: `The gateway address for default routing out of the network. This value
174174
is selected by GCP.`,
175175
},
176+
"network_id": {
177+
Type: schema.TypeString,
178+
Computed: true,
179+
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
180+
},
176181
"numeric_id": {
177182
Type: schema.TypeString,
178183
Computed: true,
184+
Deprecated: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.",
179185
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
180186
},
181187
"delete_default_routes_on_create": {
@@ -425,6 +431,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
425431
if err := d.Set("name", flattenComputeNetworkName(res["name"], d, config)); err != nil {
426432
return fmt.Errorf("Error reading Network: %s", err)
427433
}
434+
if err := d.Set("network_id", flattenComputeNetworkNetworkId(res["id"], d, config)); err != nil {
435+
return fmt.Errorf("Error reading Network: %s", err)
436+
}
428437
if err := d.Set("numeric_id", flattenComputeNetworkNumericId(res["numericId"], d, config)); err != nil {
429438
return fmt.Errorf("Error reading Network: %s", err)
430439
}
@@ -640,6 +649,10 @@ func flattenComputeNetworkName(v interface{}, d *schema.ResourceData, config *tr
640649
return v
641650
}
642651

652+
func flattenComputeNetworkNetworkId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
653+
return v
654+
}
655+
643656
func flattenComputeNetworkNumericId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
644657
return v
645658
}

google-beta/services/compute/resource_compute_network_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
256256
{
257257
Config: testAccComputeNetwork_basic(networkName),
258258
Check: resource.ComposeTestCheckFunc(
259+
resource.TestMatchResourceAttr("google_compute_network.bar", "network_id", regexp.MustCompile("^\\d{16,48}$")),
259260
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{16,48}$")),
260261
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
261262
),

website/docs/d/compute_network.html.markdown

+3-1
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

+6
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)