Skip to content

Commit

Permalink
compute: add network_id to google_compute_network
Browse files Browse the repository at this point in the history
Add `network_id` to `google_compute_network`. It's an integer, not a
string, and follows the expected convention for naming.

This adds a note deprecating `numeric_id` (to be potentially removed at
some later date), which will have the same value, but as a string.

Part of terraform-provider-google#20530
  • Loading branch information
wyardley committed Dec 5, 2024
1 parent 94d5485 commit 961479b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion mmv1/products/compute/Network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ properties:
immutable: true
validation:
function: 'verify.ValidateGCEName'
- name: 'networkId'
description: |
The unique identifier for the resource. This identifier is defined by the server.
api_name: id
output: true
- name: 'numericId'
type: String
description: |
The unique identifier for the resource. This identifier is defined by the server.
(Deprecated) The unique identifier for the resource. This identifier is defined by the server.
Use `network_id` instead.
output: true
- name: 'autoCreateSubnetworks'
type: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ 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.
"network_id": {
Type: schema.TypeInt,
Computed: true,
},

// Deprecated in favor of network_id
"numeric_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -104,6 +107,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 @@ -45,6 +45,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
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,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
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. Use `network_id` instead.

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

Expand Down

0 comments on commit 961479b

Please sign in to comment.