Skip to content

Commit

Permalink
compute: added numeric_id to google_compute_network data source (#…
Browse files Browse the repository at this point in the history
…12339) (#20548)

[upstream:3640b752be9f7ffbbf13dd2b578994f4905fb1ec]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 2, 2024
1 parent 52ee3c6 commit f957c75
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/12339.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `numeric_id` to the `google_compute_network` data source
```
12 changes: 12 additions & 0 deletions google/services/compute/data_source_google_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package compute

import (
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
Expand All @@ -25,6 +26,14 @@ 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,
Computed: true,
},

"gateway_ipv4": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -85,6 +94,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("numeric_id", strconv.Itoa(int(network.Id))); err != nil {
return fmt.Errorf("Error setting numeric_id: %s", err)
}
if err := d.Set("subnetworks_self_links", network.Subnetworks); err != nil {
return fmt.Errorf("Error setting subnetworks_self_links: %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",
"numeric_id",
"description",
"internal_ipv6_range",
}
Expand Down
2 changes: 1 addition & 1 deletion google/services/compute/resource_compute_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestAccComputeNetwork_numericId(t *testing.T) {
{
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{1,}$")),
resource.TestMatchResourceAttr("google_compute_network.bar", "numeric_id", regexp.MustCompile("^\\d{16,48}$")),
resource.TestCheckResourceAttr("google_compute_network.bar", "id", networkId),
),
},
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/compute_network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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.

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

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

0 comments on commit f957c75

Please sign in to comment.