From 07b15655a014d513977d88b12e4c02cc86260faa Mon Sep 17 00:00:00 2001 From: William Yardley Date: Thu, 5 Dec 2024 13:25:41 -0800 Subject: [PATCH] compute: add `network_id` to `google_compute_network` 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 --- mmv1/products/compute/Network.yaml | 8 +++++++- .../data_source_google_compute_network.go.tmpl | 12 +++++++++--- .../data_source_google_compute_network_test.go | 1 + .../compute/resource_compute_network_test.go.tmpl | 1 + .../website/docs/d/compute_network.html.markdown | 4 +++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mmv1/products/compute/Network.yaml b/mmv1/products/compute/Network.yaml index 4a722c4b3193..e4a4e79f1f58 100644 --- a/mmv1/products/compute/Network.yaml +++ b/mmv1/products/compute/Network.yaml @@ -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 diff --git a/mmv1/third_party/terraform/services/compute/data_source_google_compute_network.go.tmpl b/mmv1/third_party/terraform/services/compute/data_source_google_compute_network.go.tmpl index da19428452ad..36daf7fe781f 100644 --- a/mmv1/third_party/terraform/services/compute/data_source_google_compute_network.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/data_source_google_compute_network.go.tmpl @@ -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, @@ -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", strconv.Itoa(int(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) } diff --git a/mmv1/third_party/terraform/services/compute/data_source_google_compute_network_test.go b/mmv1/third_party/terraform/services/compute/data_source_google_compute_network_test.go index d54970e576a7..71e6d4f0caa5 100644 --- a/mmv1/third_party/terraform/services/compute/data_source_google_compute_network_test.go +++ b/mmv1/third_party/terraform/services/compute/data_source_google_compute_network_test.go @@ -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", diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_network_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_network_test.go.tmpl index 8939a15df920..b4dbdff2906f 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_network_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_network_test.go.tmpl @@ -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), ), diff --git a/mmv1/third_party/terraform/website/docs/d/compute_network.html.markdown b/mmv1/third_party/terraform/website/docs/d/compute_network.html.markdown index dfe8b1f4cb35..8288b7fd042e 100644 --- a/mmv1/third_party/terraform/website/docs/d/compute_network.html.markdown +++ b/mmv1/third_party/terraform/website/docs/d/compute_network.html.markdown @@ -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.