Skip to content

Commit 260af32

Browse files
nicosinghadammck
authored andcommitted
add AWS spot instances (#97)
1 parent 669d8a7 commit 260af32

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

parser_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,18 @@ const exampleStateFile = `
395395
"primary_ip": "10.0.0.16"
396396
}
397397
}
398+
},
399+
"aws_spot_instance_request.seventeen": {
400+
"type": "aws_spot_instance_request",
401+
"primary": {
402+
"id": "i-a1a1a1a1",
403+
"attributes": {
404+
"id": "sir-a1a1a1a1",
405+
"public_ip": "50.0.0.17",
406+
"tags.%": "1",
407+
"tags.Role": "worker"
408+
}
409+
}
398410
}
399411
}
400412
}
@@ -421,6 +433,7 @@ const expectedListOutput = `
421433
"192.168.0.3",
422434
"192.168.102.14",
423435
"50.0.0.1",
436+
"50.0.0.17",
424437
"10.20.30.50"
425438
],
426439
"vars": {
@@ -447,6 +460,7 @@ const expectedListOutput = `
447460
"thirteen": ["10.0.0.13"],
448461
"fourteen": ["192.168.102.14"],
449462
"sixteen": ["10.0.0.16"],
463+
"seventeen": ["50.0.0.17"],
450464
451465
"one.0": ["10.0.0.1"],
452466
"dup.0": ["10.0.0.1"],
@@ -465,6 +479,7 @@ const expectedListOutput = `
465479
"thirteen.0": ["10.0.0.13"],
466480
"fourteen.0": ["192.168.102.14"],
467481
"sixteen.0": ["10.0.0.16"],
482+
"seventeen.0": ["50.0.0.17"],
468483
469484
"type_aws_instance": ["10.0.0.1", "10.0.1.1", "50.0.0.1"],
470485
"type_digitalocean_droplet": ["192.168.0.3"],
@@ -479,10 +494,12 @@ const expectedListOutput = `
479494
"type_scaleway_server": ["10.0.0.11"],
480495
"type_packet_device": ["10.0.0.13"],
481496
"type_libvirt_domain": ["192.168.102.14"],
497+
"type_aws_spot_instance_request": ["50.0.0.17"],
482498
483499
"role_rrrrrrrr": ["10.20.30.40"],
484500
"role_web": ["10.0.0.1"],
485501
"role_test": ["10.0.0.10"],
502+
"role_worker": ["50.0.0.17"],
486503
"webserver": ["192.168.0.3"],
487504
"staging": ["192.168.0.3"],
488505
"status_superserver": ["10.120.0.226"],
@@ -507,6 +524,7 @@ const expectedInventoryOutput = `[all]
507524
192.168.0.3
508525
192.168.102.14
509526
50.0.0.1
527+
50.0.0.17
510528
10.20.30.50
511529
512530
[all:vars]
@@ -579,6 +597,9 @@ olddatacenter="\u003c0.7_format"
579597
[role_web]
580598
10.0.0.1
581599
600+
[role_worker]
601+
50.0.0.17
602+
582603
[scw_test]
583604
10.0.0.11
584605
@@ -588,6 +609,12 @@ olddatacenter="\u003c0.7_format"
588609
[seven.0]
589610
10.0.0.7
590611
612+
[seventeen]
613+
50.0.0.17
614+
615+
[seventeen.0]
616+
50.0.0.17
617+
591618
[six]
592619
10.120.0.226
593620
@@ -644,6 +671,9 @@ olddatacenter="\u003c0.7_format"
644671
10.0.1.1
645672
50.0.0.1
646673
674+
[type_aws_spot_instance_request]
675+
50.0.0.17
676+
647677
[type_cloudstack_instance]
648678
10.2.1.5
649679

resource.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ func (r Resource) Tags() map[string]string {
123123
t[kk] = vv
124124
}
125125
}
126+
case "aws_spot_instance_request":
127+
for k, v := range r.Attributes() {
128+
parts := strings.SplitN(k, ".", 2)
129+
// At some point Terraform changed the key for counts of attributes to end with ".%"
130+
// instead of ".#". Both need to be considered as Terraform still supports state
131+
// files using the old format.
132+
if len(parts) == 2 && parts[0] == "tags" && parts[1] != "#" && parts[1] != "%" {
133+
kk := strings.ToLower(parts[1])
134+
vv := strings.ToLower(v)
135+
t[kk] = vv
136+
}
137+
}
126138
case "vsphere_virtual_machine":
127139
for k, v := range r.Attributes() {
128140
parts := strings.SplitN(k, ".", 2)

0 commit comments

Comments
 (0)