This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
/
show_test.go
701 lines (664 loc) · 20 KB
/
show_test.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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
package instance // import "github.com/docker/infrakit/pkg/provider/terraform/instance"
import (
"bufio"
"bytes"
"os"
"path"
"strings"
"testing"
"github.com/docker/infrakit/pkg/spi/flavor"
"github.com/docker/infrakit/pkg/spi/group"
"github.com/stretchr/testify/require"
. "github.com/docker/infrakit/pkg/testing"
)
func TestTerraformShowParseResultEmpty(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("aws_vpc")},
nil,
bytes.NewBuffer([]byte("")),
)
require.NoError(t, err)
require.Equal(t, map[TResourceType]map[TResourceName]TResourceProperties{}, found)
}
func TestTerraformShowParseResultResTypes(t *testing.T) {
data := []byte(`
res-type1.host1:
id = type1-host1
other = type1-host1-other
res-type1.host2:
id = type1-host2
res-type2.host1:
id = type2-host1
other = type2-host1-other
res-type3.host1:
id = type3-host1
other = type3-host1-other`)
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("unknown")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(t, map[TResourceType]map[TResourceName]TResourceProperties{}, found)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type1")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type1"): {
TResourceName("host1"): {"id": "type1-host1", "other": "type1-host1-other"},
TResourceName("host2"): {"id": "type1-host2"},
},
},
found,
)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type2")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type2"): {
TResourceName("host1"): {"id": "type2-host1", "other": "type2-host1-other"},
},
},
found,
)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type3")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type3"): {
TResourceName("host1"): {"id": "type3-host1", "other": "type3-host1-other"},
},
},
found,
)
// Property ID filtering
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type3")},
[]string{"id"},
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type3"): {
TResourceName("host1"): {"id": "type3-host1"},
},
},
found,
)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type3")},
[]string{"id", "foo"},
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type3"): {
TResourceName("host1"): {"id": "type3-host1"},
},
},
found,
)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type3")},
[]string{"foo"},
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type3"): {
TResourceName("host1"): {},
},
},
found,
)
// Reesource type filtering
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type1"), TResourceType("res-type2"), TResourceType("res-type3"), TResourceType("foo")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type1"): {
TResourceName("host1"): {"id": "type1-host1", "other": "type1-host1-other"},
TResourceName("host2"): {"id": "type1-host2"},
},
TResourceType("res-type2"): {
TResourceName("host1"): {"id": "type2-host1", "other": "type2-host1-other"},
},
TResourceType("res-type3"): {
TResourceName("host1"): {"id": "type3-host1", "other": "type3-host1-other"},
},
},
found,
)
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("res-type1"), TResourceType("res-type3"), TResourceType("foo")},
[]string{"other"},
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(
t,
map[TResourceType]map[TResourceName]TResourceProperties{
TResourceType("res-type1"): {
TResourceName("host1"): {"other": "type1-host1-other"},
TResourceName("host2"): {},
},
TResourceType("res-type3"): {
TResourceName("host1"): {"other": "type3-host1-other"},
},
},
found,
)
}
func convertToSingleInstanceOutput(data []byte, resTypeName string) []byte {
resType := strings.Split(resTypeName, ".")[0]
resName := strings.Split(resTypeName, ".")[1]
match := false
lines := []string{}
reader := bufio.NewReader(bytes.NewBuffer(data))
for {
line, _, err := reader.ReadLine()
if err != nil {
break
}
m := title.FindAllStringSubmatch(string(line), -1)
if m != nil && len(m[0][1]) > 0 && len(m[0][2]) > 0 {
if m[0][1] == resType && m[0][2] == resName {
match = true
} else if len(lines) > 0 {
// No longer match, break if we have data
break
}
} else if match {
// Remove leading spaces
lineStr := string(line)
for lineStr[0:1] == " " {
lineStr = lineStr[1:]
}
lines = append(lines, lineStr)
}
}
return []byte(strings.Join(lines, "\n"))
}
func TestTerraformShowParseResultEmptyValues(t *testing.T) {
// {
// "id": 123,
// "destination_cidr_block": "0.0.0.0/0",
// "destination_prefix_list_id": "",
// "gateway_id": "",
// "instance_id": "",
// "instance_owner_id": "",
// "pie": 3.14
// }
// Code editors tend to remove the trailing whitespace above, ensure that a space exists
// after the equals
input := strings.Replace(`
type.host:
id = 123
destination_cidr_block = 0.0.0.0/0
destination_prefix_list_id =
gateway_id = igw-c5fcffac
instance_id =
instance_owner_id =
pie = 3.14
`, "=\n", "= \n", -1)
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("type")},
nil,
bytes.NewBuffer([]byte(input)),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": 123,
"destination_cidr_block": "0.0.0.0/0",
"destination_prefix_list_id": "",
"gateway_id": "igw-c5fcffac",
"instance_id": "",
"instance_owner_id": "",
"pie": 3.14,
}
require.Equal(t, expected, found[TResourceType("type")][TResourceName("host")])
// Also verify single instance output
data := convertToSingleInstanceOutput([]byte(input), "type.host")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultLists(t *testing.T) {
// {
// "id": 1,
// "tags": ["tag1", "tag2"],
// "keys": [1, "k2", false],
// "z-foo": "z-bar"
// }
data := []byte(`
type.host:
id = 1
tags.# = 2
tags.123 = tag1
tags.234 = tag2
keys.# = 3
keys.123 = 1
keys.234 = k2
keys.345 = false
z-foo = z-bar
`)
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("type")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": 1,
"tags": []interface{}{"tag1", "tag2"},
"keys": []interface{}{1, "k2", false},
"z-foo": "z-bar",
}
require.Equal(t, expected, found[TResourceType("type")][TResourceName("host")])
// Also verify single instance output
data = convertToSingleInstanceOutput(data, "type.host")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultMaps(t *testing.T) {
// {
// "id": 1,
// "tags": {
// "tag1": "v1",
// "tag2": "v2"
// },
// "keys": {
// "key1": 1,
// "key2": "k2",
// "key3": false
// }
// }
data := []byte(`
type.host:
id = 1
tags.% = 2
tags.tag1 = v1
tags.tag2 = v2
keys.% = 3
keys.key1 = 1
keys.key2 = k2
keys.key3 = false
z-foo = z-bar
`)
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("type")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": 1,
"tags": map[string]interface{}{"tag1": "v1", "tag2": "v2"},
"keys": map[string]interface{}{"key1": 1, "key2": "k2", "key3": false},
"z-foo": "z-bar",
}
require.Equal(t, expected, found[TResourceType("type")][TResourceName("host")])
// Also verify single instance output
data = convertToSingleInstanceOutput(data, "type.host")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultNested(t *testing.T) {
// {
// "id": 1,
// "tags": [
// {"list1": [1, 2]},
// 5,
// {"list2": [3, 4]},
// [
// true, false
// ]
// ]
// }
data := []byte(`
type.host:
id = 1
tags.# = 3
tags.111.list1.# = 2
tags.111.list1.111 = 1
tags.111.list1.222 = 2
tags.222 = 5
tags.333.list2.# = 2
tags.333.list2.111 = 3
tags.333.list2.222 = 4
`)
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("type")},
nil,
bytes.NewBuffer(data),
)
require.NoError(t, err)
require.Equal(t, 1, len(found))
props := found[TResourceType("type")][TResourceName("host")]
require.Equal(t, 2, len(props))
require.Equal(t, 1, props["id"])
// Tag list sort order not guaranteed
tags := props["tags"].([]interface{})
require.Equal(t, 3, len(tags))
require.Contains(t, tags, 5)
require.Contains(t, tags, map[string]interface{}{"list1": []interface{}{1, 2}})
require.Contains(t, tags, map[string]interface{}{"list2": []interface{}{3, 4}})
// Also verify single instance output
data = convertToSingleInstanceOutput(data, "type.host")
props, err = parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, 2, len(props))
require.Equal(t, 1, props["id"])
tags = props["tags"].([]interface{})
require.Equal(t, 3, len(tags))
require.Contains(t, tags, 5)
require.Contains(t, tags, map[string]interface{}{"list1": []interface{}{1, 2}})
require.Contains(t, tags, map[string]interface{}{"list2": []interface{}{3, 4}})
}
var terraformShowOutput = []byte(`
aws_internet_gateway.default:
id = igw-c5fcffac
tags.% = 1
tags.provisioner = infrakit-terraform-demo
vpc_id = vpc-f8d45a90
aws_route.internet_access:
id = r-rtb-7bf68e131080289494
destination_cidr_block = 0.0.0.0/0
destination_prefix_list_id =
gateway_id = igw-c5fcffac
instance_id =
instance_owner_id =
nat_gateway_id =
network_interface_id =
origin = CreateRoute
route_table_id = rtb-7bf68e13
state = active
vpc_peering_connection_id =
aws_security_group.default:
id = sg-b903abd2
description = Used in the terraform
egress.# = 1
egress.482069346.cidr_blocks.# = 1
egress.482069346.cidr_blocks.0 = 0.0.0.0/0
egress.482069346.from_port = 0
egress.482069346.prefix_list_ids.# = 0
egress.482069346.protocol = -1
egress.482069346.security_groups.# = 0
egress.482069346.self = false
egress.482069346.to_port = 0
ingress.# = 2
ingress.2165049311.cidr_blocks.# = 1
ingress.2165049311.cidr_blocks.0 = 10.0.0.0/16
ingress.2165049311.from_port = 80
ingress.2165049311.protocol = tcp
ingress.2165049311.security_groups.# = 0
ingress.2165049311.self = false
ingress.2165049311.to_port = 80
ingress.2541437006.cidr_blocks.# = 1
ingress.2541437006.cidr_blocks.0 = 0.0.0.0/0
ingress.2541437006.from_port = 22
ingress.2541437006.protocol = tcp
ingress.2541437006.security_groups.# = 0
ingress.2541437006.self = false
ingress.2541437006.to_port = 22
name = terraform_example
owner_id = 041673875206
tags.% = 1
tags.provisioner = infrakit-terraform-demo
vpc_id = vpc-f8d45a90
aws_subnet.default:
id = subnet-32feb75a
availability_zone = eu-central-1a
cidr_block = 10.0.1.0/24
map_public_ip_on_launch = true
tags.% = 1
tags.provisioner = infrakit-terraform-demo
vpc_id = vpc-f8d45a90
ibm_compute_vm_instance.instance-1499827079:
id = 36147555
cores = 1
datacenter = dal10
file_storage_ids.# = 0
hostname = worker-1499827079
memory = 2048
ssh_key_ids.# = 1
ssh_key_ids.0 = 123456
tags.# = 5
tags.1516831048 = infrakit.group:workers
tags.3434794676 = infrakit.config.hash:tubmesopo6lrsfnl5otajlpvwd23v46j
tags.356689043 = name:instance-1499827079
tags.3639269190 = infrakit-link-context:swarm::c80s4c4kq0kgjs64ojxzvsdjz::worker
tags.838324444 = infrakit.cluster.id:c80s4c4kq0kgjs64ojxzvsdjz
user_metadata = set -o errexit
set -o nounset
set -o xtrace
apt-get -y update
FOO=BAR
echo $FOO
z_prop = z_val
aws_vpc.default:
id = vpc-f8d45a90
cidr_block = 10.0.0.0/16
default_network_acl_id = acl-9d88fef5
default_route_table_id = rtb-7bf68e13
default_security_group_id = sg-1403ab7f
dhcp_options_id = dopt-b632fedf
enable_dns_hostnames = false
enable_dns_support = true
instance_tenancy = default
main_route_table_id = rtb-7bf68e13
tags.% = 1
tags.provisioner = infrakit-terraform-demo
`)
func TestTerraformShowParseResultTagsList(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("ibm_compute_vm_instance")},
nil,
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": 36147555,
"cores": 1,
"datacenter": "dal10",
"file_storage_ids": []interface{}{},
"hostname": "worker-1499827079",
"memory": 2048,
"ssh_key_ids": []interface{}{123456},
"tags": []interface{}{
group.GroupTag + ":workers",
group.ConfigSHATag + ":tubmesopo6lrsfnl5otajlpvwd23v46j",
"name:instance-1499827079",
"infrakit-link-context:swarm::c80s4c4kq0kgjs64ojxzvsdjz::worker",
flavor.ClusterIDTag + ":c80s4c4kq0kgjs64ojxzvsdjz",
},
"user_metadata": "set -o errexit\nset -o nounset\nset -o xtrace\napt-get -y update\nFOO=BAR\necho $FOO",
"z_prop": "z_val",
}
require.Equal(t, expected, found[TResourceType("ibm_compute_vm_instance")][TResourceName("instance-1499827079")])
found, err = parseTerraformShowOutput(
[]TResourceType{TResourceType("ibm_compute_vm_instance")},
[]string{},
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
require.Equal(t, expected, found[TResourceType("ibm_compute_vm_instance")][TResourceName("instance-1499827079")])
// Also verify single instance output
data := convertToSingleInstanceOutput(terraformShowOutput, "ibm_compute_vm_instance.instance-1499827079")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultTagsListWithFilters(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("ibm_compute_vm_instance")},
[]string{"id", "cores", "tags", "foo"},
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": 36147555,
"cores": 1,
"tags": []interface{}{
group.GroupTag + ":workers",
group.ConfigSHATag + ":tubmesopo6lrsfnl5otajlpvwd23v46j",
"name:instance-1499827079",
"infrakit-link-context:swarm::c80s4c4kq0kgjs64ojxzvsdjz::worker",
flavor.ClusterIDTag + ":c80s4c4kq0kgjs64ojxzvsdjz",
},
}
require.Equal(t, expected, found[TResourceType("ibm_compute_vm_instance")][TResourceName("instance-1499827079")])
}
func TestTerraformShowParseResultAwsVpc(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("aws_vpc")},
nil,
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": "vpc-f8d45a90",
"cidr_block": "10.0.0.0/16",
"default_network_acl_id": "acl-9d88fef5",
"default_route_table_id": "rtb-7bf68e13",
"default_security_group_id": "sg-1403ab7f",
"dhcp_options_id": "dopt-b632fedf",
"enable_dns_hostnames": false,
"enable_dns_support": true,
"instance_tenancy": "default",
"main_route_table_id": "rtb-7bf68e13",
"tags": map[string]interface{}{"provisioner": "infrakit-terraform-demo"},
}
require.Equal(t, expected, found[TResourceType("aws_vpc")][TResourceName("default")])
// Also verify single instance output
data := convertToSingleInstanceOutput(terraformShowOutput, "aws_vpc.default")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultAwsSubnet(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("aws_subnet")},
nil,
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
expected := TResourceProperties{
"id": "subnet-32feb75a",
"availability_zone": "eu-central-1a",
"cidr_block": "10.0.1.0/24",
"map_public_ip_on_launch": true,
"tags": map[string]interface{}{"provisioner": "infrakit-terraform-demo"},
"vpc_id": "vpc-f8d45a90",
}
require.Equal(t, expected, found[TResourceType("aws_subnet")][TResourceName("default")])
// Also verify single instance output
data := convertToSingleInstanceOutput(terraformShowOutput, "aws_subnet.default")
props, err := parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
require.Equal(t, expected, props)
}
func TestTerraformShowParseResultAwsSecurityGroup(t *testing.T) {
found, err := parseTerraformShowOutput(
[]TResourceType{TResourceType("aws_security_group")},
nil,
bytes.NewBuffer(terraformShowOutput),
)
require.NoError(t, err)
require.Equal(t, 1, len(found))
props := found[TResourceType("aws_security_group")][TResourceName("default")]
// List sort order for "ingress" is not guananteed, check separately
ingress := props["ingress"].([]interface{})
delete(props, "ingress")
require.Equal(t, 2, len(ingress))
expectedIngress1 := map[string]interface{}{
"cidr_blocks": []interface{}{"10.0.0.0/16"},
"from_port": 80,
"protocol": "tcp",
"security_groups": []interface{}{},
"self": false,
"to_port": 80,
}
expectedIngress2 := map[string]interface{}{
"cidr_blocks": []interface{}{"0.0.0.0/0"},
"from_port": 22,
"protocol": "tcp",
"security_groups": []interface{}{},
"self": false,
"to_port": 22,
}
require.Contains(t, ingress, expectedIngress1)
require.Contains(t, ingress, expectedIngress2)
// Verify everything else
expected := TResourceProperties{
"id": "sg-b903abd2",
"description": "Used in the terraform",
"egress": []interface{}{
map[string]interface{}{
"cidr_blocks": []interface{}{"0.0.0.0/0"},
"from_port": 0,
"prefix_list_ids": []interface{}{},
"protocol": -1,
"security_groups": []interface{}{},
"self": false,
"to_port": 0,
},
},
"name": "terraform_example",
"owner_id": 41673875206,
"tags": map[string]interface{}{
"provisioner": "infrakit-terraform-demo",
},
"vpc_id": "vpc-f8d45a90",
}
require.Equal(t, expected, props)
// Also verify single instance output
data := convertToSingleInstanceOutput(terraformShowOutput, "aws_security_group.default")
props, err = parseTerraformShowForInstanceOutput(bytes.NewBuffer(data))
require.NoError(t, err)
ingress = props["ingress"].([]interface{})
delete(props, "ingress")
require.Equal(t, 2, len(ingress))
require.Contains(t, ingress, expectedIngress1)
require.Contains(t, ingress, expectedIngress2)
require.Equal(t, expected, props)
}
func TestRunTerraformShow(t *testing.T) {
t.Log("Test DISABLED -- TODO(chungers) - this requires some local state. refactor this test or use mocks")
t.SkipNow()
tf, dir := getPlugin(t)
defer os.RemoveAll(dir)
dir = path.Join(dir, "aws-two-tier")
found, err := tf.terraform.doTerraformShow([]TResourceType{TResourceType("aws_vpc")}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(found))
T(100).Infoln(found)
}