diff --git a/.changelog/12504.txt b/.changelog/12504.txt new file mode 100644 index 0000000000..bbceaab087 --- /dev/null +++ b/.changelog/12504.txt @@ -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 +``` \ No newline at end of file diff --git a/google-beta/services/compute/data_source_google_compute_network.go b/google-beta/services/compute/data_source_google_compute_network.go index 5b37446b76..d9936d0a55 100644 --- a/google-beta/services/compute/data_source_google_compute_network.go +++ b/google-beta/services/compute/data_source_google_compute_network.go @@ -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, @@ -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) } diff --git a/google-beta/services/compute/data_source_google_compute_network_test.go b/google-beta/services/compute/data_source_google_compute_network_test.go index cde6223ac8..4ba7005164 100644 --- a/google-beta/services/compute/data_source_google_compute_network_test.go +++ b/google-beta/services/compute/data_source_google_compute_network_test.go @@ -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", diff --git a/google-beta/services/compute/resource_compute_network.go b/google-beta/services/compute/resource_compute_network.go index 6fbb237c96..bd8c747d90 100644 --- a/google-beta/services/compute/resource_compute_network.go +++ b/google-beta/services/compute/resource_compute_network.go @@ -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": { @@ -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) } @@ -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 } diff --git a/google-beta/services/compute/resource_compute_network_test.go b/google-beta/services/compute/resource_compute_network_test.go index 307de6dbcb..7e16ef7958 100644 --- a/google-beta/services/compute/resource_compute_network_test.go +++ b/google-beta/services/compute/resource_compute_network_test.go @@ -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), ), diff --git a/website/docs/d/compute_network.html.markdown b/website/docs/d/compute_network.html.markdown index dfe8b1f4cb..52de13d65f 100644 --- a/website/docs/d/compute_network.html.markdown +++ b/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. `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. diff --git a/website/docs/r/compute_network.html.markdown b/website/docs/r/compute_network.html.markdown index 95927b052d..def0019ee9 100644 --- a/website/docs/r/compute_network.html.markdown +++ b/website/docs/r/compute_network.html.markdown @@ -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.