Skip to content

Commit

Permalink
Add group field to google_network_connectivity_spoke (#12537) (#8909
Browse files Browse the repository at this point in the history
)

[upstream:9e83dc2be24eda2f1e3beb89b0153b06a49bea05]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 13, 2024
1 parent c97f56f commit b3aa81d
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12537.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
networkconnectivity: added `group` field to `google_network_connectivity_spoke` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
54 changes: 54 additions & 0 deletions website/docs/r/network_connectivity_spoke.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,56 @@ resource "google_network_connectivity_spoke" "primary" {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=network_connectivity_spoke_linked_vpc_network_group&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=network_connectivity_spoke_router_appliance_basic&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b3aa81d

Please sign in to comment.