Skip to content

Commit 7be2072

Browse files
compute: added numeric_id to google_compute_network data source (#12339) (#8821)
[upstream:3640b752be9f7ffbbf13dd2b578994f4905fb1ec] Signed-off-by: Modular Magician <[email protected]>
1 parent 575c722 commit 7be2072

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

.changelog/12339.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `numeric_id` to the `google_compute_network` data source
3+
```

google-beta/services/compute/data_source_google_compute_network.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package compute
44

55
import (
66
"fmt"
7+
"strconv"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
@@ -25,6 +26,14 @@ func DataSourceGoogleComputeNetwork() *schema.Resource {
2526
Computed: true,
2627
},
2728

29+
// TODO: this should eventually be TypeInt, but leaving as
30+
// string for now to match the resource and to avoid a
31+
// breaking change.
32+
"numeric_id": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
},
36+
2837
"gateway_ipv4": {
2938
Type: schema.TypeString,
3039
Computed: true,
@@ -92,6 +101,9 @@ func dataSourceGoogleComputeNetworkRead(d *schema.ResourceData, meta interface{}
92101
if err := d.Set("description", network.Description); err != nil {
93102
return fmt.Errorf("Error setting description: %s", err)
94103
}
104+
if err := d.Set("numeric_id", strconv.Itoa(int(network.Id))); err != nil {
105+
return fmt.Errorf("Error setting numeric_id: %s", err)
106+
}
95107
if err := d.Set("subnetworks_self_links", network.Subnetworks); err != nil {
96108
return fmt.Errorf("Error setting subnetworks_self_links: %s", err)
97109
}

google-beta/services/compute/data_source_google_compute_network_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func testAccDataSourceGoogleNetworkCheck(data_source_name string, resource_name
4747
network_attrs_to_test := []string{
4848
"id",
4949
"name",
50+
"numeric_id",
5051
"description",
5152
"internal_ipv6_range",
5253
}

google-beta/services/compute/resource_compute_network_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
256256
{
257257
Config: testAccComputeNetwork_basic(networkName),
258258
Check: resource.ComposeTestCheckFunc(
259-
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{1,}$")),
259+
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{16,48}$")),
260260
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
261261
),
262262
},

website/docs/d/compute_network.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ In addition to the arguments listed above, the following attributes are exported
3636

3737
* `description` - Description of this network.
3838

39+
* `numeric_id` - The numeric unique identifier for the resource.
40+
3941
* `gateway_ipv4` - The IP address of the gateway.
4042

4143
* `internal_ipv6_range` - The ula internal ipv6 range assigned to this network.

0 commit comments

Comments
 (0)