1+ {{ if ne $ .TargetVersionName ` ga` -}}
2+ package networkconnectivity_test
3+
4+ import (
5+ " testing"
6+
7+ " github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+ " github.com/hashicorp/terraform-provider-google/google/acctest"
9+ " github.com/hashicorp/terraform-provider-google/google/envvar"
10+ " github.com/hashicorp/terraform-plugin-testing/plancheck"
11+ )
12+
13+ func TestAccNetworkConnectivityGatewayAdvertisedRouter_test_basic(t *testing.T ) {
14+ t.Parallel ()
15+
16+ context := map[string]interface{}{
17+ " project_name" : envvar.GetTestProjectFromEnv (),
18+ " region" : envvar.GetTestRegionFromEnv (),
19+ " random_suffix" : acctest.RandString (t, 10),
20+ }
21+
22+ acctest.VcrTest (t, resource.TestCase {
23+ PreCheck: func() { acctest.AccTestPreCheck (t) },
24+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories (t),
25+ CheckDestroy: testAccCheckNetworkConnectivitySpokeDestroyProducer(t),
26+ Steps: []resource.TestStep {
27+ {
28+ Config: testAccNetworkConnectivitySpoke_test_basic(context),
29+ },
30+ {
31+ ResourceName: " google_network_connectivity_gateway_advertised_route.gateway-advertised-route" ,
32+ ImportState: true,
33+ ImportStateVerify: true,
34+ ImportStateVerifyIgnore: []string{" labels" , " terraform_labels" },
35+ },
36+ {
37+ Config: testAccNetworkConnectivitySpoke_test_update(context),
38+ ConfigPlanChecks: resource.ConfigPlanChecks {
39+ PreApply: []plancheck.PlanCheck {
40+ plancheck.ExpectResourceAction (" google_network_connectivity_gateway_advertised_route.gateway-advertised-route" , plancheck.ResourceActionUpdate ),
41+ },
42+ },
43+ },
44+ {
45+ ResourceName: " google_network_connectivity_gateway_advertised_route.gateway-advertised-route" ,
46+ ImportState: true,
47+ ImportStateVerify: true,
48+ ImportStateVerifyIgnore: []string{" labels" , " terraform_labels" },
49+ },
50+ },
51+ })
52+ }
53+
54+ func testAccNetworkConnectivitySpoke_test_basic(context map[string]interface{}) string {
55+ return acctest.Nprintf (`
56+
57+ resource "google_compute_network" "network" {
58+ name = "tf-test-network%{random_suffix}"
59+ auto_create_subnetworks = false
60+ }
61+
62+ resource "google_compute_subnetwork" "subnetwork" {
63+ name = "tf-test-subnet%{random_suffix}"
64+ ip_cidr_range = "10.0.0.0/28"
65+ region = "us-east1"
66+ network = google_compute_network.network.self_link
67+ }
68+
69+ resource "google_network_connectivity_hub" "basic_hub" {
70+ name = "tf-test-hub%{random_suffix}"
71+ description = "A sample hub"
72+ labels = {
73+ label-two = "value-one"
74+ }
75+ preset_topology = "HYBRID_INSPECTION"
76+ }
77+
78+ resource "google_network_connectivity_spoke" "primary" {
79+ name = "tf-test-name%{random_suffix}"
80+ location = "us-east1"
81+ description = "A sample spoke with a linked routher appliance instance"
82+ labels = {
83+ label-one = "value-one"
84+ }
85+ hub = google_network_connectivity_hub.basic_hub.id
86+ gateway {
87+ ip_range_reservations {
88+ ip_range = "10.0.0.0/23"
89+ }
90+ capacity = "CAPACITY_1_GBPS"
91+ }
92+ group = "gateways"
93+ }
94+
95+ resource "google_network_connectivity_gateway_advertised_route" "gateway-advertised-route" {
96+ spoke = google_network_connectivity_spoke.primary.name
97+ location = "us-east1"
98+ name = "tf-test-gateway-advertised-route%{random_suffix}"
99+ labels = {
100+ label-one = "value-one"
101+ }
102+ description = "description of the gateway advertised route"
103+ ip_range = "0.0.0.0/24"
104+ recipient = "ADVERTISE_TO_HUB"
105+ priority = 200
106+ }
107+ ` , context)
108+ }
109+
110+ func testAccNetworkConnectivitySpoke_test_update(context map[string]interface{}) string {
111+ return acctest.Nprintf (`
112+
113+ resource "google_compute_network" "network" {
114+ name = "tf-test-network%{random_suffix}"
115+ auto_create_subnetworks = false
116+ }
117+
118+ resource "google_compute_subnetwork" "subnetwork" {
119+ name = "tf-test-subnet%{random_suffix}"
120+ ip_cidr_range = "10.0.0.0/28"
121+ region = "us-east1"
122+ network = google_compute_network.network.self_link
123+ }
124+
125+ resource "google_network_connectivity_hub" "basic_hub" {
126+ name = "tf-test-hub%{random_suffix}"
127+ description = "A sample hub"
128+ labels = {
129+ label-two = "value-one"
130+ }
131+ preset_topology = "HYBRID_INSPECTION"
132+ }
133+
134+ resource "google_network_connectivity_spoke" "primary" {
135+ name = "tf-test-name%{random_suffix}"
136+ location = "us-east1"
137+ description = "A sample spoke with a linked routher appliance instance"
138+ labels = {
139+ label-one = "value-one"
140+ }
141+ hub = google_network_connectivity_hub.basic_hub.id
142+ gateway {
143+ ip_range_reservations {
144+ ip_range = "10.0.0.0/23"
145+ }
146+ capacity = "CAPACITY_1_GBPS"
147+ }
148+ group = "gateways"
149+ }
150+
151+ resource "google_network_connectivity_gateway_advertised_route" "gateway-advertised-route" {
152+ spoke = google_network_connectivity_spoke.primary.name
153+ location = "us-east1"
154+ name = "tf-test-gateway-advertised-route%{random_suffix}"
155+ labels = {
156+ label-one = "value-one"
157+ }
158+ description = "description of the gateway advertised route"
159+ ip_range = "0.0.0.0/24"
160+ recipient = "ADVERTISE_TO_HUB"
161+ priority = 100
162+ }
163+ ` , context)
164+ }
165+
166+
167+ {{- end }}
0 commit comments