@@ -189,7 +189,7 @@ func (p *plugin) terraformApply() error {
189
189
}
190
190
191
191
func (p * plugin ) doTerraformApply () error {
192
- log .Infoln (" Applying plan" )
192
+ log .Infoln (time . Now (). Format ( time . RFC850 ) + " Applying plan" )
193
193
cmd := exec .Command ("terraform" , "apply" )
194
194
cmd .Dir = p .Dir
195
195
stdout , err := cmd .StdoutPipe ()
@@ -352,6 +352,7 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
352
352
spec .Tags ["Name" ] = string (id )
353
353
}
354
354
}
355
+
355
356
switch properties .Type {
356
357
case "aws_instance" , "azurerm_virtual_machine" , "digitalocean_droplet" , "google_compute_instance" :
357
358
if t , exists := properties .Value ["tags" ]; ! exists {
@@ -362,6 +363,17 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
362
363
mm [tt ] = vv
363
364
}
364
365
}
366
+ case "softlayer_virtual_guest" :
367
+ log .Debugln ("softlayer_virtual_guest detected, adding hostname to properties: hostname=" , name )
368
+ properties .Value ["hostname" ] = name
369
+ var tags []interface {}
370
+
371
+ //softlayer uses a list of tags, instead of a map of tags
372
+ for i , v := range spec .Tags {
373
+ log .Debugln ("softlayer_virtual_guest detected, append system tag v=" , v )
374
+ tags = append (tags , i + ":" + v )
375
+ }
376
+ properties .Value ["tags" ] = tags
365
377
}
366
378
367
379
// Use tag to store the logical id
@@ -375,6 +387,8 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
375
387
switch properties .Type {
376
388
case "aws_instance" , "digitalocean_droplet" :
377
389
addUserData (properties .Value , "user_data" , spec .Init )
390
+ case "softlayer_virtual_guest" :
391
+ addUserData (properties .Value , "user_metadata" , spec .Init )
378
392
case "azurerm_virtual_machine" :
379
393
// os_profile.custom_data
380
394
if m , has := properties .Value ["os_profile" ]; ! has {
@@ -414,7 +428,7 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
414
428
// Destroy terminates an existing instance.
415
429
func (p * plugin ) Destroy (instance instance.ID ) error {
416
430
fp := filepath .Join (p .Dir , string (instance )+ ".tf.json" )
417
- log .Debugln ("destroy" , fp )
431
+ log .Debugln ("destroy instance " , fp )
418
432
err := p .fs .Remove (fp )
419
433
if err != nil {
420
434
return err
@@ -445,6 +459,7 @@ scan:
445
459
ID : instance .ID (id ),
446
460
LogicalID : terraformLogicalID (v ),
447
461
}
462
+
448
463
if len (tags ) == 0 {
449
464
result = append (result , inst )
450
465
} else {
@@ -457,12 +472,16 @@ scan:
457
472
}
458
473
}
459
474
}
475
+ log .Debugln ("describe-instances result=" , result )
476
+
460
477
return result , nil
461
478
}
462
479
463
480
func terraformTags (v interface {}, key string ) map [string ]string {
481
+ log .Debugln ("terraformTags" , v )
464
482
m , ok := v .(map [string ]interface {})
465
483
if ! ok {
484
+ log .Debugln ("terraformTags: return nil" )
466
485
return nil
467
486
}
468
487
tags := map [string ]string {}
@@ -471,7 +490,28 @@ func terraformTags(v interface{}, key string) map[string]string {
471
490
tags [k ] = fmt .Sprintf ("%v" , v )
472
491
}
473
492
return tags
493
+ } else if mm , ok := m [key ].([]interface {}); ok {
494
+ // add each tag in the list to the tags map
495
+ for _ , v := range mm {
496
+ value := fmt .Sprintf ("%v" , v )
497
+ if strings .Contains (value , ":" ) {
498
+ log .Debugln ("terraformTags system tags detected v=" , v )
499
+ vv := strings .Split (value , ":" )
500
+ if len (vv ) == 2 {
501
+ tags [vv [0 ]] = vv [1 ]
502
+ } else {
503
+ log .Errorln ("terraformTags: ignore invalid tag detected" , value )
504
+ }
505
+ } else {
506
+ log .Warnln ("terraformTags user tags ignored v=" , value )
507
+ }
508
+ }
509
+ log .Debugln ("terraformTags return tags" , tags )
510
+ return tags
511
+ } else {
512
+ log .Errorln ("terraformTags: invalid terraformTags tags value" , m [key ])
474
513
}
514
+
475
515
for k , v := range m {
476
516
if k != "tags.%" && strings .Index (k , "tags." ) == 0 {
477
517
n := k [len ("tags." ):]
0 commit comments