diff --git a/.changelog/12537.txt b/.changelog/12537.txt new file mode 100644 index 0000000000..305210ef94 --- /dev/null +++ b/.changelog/12537.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +networkconnectivity: added `group` field to `google_network_connectivity_spoke` resource +``` \ No newline at end of file diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go index 40586c6e49..84141f767c 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go @@ -80,6 +80,13 @@ func ResourceNetworkConnectivitySpoke() *schema.Resource { Optional: true, Description: `An optional description of the spoke.`, }, + "group": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + Description: `The name of the group that this spoke is associated with.`, + }, "labels": { Type: schema.TypeMap, Optional: true, @@ -364,6 +371,12 @@ func resourceNetworkConnectivitySpokeCreate(d *schema.ResourceData, meta interfa } else if v, ok := d.GetOkExists("hub"); !tpgresource.IsEmptyValue(reflect.ValueOf(hubProp)) && (ok || !reflect.DeepEqual(v, hubProp)) { obj["hub"] = hubProp } + groupProp, err := expandNetworkConnectivitySpokeGroup(d.Get("group"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("group"); !tpgresource.IsEmptyValue(reflect.ValueOf(groupProp)) && (ok || !reflect.DeepEqual(v, groupProp)) { + obj["group"] = groupProp + } linkedVpnTunnelsProp, err := expandNetworkConnectivitySpokeLinkedVpnTunnels(d.Get("linked_vpn_tunnels"), d, config) if err != nil { return err @@ -517,6 +530,9 @@ func resourceNetworkConnectivitySpokeRead(d *schema.ResourceData, meta interface if err := d.Set("hub", flattenNetworkConnectivitySpokeHub(res["hub"], d, config)); err != nil { return fmt.Errorf("Error reading Spoke: %s", err) } + if err := d.Set("group", flattenNetworkConnectivitySpokeGroup(res["group"], d, config)); err != nil { + return fmt.Errorf("Error reading Spoke: %s", err) + } if err := d.Set("linked_vpn_tunnels", flattenNetworkConnectivitySpokeLinkedVpnTunnels(res["linkedVpnTunnels"], d, config)); err != nil { return fmt.Errorf("Error reading Spoke: %s", err) } @@ -781,6 +797,10 @@ func flattenNetworkConnectivitySpokeHub(v interface{}, d *schema.ResourceData, c return tpgresource.ConvertSelfLinkToV1(v.(string)) } +func flattenNetworkConnectivitySpokeGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenNetworkConnectivitySpokeLinkedVpnTunnels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return nil @@ -1000,6 +1020,10 @@ func expandNetworkConnectivitySpokeHub(v interface{}, d tpgresource.TerraformRes return v, nil } +func expandNetworkConnectivitySpokeGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandNetworkConnectivitySpokeLinkedVpnTunnels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_test.go b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_test.go index 37b142a2f2..c3e101ded3 100644 --- a/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_test.go +++ b/google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_test.go @@ -93,6 +93,76 @@ resource "google_network_connectivity_spoke" "primary" { `, context) } +func TestAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckNetworkConnectivitySpokeDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(context), + }, + { + ResourceName: "google_network_connectivity_spoke.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"hub", "labels", "location", "terraform_labels"}, + }, + }, + }) +} + +func testAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_network" "network" { + name = "tf-test-net-spoke%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_network_connectivity_hub" "basic_hub" { + name = "tf-test-hub1-spoke%{random_suffix}" + description = "A sample hub" + labels = { + label-two = "value-one" + } +} + +resource "google_network_connectivity_group" "default_group" { + hub = google_network_connectivity_hub.basic_hub.id + name = "default" + description = "A sample hub group" +} + +resource "google_network_connectivity_spoke" "primary" { + name = "tf-test-group-spoke1%{random_suffix}" + location = "global" + description = "A sample spoke with a linked VPC" + labels = { + label-one = "value-one" + } + hub = google_network_connectivity_hub.basic_hub.id + linked_vpc_network { + exclude_export_ranges = [ + "198.51.100.0/24", + "10.10.0.0/16" + ] + include_export_ranges = [ + "198.51.100.0/23", + "10.0.0.0/8" + ] + uri = google_compute_network.network.self_link + } + group = google_network_connectivity_group.default_group.id +} +`, context) +} + func TestAccNetworkConnectivitySpoke_networkConnectivitySpokeRouterApplianceBasicExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/network_connectivity_spoke.html.markdown b/website/docs/r/network_connectivity_spoke.html.markdown index 9265ce115c..4c63ed8c60 100644 --- a/website/docs/r/network_connectivity_spoke.html.markdown +++ b/website/docs/r/network_connectivity_spoke.html.markdown @@ -71,6 +71,56 @@ resource "google_network_connectivity_spoke" "primary" { } } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Network Connectivity Spoke Linked Vpc Network Group + + +```hcl +resource "google_compute_network" "network" { + name = "net-spoke" + auto_create_subnetworks = false +} + +resource "google_network_connectivity_hub" "basic_hub" { + name = "hub1-spoke" + description = "A sample hub" + labels = { + label-two = "value-one" + } +} + +resource "google_network_connectivity_group" "default_group" { + hub = google_network_connectivity_hub.basic_hub.id + name = "default" + description = "A sample hub group" +} + +resource "google_network_connectivity_spoke" "primary" { + name = "group-spoke1" + location = "global" + description = "A sample spoke with a linked VPC" + labels = { + label-one = "value-one" + } + hub = google_network_connectivity_hub.basic_hub.id + linked_vpc_network { + exclude_export_ranges = [ + "198.51.100.0/24", + "10.10.0.0/16" + ] + include_export_ranges = [ + "198.51.100.0/23", + "10.0.0.0/8" + ] + uri = google_compute_network.network.self_link + } + group = google_network_connectivity_group.default_group.id +} +```
Open in Cloud Shell @@ -427,6 +477,10 @@ The following arguments are supported: (Optional) An optional description of the spoke. +* `group` - + (Optional) + The name of the group that this spoke is associated with. + * `linked_vpn_tunnels` - (Optional) The URIs of linked VPN tunnel resources