Skip to content

Commit

Permalink
compute: added network_id to google_compute_network (#12504) (#8915)
Browse files Browse the repository at this point in the history
[upstream:219edef6198ad089672bcea662015ea5a3e3594a]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 16, 2024
1 parent 0ff2db3 commit b3a1598
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changelog/12504.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
compute: added `network_id` (integer) to `google_compute_network` resource and data source
```
```release-note: deprecation
compute: deprecated `numeric_id` (string) field in `google_compute_network` resource. Use the new `network_id` (integer) field instead
```
17 changes: 12 additions & 5 deletions google-beta/services/compute/data_source_google_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ func DataSourceGoogleComputeNetwork() *schema.Resource {
Computed: true,
},

// TODO: this should eventually be TypeInt, but leaving as
// string for now to match the resource and to avoid a
// breaking change.
"numeric_id": {
Type: schema.TypeString,
"network_id": {
Type: schema.TypeInt,
Computed: true,
},

// Deprecated in favor of network_id
"numeric_id": {
Type: schema.TypeString,
Computed: true,
Deprecated: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.",
},

"gateway_ipv4": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -101,6 +105,9 @@ func dataSourceGoogleComputeNetworkRead(d *schema.ResourceData, meta interface{}
if err := d.Set("description", network.Description); err != nil {
return fmt.Errorf("Error setting description: %s", err)
}
if err := d.Set("network_id", network.Id); err != nil {
return fmt.Errorf("Error setting network_id: %s", err)
}
if err := d.Set("numeric_id", strconv.Itoa(int(network.Id))); err != nil {
return fmt.Errorf("Error setting numeric_id: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func testAccDataSourceGoogleNetworkCheck(data_source_name string, resource_name
network_attrs_to_test := []string{
"id",
"name",
"network_id",
"numeric_id",
"description",
"internal_ipv6_range",
Expand Down
13 changes: 13 additions & 0 deletions google-beta/services/compute/resource_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ subnetworks of this network, across regions. Possible values: ["REGIONAL", "GLOB
Description: `The gateway address for default routing out of the network. This value
is selected by GCP.`,
},
"network_id": {
Type: schema.TypeString,
Computed: true,
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
},
"numeric_id": {
Type: schema.TypeString,
Computed: true,
Deprecated: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.",
Description: `The unique identifier for the resource. This identifier is defined by the server.`,
},
"delete_default_routes_on_create": {
Expand Down Expand Up @@ -425,6 +431,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("name", flattenComputeNetworkName(res["name"], d, config)); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
if err := d.Set("network_id", flattenComputeNetworkNetworkId(res["id"], d, config)); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
if err := d.Set("numeric_id", flattenComputeNetworkNumericId(res["numericId"], d, config)); err != nil {
return fmt.Errorf("Error reading Network: %s", err)
}
Expand Down Expand Up @@ -640,6 +649,10 @@ func flattenComputeNetworkName(v interface{}, d *schema.ResourceData, config *tr
return v
}

func flattenComputeNetworkNetworkId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeNetworkNumericId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
{
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("google_compute_network.bar", "network_id", regexp.MustCompile("^\\d{16,48}$")),
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{16,48}$")),
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
),
Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/compute_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ In addition to the arguments listed above, the following attributes are exported

* `description` - Description of this network.

* `numeric_id` - The numeric unique identifier for the resource.
* `network_id` - The numeric unique identifier for the resource.

* `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.

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

Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/compute_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ In addition to the arguments listed above, the following computed attributes are
The gateway address for default routing out of the network. This value
is selected by GCP.

* `network_id` -
The unique identifier for the resource. This identifier is defined by the server.

* `numeric_id` -
(Deprecated)
The unique identifier for the resource. This identifier is defined by the server.

~> **Warning:** `numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.
* `self_link` - The URI of the created resource.


Expand Down

0 comments on commit b3a1598

Please sign in to comment.