Skip to content

Commit b3aa81d

Browse files
Add group field to google_network_connectivity_spoke (#12537) (#8909)
[upstream:9e83dc2be24eda2f1e3beb89b0153b06a49bea05] Signed-off-by: Modular Magician <[email protected]>
1 parent c97f56f commit b3aa81d

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed

Diff for: .changelog/12537.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networkconnectivity: added `group` field to `google_network_connectivity_spoke` resource
3+
```

Diff for: google-beta/services/networkconnectivity/resource_network_connectivity_spoke.go

+24
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func ResourceNetworkConnectivitySpoke() *schema.Resource {
8080
Optional: true,
8181
Description: `An optional description of the spoke.`,
8282
},
83+
"group": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Optional: true,
87+
ForceNew: true,
88+
Description: `The name of the group that this spoke is associated with.`,
89+
},
8390
"labels": {
8491
Type: schema.TypeMap,
8592
Optional: true,
@@ -364,6 +371,12 @@ func resourceNetworkConnectivitySpokeCreate(d *schema.ResourceData, meta interfa
364371
} else if v, ok := d.GetOkExists("hub"); !tpgresource.IsEmptyValue(reflect.ValueOf(hubProp)) && (ok || !reflect.DeepEqual(v, hubProp)) {
365372
obj["hub"] = hubProp
366373
}
374+
groupProp, err := expandNetworkConnectivitySpokeGroup(d.Get("group"), d, config)
375+
if err != nil {
376+
return err
377+
} else if v, ok := d.GetOkExists("group"); !tpgresource.IsEmptyValue(reflect.ValueOf(groupProp)) && (ok || !reflect.DeepEqual(v, groupProp)) {
378+
obj["group"] = groupProp
379+
}
367380
linkedVpnTunnelsProp, err := expandNetworkConnectivitySpokeLinkedVpnTunnels(d.Get("linked_vpn_tunnels"), d, config)
368381
if err != nil {
369382
return err
@@ -517,6 +530,9 @@ func resourceNetworkConnectivitySpokeRead(d *schema.ResourceData, meta interface
517530
if err := d.Set("hub", flattenNetworkConnectivitySpokeHub(res["hub"], d, config)); err != nil {
518531
return fmt.Errorf("Error reading Spoke: %s", err)
519532
}
533+
if err := d.Set("group", flattenNetworkConnectivitySpokeGroup(res["group"], d, config)); err != nil {
534+
return fmt.Errorf("Error reading Spoke: %s", err)
535+
}
520536
if err := d.Set("linked_vpn_tunnels", flattenNetworkConnectivitySpokeLinkedVpnTunnels(res["linkedVpnTunnels"], d, config)); err != nil {
521537
return fmt.Errorf("Error reading Spoke: %s", err)
522538
}
@@ -781,6 +797,10 @@ func flattenNetworkConnectivitySpokeHub(v interface{}, d *schema.ResourceData, c
781797
return tpgresource.ConvertSelfLinkToV1(v.(string))
782798
}
783799

800+
func flattenNetworkConnectivitySpokeGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
801+
return v
802+
}
803+
784804
func flattenNetworkConnectivitySpokeLinkedVpnTunnels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
785805
if v == nil {
786806
return nil
@@ -1000,6 +1020,10 @@ func expandNetworkConnectivitySpokeHub(v interface{}, d tpgresource.TerraformRes
10001020
return v, nil
10011021
}
10021022

1023+
func expandNetworkConnectivitySpokeGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1024+
return v, nil
1025+
}
1026+
10031027
func expandNetworkConnectivitySpokeLinkedVpnTunnels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10041028
l := v.([]interface{})
10051029
if len(l) == 0 || l[0] == nil {

Diff for: google-beta/services/networkconnectivity/resource_network_connectivity_spoke_generated_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,76 @@ resource "google_network_connectivity_spoke" "primary" {
9393
`, context)
9494
}
9595

96+
func TestAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(t *testing.T) {
97+
t.Parallel()
98+
99+
context := map[string]interface{}{
100+
"random_suffix": acctest.RandString(t, 10),
101+
}
102+
103+
acctest.VcrTest(t, resource.TestCase{
104+
PreCheck: func() { acctest.AccTestPreCheck(t) },
105+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
106+
CheckDestroy: testAccCheckNetworkConnectivitySpokeDestroyProducer(t),
107+
Steps: []resource.TestStep{
108+
{
109+
Config: testAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(context),
110+
},
111+
{
112+
ResourceName: "google_network_connectivity_spoke.primary",
113+
ImportState: true,
114+
ImportStateVerify: true,
115+
ImportStateVerifyIgnore: []string{"hub", "labels", "location", "terraform_labels"},
116+
},
117+
},
118+
})
119+
}
120+
121+
func testAccNetworkConnectivitySpoke_networkConnectivitySpokeLinkedVpcNetworkGroupExample(context map[string]interface{}) string {
122+
return acctest.Nprintf(`
123+
resource "google_compute_network" "network" {
124+
name = "tf-test-net-spoke%{random_suffix}"
125+
auto_create_subnetworks = false
126+
}
127+
128+
resource "google_network_connectivity_hub" "basic_hub" {
129+
name = "tf-test-hub1-spoke%{random_suffix}"
130+
description = "A sample hub"
131+
labels = {
132+
label-two = "value-one"
133+
}
134+
}
135+
136+
resource "google_network_connectivity_group" "default_group" {
137+
hub = google_network_connectivity_hub.basic_hub.id
138+
name = "default"
139+
description = "A sample hub group"
140+
}
141+
142+
resource "google_network_connectivity_spoke" "primary" {
143+
name = "tf-test-group-spoke1%{random_suffix}"
144+
location = "global"
145+
description = "A sample spoke with a linked VPC"
146+
labels = {
147+
label-one = "value-one"
148+
}
149+
hub = google_network_connectivity_hub.basic_hub.id
150+
linked_vpc_network {
151+
exclude_export_ranges = [
152+
"198.51.100.0/24",
153+
"10.10.0.0/16"
154+
]
155+
include_export_ranges = [
156+
"198.51.100.0/23",
157+
"10.0.0.0/8"
158+
]
159+
uri = google_compute_network.network.self_link
160+
}
161+
group = google_network_connectivity_group.default_group.id
162+
}
163+
`, context)
164+
}
165+
96166
func TestAccNetworkConnectivitySpoke_networkConnectivitySpokeRouterApplianceBasicExample(t *testing.T) {
97167
t.Parallel()
98168

Diff for: website/docs/r/network_connectivity_spoke.html.markdown

+54
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,56 @@ resource "google_network_connectivity_spoke" "primary" {
7171
}
7272
}
7373
```
74+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
75+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
76+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
77+
</a>
78+
</div>
79+
## Example Usage - Network Connectivity Spoke Linked Vpc Network Group
80+
81+
82+
```hcl
83+
resource "google_compute_network" "network" {
84+
name = "net-spoke"
85+
auto_create_subnetworks = false
86+
}
87+
88+
resource "google_network_connectivity_hub" "basic_hub" {
89+
name = "hub1-spoke"
90+
description = "A sample hub"
91+
labels = {
92+
label-two = "value-one"
93+
}
94+
}
95+
96+
resource "google_network_connectivity_group" "default_group" {
97+
hub = google_network_connectivity_hub.basic_hub.id
98+
name = "default"
99+
description = "A sample hub group"
100+
}
101+
102+
resource "google_network_connectivity_spoke" "primary" {
103+
name = "group-spoke1"
104+
location = "global"
105+
description = "A sample spoke with a linked VPC"
106+
labels = {
107+
label-one = "value-one"
108+
}
109+
hub = google_network_connectivity_hub.basic_hub.id
110+
linked_vpc_network {
111+
exclude_export_ranges = [
112+
"198.51.100.0/24",
113+
"10.10.0.0/16"
114+
]
115+
include_export_ranges = [
116+
"198.51.100.0/23",
117+
"10.0.0.0/8"
118+
]
119+
uri = google_compute_network.network.self_link
120+
}
121+
group = google_network_connectivity_group.default_group.id
122+
}
123+
```
74124
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
75125
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
76126
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -427,6 +477,10 @@ The following arguments are supported:
427477
(Optional)
428478
An optional description of the spoke.
429479

480+
* `group` -
481+
(Optional)
482+
The name of the group that this spoke is associated with.
483+
430484
* `linked_vpn_tunnels` -
431485
(Optional)
432486
The URIs of linked VPN tunnel resources

0 commit comments

Comments
 (0)