@@ -4,6 +4,7 @@ package compute_test
4
4
5
5
import (
6
6
"fmt"
7
+ "regexp"
7
8
"testing"
8
9
9
10
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -26,9 +27,10 @@ func TestAccComputeRouterPeer_basic(t *testing.T) {
26
27
t , "google_compute_router_peer.foobar" ),
27
28
},
28
29
{
29
- ResourceName : "google_compute_router_peer.foobar" ,
30
- ImportState : true ,
31
- ImportStateVerify : true ,
30
+ ResourceName : "google_compute_router_peer.foobar" ,
31
+ ImportState : true ,
32
+ ImportStateVerify : true ,
33
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
32
34
},
33
35
{
34
36
Config : testAccComputeRouterPeerKeepRouter (routerName ),
@@ -54,19 +56,21 @@ func TestAccComputeRouterPeer_advertiseMode(t *testing.T) {
54
56
t , "google_compute_router_peer.foobar" ),
55
57
},
56
58
{
57
- ResourceName : "google_compute_router_peer.foobar" ,
58
- ImportState : true ,
59
- ImportStateVerify : true ,
59
+ ResourceName : "google_compute_router_peer.foobar" ,
60
+ ImportState : true ,
61
+ ImportStateVerify : true ,
62
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" , "is_custom_learned_priority_set" },
60
63
},
61
64
{
62
65
Config : testAccComputeRouterPeerAdvertiseModeUpdate (routerName ),
63
66
Check : testAccCheckComputeRouterPeerExists (
64
67
t , "google_compute_router_peer.foobar" ),
65
68
},
66
69
{
67
- ResourceName : "google_compute_router_peer.foobar" ,
68
- ImportState : true ,
69
- ImportStateVerify : true ,
70
+ ResourceName : "google_compute_router_peer.foobar" ,
71
+ ImportState : true ,
72
+ ImportStateVerify : true ,
73
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" , "is_custom_learned_priority_set" },
70
74
},
71
75
},
72
76
})
@@ -87,29 +91,32 @@ func TestAccComputeRouterPeer_enable(t *testing.T) {
87
91
t , "google_compute_router_peer.foobar" ),
88
92
},
89
93
{
90
- ResourceName : "google_compute_router_peer.foobar" ,
91
- ImportState : true ,
92
- ImportStateVerify : true ,
94
+ ResourceName : "google_compute_router_peer.foobar" ,
95
+ ImportState : true ,
96
+ ImportStateVerify : true ,
97
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
93
98
},
94
99
{
95
100
Config : testAccComputeRouterPeerEnable (routerName , false ),
96
101
Check : testAccCheckComputeRouterPeerExists (
97
102
t , "google_compute_router_peer.foobar" ),
98
103
},
99
104
{
100
- ResourceName : "google_compute_router_peer.foobar" ,
101
- ImportState : true ,
102
- ImportStateVerify : true ,
105
+ ResourceName : "google_compute_router_peer.foobar" ,
106
+ ImportState : true ,
107
+ ImportStateVerify : true ,
108
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
103
109
},
104
110
{
105
111
Config : testAccComputeRouterPeerEnable (routerName , true ),
106
112
Check : testAccCheckComputeRouterPeerExists (
107
113
t , "google_compute_router_peer.foobar" ),
108
114
},
109
115
{
110
- ResourceName : "google_compute_router_peer.foobar" ,
111
- ImportState : true ,
112
- ImportStateVerify : true ,
116
+ ResourceName : "google_compute_router_peer.foobar" ,
117
+ ImportState : true ,
118
+ ImportStateVerify : true ,
119
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
113
120
},
114
121
},
115
122
})
@@ -130,29 +137,32 @@ func TestAccComputeRouterPeer_bfd(t *testing.T) {
130
137
t , "google_compute_router_peer.foobar" ),
131
138
},
132
139
{
133
- ResourceName : "google_compute_router_peer.foobar" ,
134
- ImportState : true ,
135
- ImportStateVerify : true ,
140
+ ResourceName : "google_compute_router_peer.foobar" ,
141
+ ImportState : true ,
142
+ ImportStateVerify : true ,
143
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
136
144
},
137
145
{
138
146
Config : testAccComputeRouterPeerBfd (routerName , "DISABLED" ),
139
147
Check : testAccCheckComputeRouterPeerExists (
140
148
t , "google_compute_router_peer.foobar" ),
141
149
},
142
150
{
143
- ResourceName : "google_compute_router_peer.foobar" ,
144
- ImportState : true ,
145
- ImportStateVerify : true ,
151
+ ResourceName : "google_compute_router_peer.foobar" ,
152
+ ImportState : true ,
153
+ ImportStateVerify : true ,
154
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
146
155
},
147
156
{
148
157
Config : testAccComputeRouterPeerBasic (routerName ),
149
158
Check : testAccCheckComputeRouterPeerExists (
150
159
t , "google_compute_router_peer.foobar" ),
151
160
},
152
161
{
153
- ResourceName : "google_compute_router_peer.foobar" ,
154
- ImportState : true ,
155
- ImportStateVerify : true ,
162
+ ResourceName : "google_compute_router_peer.foobar" ,
163
+ ImportState : true ,
164
+ ImportStateVerify : true ,
165
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
156
166
},
157
167
},
158
168
})
@@ -173,9 +183,10 @@ func TestAccComputeRouterPeer_routerApplianceInstance(t *testing.T) {
173
183
t , "google_compute_router_peer.foobar" ),
174
184
},
175
185
{
176
- ResourceName : "google_compute_router_peer.foobar" ,
177
- ImportState : true ,
178
- ImportStateVerify : true ,
186
+ ResourceName : "google_compute_router_peer.foobar" ,
187
+ ImportState : true ,
188
+ ImportStateVerify : true ,
189
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
179
190
},
180
191
},
181
192
})
@@ -200,9 +211,10 @@ func TestAccComputeRouterPeer_Ipv6Basic(t *testing.T) {
200
211
),
201
212
},
202
213
{
203
- ResourceName : resourceName ,
204
- ImportState : true ,
205
- ImportStateVerify : true ,
214
+ ResourceName : resourceName ,
215
+ ImportState : true ,
216
+ ImportStateVerify : true ,
217
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
206
218
},
207
219
},
208
220
})
@@ -227,9 +239,10 @@ func TestAccComputeRouterPeer_Ipv4BasicCreateUpdate(t *testing.T) {
227
239
),
228
240
},
229
241
{
230
- ResourceName : resourceName ,
231
- ImportState : true ,
232
- ImportStateVerify : true ,
242
+ ResourceName : resourceName ,
243
+ ImportState : true ,
244
+ ImportStateVerify : true ,
245
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
233
246
},
234
247
{
235
248
Config : testAccComputeRouterPeerUpdateIpv4Address (routerName ),
@@ -242,9 +255,37 @@ func TestAccComputeRouterPeer_Ipv4BasicCreateUpdate(t *testing.T) {
242
255
),
243
256
},
244
257
{
245
- ResourceName : resourceName ,
246
- ImportState : true ,
247
- ImportStateVerify : true ,
258
+ ResourceName : resourceName ,
259
+ ImportState : true ,
260
+ ImportStateVerify : true ,
261
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
262
+ },
263
+ },
264
+ })
265
+ }
266
+
267
+ func TestAccComputeRouterPeer_UpdateRouterCustomLearnedRoutePriority (t * testing.T ) {
268
+ t .Parallel ()
269
+ routerName := fmt .Sprintf ("tf-test-router-%s" , acctest .RandString (t , 10 ))
270
+ resourceName := "google_compute_router_peer.peer"
271
+ acctest .VcrTest (t , resource.TestCase {
272
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
273
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
274
+ CheckDestroy : testAccCheckComputeRouterPeerDestroyProducer (t ),
275
+ Steps : []resource.TestStep {
276
+ {
277
+ Config : testAccComputeRouterPeerCustomLearnedRoutePriority (routerName , 100 , false ),
278
+ Check : resource .ComposeTestCheckFunc (
279
+ resource .TestCheckResourceAttr (resourceName , "custom_learned_route_priority" , "100" ), // Check for one element in the list
280
+ ),
281
+ }, {
282
+ Config : testAccComputeRouterPeerCustomLearnedRoutePriority (routerName , 0 , false ),
283
+ ExpectError : regexp .MustCompile (`Error: Invalid custom_learned_route_priority value: When zero_custom_learned_route_priority is set to 'false', the custom_learned_route_priority field cannot be 0. Please provide a non-zero value.` ), // Expect the specific error message
284
+ }, {
285
+ Config : testAccComputeRouterPeerCustomLearnedRoutePriority (routerName , 0 , true ),
286
+ Check : resource .ComposeTestCheckFunc (
287
+ resource .TestCheckResourceAttr (resourceName , "custom_learned_route_priority" , "0" ),
288
+ ),
248
289
},
249
290
},
250
291
})
@@ -269,9 +310,10 @@ func TestAccComputeRouterPeer_UpdateIpv6Address(t *testing.T) {
269
310
),
270
311
},
271
312
{
272
- ResourceName : resourceName ,
273
- ImportState : true ,
274
- ImportStateVerify : true ,
313
+ ResourceName : resourceName ,
314
+ ImportState : true ,
315
+ ImportStateVerify : true ,
316
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
275
317
},
276
318
{
277
319
Config : testAccComputeRouterPeerUpdateIpv6Address (routerName , true ),
@@ -282,9 +324,10 @@ func TestAccComputeRouterPeer_UpdateIpv6Address(t *testing.T) {
282
324
),
283
325
},
284
326
{
285
- ResourceName : resourceName ,
286
- ImportState : true ,
287
- ImportStateVerify : true ,
327
+ ResourceName : resourceName ,
328
+ ImportState : true ,
329
+ ImportStateVerify : true ,
330
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
288
331
},
289
332
},
290
333
})
@@ -309,9 +352,10 @@ func TestAccComputeRouterPeer_EnableDisableIpv6(t *testing.T) {
309
352
),
310
353
},
311
354
{
312
- ResourceName : resourceName ,
313
- ImportState : true ,
314
- ImportStateVerify : true ,
355
+ ResourceName : resourceName ,
356
+ ImportState : true ,
357
+ ImportStateVerify : true ,
358
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
315
359
},
316
360
{
317
361
Config : testAccComputeRouterPeerIpv6 (routerName , true ),
@@ -322,9 +366,10 @@ func TestAccComputeRouterPeer_EnableDisableIpv6(t *testing.T) {
322
366
),
323
367
},
324
368
{
325
- ResourceName : resourceName ,
326
- ImportState : true ,
327
- ImportStateVerify : true ,
369
+ ResourceName : resourceName ,
370
+ ImportState : true ,
371
+ ImportStateVerify : true ,
372
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
328
373
},
329
374
{
330
375
Config : testAccComputeRouterPeerIpv6 (routerName , false ),
@@ -335,9 +380,10 @@ func TestAccComputeRouterPeer_EnableDisableIpv6(t *testing.T) {
335
380
),
336
381
},
337
382
{
338
- ResourceName : resourceName ,
339
- ImportState : true ,
340
- ImportStateVerify : true ,
383
+ ResourceName : resourceName ,
384
+ ImportState : true ,
385
+ ImportStateVerify : true ,
386
+ ImportStateVerifyIgnore : []string {"zero_custom_learned_route_priority" },
341
387
},
342
388
},
343
389
})
@@ -999,6 +1045,42 @@ func testAccComputeRouterPeerWithMd5AuthKeyUpdate(routerName string) string {
999
1045
routerName , routerName )
1000
1046
}
1001
1047
1048
+ func testAccComputeRouterPeerCustomLearnedRoutePriority (routerName string , customLearnedRoutePriority int , zeroCustomLearnedRoutePriority bool ) string {
1049
+ return fmt .Sprintf (`
1050
+ resource "google_compute_network" "network" {
1051
+ name = "%s-net"
1052
+ auto_create_subnetworks = false
1053
+ }
1054
+
1055
+ resource "google_compute_subnetwork" "subnetwork" {
1056
+ name = "%s-sub"
1057
+ network = google_compute_network.network.self_link
1058
+ ip_cidr_range = "10.0.0.0/16"
1059
+ region = "us-central1"
1060
+ }
1061
+
1062
+ resource "google_compute_router" "router" {
1063
+ name = "%s-router"
1064
+ region = google_compute_subnetwork.subnetwork.region
1065
+ network = google_compute_network.network.self_link
1066
+ bgp {
1067
+ asn = 64514
1068
+ }
1069
+ }
1070
+
1071
+ resource "google_compute_router_peer" "peer" {
1072
+ name = "%s-router-peer"
1073
+ router = google_compute_router.router.name
1074
+ region = google_compute_router.router.region
1075
+ interface = "interface-1"
1076
+ peer_asn = 65513
1077
+ custom_learned_route_priority = %d
1078
+ zero_custom_learned_route_priority = %t
1079
+ }
1080
+ ` , routerName , routerName , routerName , routerName , customLearnedRoutePriority , zeroCustomLearnedRoutePriority )
1081
+
1082
+ }
1083
+
1002
1084
func testAccComputeRouterPeerKeepRouter (routerName string ) string {
1003
1085
return fmt .Sprintf (`
1004
1086
resource "google_compute_network" "foobar" {
0 commit comments