Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute: added network_id to google_compute_network #8915

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
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
Loading