forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_compute_vpn_tunnel.go
684 lines (611 loc) · 20.5 KB
/
resource_compute_vpn_tunnel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package google
import (
"bytes"
"fmt"
"log"
"net"
"reflect"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform/helper/schema"
compute "google.golang.org/api/compute/v1"
)
// validatePeerAddr returns false if a tunnel's peer_ip property
// is invalid. Currently, only addresses that collide with RFC
// 5735 (https://tools.ietf.org/html/rfc5735) fail validation.
func validatePeerAddr(i interface{}, val string) ([]string, []error) {
ip := net.ParseIP(i.(string))
if ip == nil {
return nil, []error{fmt.Errorf("could not parse %q to IP address", val)}
}
for _, test := range invalidPeerAddrs {
if bytes.Compare(ip, test.from) >= 0 && bytes.Compare(ip, test.to) <= 0 {
return nil, []error{fmt.Errorf("address is invalid (is between %q and %q, conflicting with RFC5735)", test.from, test.to)}
}
}
return nil, nil
}
// invalidPeerAddrs is a collection of IP addres ranges that represent
// a conflict with RFC 5735 (https://tools.ietf.org/html/rfc5735#page-3).
// CIDR range notations in the RFC were converted to a (from, to) pair
// for easy checking with bytes.Compare.
var invalidPeerAddrs = []struct {
from net.IP
to net.IP
}{
{
from: net.ParseIP("0.0.0.0"),
to: net.ParseIP("0.255.255.255"),
},
{
from: net.ParseIP("10.0.0.0"),
to: net.ParseIP("10.255.255.255"),
},
{
from: net.ParseIP("127.0.0.0"),
to: net.ParseIP("127.255.255.255"),
},
{
from: net.ParseIP("169.254.0.0"),
to: net.ParseIP("169.254.255.255"),
},
{
from: net.ParseIP("172.16.0.0"),
to: net.ParseIP("172.31.255.255"),
},
{
from: net.ParseIP("192.0.0.0"),
to: net.ParseIP("192.0.0.255"),
},
{
from: net.ParseIP("192.0.2.0"),
to: net.ParseIP("192.0.2.255"),
},
{
from: net.ParseIP("192.88.99.0"),
to: net.ParseIP("192.88.99.255"),
},
{
from: net.ParseIP("192.168.0.0"),
to: net.ParseIP("192.168.255.255"),
},
{
from: net.ParseIP("198.18.0.0"),
to: net.ParseIP("198.19.255.255"),
},
{
from: net.ParseIP("198.51.100.0"),
to: net.ParseIP("198.51.100.255"),
},
{
from: net.ParseIP("203.0.113.0"),
to: net.ParseIP("203.0.113.255"),
},
{
from: net.ParseIP("224.0.0.0"),
to: net.ParseIP("239.255.255.255"),
},
{
from: net.ParseIP("240.0.0.0"),
to: net.ParseIP("255.255.255.255"),
},
{
from: net.ParseIP("255.255.255.255"),
to: net.ParseIP("255.255.255.255"),
},
}
func getVpnTunnelLink(config *Config, project string, region string, tunnel string) (string, error) {
if !strings.HasPrefix(tunnel, "https://www.googleapis.com/compute/") {
// Tunnel value provided is just the name, lookup the tunnel SelfLink
tunnelData, err := config.clientCompute.VpnTunnels.Get(
project, region, tunnel).Do()
if err != nil {
return "", fmt.Errorf("Error reading tunnel: %s", err)
}
tunnel = tunnelData.SelfLink
}
return tunnel, nil
}
func resourceComputeVpnTunnel() *schema.Resource {
return &schema.Resource{
Create: resourceComputeVpnTunnelCreate,
Read: resourceComputeVpnTunnelRead,
Update: resourceComputeVpnTunnelUpdate,
Delete: resourceComputeVpnTunnelDelete,
Importer: &schema.ResourceImporter{
State: resourceComputeVpnTunnelImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(240 * time.Second),
Update: schema.DefaultTimeout(240 * time.Second),
Delete: schema.DefaultTimeout(240 * time.Second),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"peer_ip": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validatePeerAddr,
},
"shared_secret": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
},
"target_vpn_gateway": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"router": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"ike_version": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 2,
},
"local_traffic_selector": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
"remote_traffic_selector": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"creation_timestamp": {
Type: schema.TypeString,
Computed: true,
},
"detailed_status": {
Type: schema.TypeString,
Computed: true,
},
"label_fingerprint": {
Type: schema.TypeString,
Computed: true,
},
"shared_secret_hash": {
Type: schema.TypeString,
Computed: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"self_link": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceComputeVpnTunnelCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
obj := make(map[string]interface{})
nameProp, err := expandComputeVpnTunnelName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
descriptionProp, err := expandComputeVpnTunnelDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
targetVpnGatewayProp, err := expandComputeVpnTunnelTargetVpnGateway(d.Get("target_vpn_gateway"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("target_vpn_gateway"); !isEmptyValue(reflect.ValueOf(targetVpnGatewayProp)) && (ok || !reflect.DeepEqual(v, targetVpnGatewayProp)) {
obj["targetVpnGateway"] = targetVpnGatewayProp
}
routerProp, err := expandComputeVpnTunnelRouter(d.Get("router"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("router"); !isEmptyValue(reflect.ValueOf(routerProp)) && (ok || !reflect.DeepEqual(v, routerProp)) {
obj["router"] = routerProp
}
peerIpProp, err := expandComputeVpnTunnelPeerIp(d.Get("peer_ip"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("peer_ip"); !isEmptyValue(reflect.ValueOf(peerIpProp)) && (ok || !reflect.DeepEqual(v, peerIpProp)) {
obj["peerIp"] = peerIpProp
}
sharedSecretProp, err := expandComputeVpnTunnelSharedSecret(d.Get("shared_secret"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("shared_secret"); !isEmptyValue(reflect.ValueOf(sharedSecretProp)) && (ok || !reflect.DeepEqual(v, sharedSecretProp)) {
obj["sharedSecret"] = sharedSecretProp
}
ikeVersionProp, err := expandComputeVpnTunnelIkeVersion(d.Get("ike_version"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ike_version"); !isEmptyValue(reflect.ValueOf(ikeVersionProp)) && (ok || !reflect.DeepEqual(v, ikeVersionProp)) {
obj["ikeVersion"] = ikeVersionProp
}
localTrafficSelectorProp, err := expandComputeVpnTunnelLocalTrafficSelector(d.Get("local_traffic_selector"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("local_traffic_selector"); !isEmptyValue(reflect.ValueOf(localTrafficSelectorProp)) && (ok || !reflect.DeepEqual(v, localTrafficSelectorProp)) {
obj["localTrafficSelector"] = localTrafficSelectorProp
}
remoteTrafficSelectorProp, err := expandComputeVpnTunnelRemoteTrafficSelector(d.Get("remote_traffic_selector"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("remote_traffic_selector"); !isEmptyValue(reflect.ValueOf(remoteTrafficSelectorProp)) && (ok || !reflect.DeepEqual(v, remoteTrafficSelectorProp)) {
obj["remoteTrafficSelector"] = remoteTrafficSelectorProp
}
labelsProp, err := expandComputeVpnTunnelLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
regionProp, err := expandComputeVpnTunnelRegion(d.Get("region"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(regionProp)) && (ok || !reflect.DeepEqual(v, regionProp)) {
obj["region"] = regionProp
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new VpnTunnel: %#v", obj)
res, err := sendRequest(config, "POST", url, obj)
if err != nil {
return fmt.Errorf("Error creating VpnTunnel: %s", err)
}
// Store the ID now
id, err := replaceVars(d, config, "{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
waitErr := computeOperationWaitTime(
config.clientCompute, op, project, "Creating VpnTunnel",
int(d.Timeout(schema.TimeoutCreate).Minutes()))
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create VpnTunnel: %s", waitErr)
}
log.Printf("[DEBUG] Finished creating VpnTunnel %q: %#v", d.Id(), res)
return resourceComputeVpnTunnelRead(d, meta)
}
func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}")
if err != nil {
return err
}
res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeVpnTunnel %q", d.Id()))
}
if err := d.Set("creation_timestamp", flattenComputeVpnTunnelCreationTimestamp(res["creationTimestamp"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("name", flattenComputeVpnTunnelName(res["name"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("description", flattenComputeVpnTunnelDescription(res["description"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("target_vpn_gateway", flattenComputeVpnTunnelTargetVpnGateway(res["targetVpnGateway"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("router", flattenComputeVpnTunnelRouter(res["router"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("peer_ip", flattenComputeVpnTunnelPeerIp(res["peerIp"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("shared_secret_hash", flattenComputeVpnTunnelSharedSecretHash(res["sharedSecretHash"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("ike_version", flattenComputeVpnTunnelIkeVersion(res["ikeVersion"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("local_traffic_selector", flattenComputeVpnTunnelLocalTrafficSelector(res["localTrafficSelector"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("remote_traffic_selector", flattenComputeVpnTunnelRemoteTrafficSelector(res["remoteTrafficSelector"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("labels", flattenComputeVpnTunnelLabels(res["labels"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("label_fingerprint", flattenComputeVpnTunnelLabelFingerprint(res["labelFingerprint"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("detailed_status", flattenComputeVpnTunnelDetailedStatus(res["detailedStatus"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("region", flattenComputeVpnTunnelRegion(res["region"])); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
project, err := getProject(d, config)
if err != nil {
return err
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
return nil
}
func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
d.Partial(true)
if d.HasChange("labels") || d.HasChange("label_fingerprint") {
obj := make(map[string]interface{})
labelsProp, err := expandComputeVpnTunnelLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
labelFingerprintProp := d.Get("label_fingerprint")
obj["labelFingerprint"] = labelFingerprintProp
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}/setLabels")
if err != nil {
return err
}
res, err := sendRequest(config, "POST", url, obj)
if err != nil {
return fmt.Errorf("Error updating VpnTunnel %q: %s", d.Id(), err)
}
project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Updating VpnTunnel",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
if err != nil {
return err
}
d.SetPartial("labels")
d.SetPartial("label_fingerprint")
}
d.Partial(false)
return resourceComputeVpnTunnelRead(d, meta)
}
func resourceComputeVpnTunnelDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}")
if err != nil {
return err
}
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting VpnTunnel %q", d.Id())
res, err := sendRequest(config, "DELETE", url, obj)
if err != nil {
return handleNotFoundError(err, d, "VpnTunnel")
}
project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Deleting VpnTunnel",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
if err != nil {
return err
}
log.Printf("[DEBUG] Finished deleting VpnTunnel %q: %#v", d.Id(), res)
return nil
}
func resourceComputeVpnTunnelImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/regions/(?P<region>[^/]+)/vpnTunnels/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
// Replace import id for the resource id
id, err := replaceVars(d, config, "{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
}
func flattenComputeVpnTunnelCreationTimestamp(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelName(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelDescription(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelTargetVpnGateway(v interface{}) interface{} {
if v == nil {
return v
}
return ConvertSelfLinkToV1(v.(string))
}
func flattenComputeVpnTunnelRouter(v interface{}) interface{} {
if v == nil {
return v
}
return NameFromSelfLinkStateFunc(v)
}
func flattenComputeVpnTunnelPeerIp(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelSharedSecret(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelSharedSecretHash(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelIkeVersion(v interface{}) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
return v
}
func flattenComputeVpnTunnelLocalTrafficSelector(v interface{}) interface{} {
if v == nil {
return v
}
return schema.NewSet(schema.HashString, v.([]interface{}))
}
func flattenComputeVpnTunnelRemoteTrafficSelector(v interface{}) interface{} {
if v == nil {
return v
}
return schema.NewSet(schema.HashString, v.([]interface{}))
}
func flattenComputeVpnTunnelLabels(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelLabelFingerprint(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelDetailedStatus(v interface{}) interface{} {
return v
}
func flattenComputeVpnTunnelRegion(v interface{}) interface{} {
if v == nil {
return v
}
return NameFromSelfLinkStateFunc(v)
}
func expandComputeVpnTunnelName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeVpnTunnelDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeVpnTunnelTargetVpnGateway(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseRegionalFieldValue("targetVpnGateways", v.(string), "project", "region", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for target_vpn_gateway: %s", err)
}
return f.RelativeLink(), nil
}
func expandComputeVpnTunnelRouter(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
if v == nil || v.(string) == "" {
return "", nil
}
f, err := parseRegionalFieldValue("routers", v.(string), "project", "region", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for router: %s", err)
}
return "https://www.googleapis.com/compute/v1/" + f.RelativeLink(), nil
}
func expandComputeVpnTunnelPeerIp(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeVpnTunnelSharedSecret(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeVpnTunnelIkeVersion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
func expandComputeVpnTunnelLocalTrafficSelector(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
v = v.(*schema.Set).List()
return v, nil
}
func expandComputeVpnTunnelRemoteTrafficSelector(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
v = v.(*schema.Set).List()
return v, nil
}
func expandComputeVpnTunnelLabels(v interface{}, d *schema.ResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}
func expandComputeVpnTunnelRegion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for region: %s", err)
}
return f.RelativeLink(), nil
}