@@ -362,25 +362,28 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
362
362
return nil , fmt .Errorf ("no-vm-instance-in-spec" )
363
363
}
364
364
365
- // set the tags.
366
- // add a name
365
+ // Add the name to the tags if it does not exist, issue case-insensitive
366
+ // check for the " name" key
367
367
if spec .Tags != nil {
368
- switch vmType {
369
- case VMSoftLayer :
370
- // Set the "name" tag to be lowercase to meet platform requirements
371
- if _ , has := spec .Tags ["name" ]; ! has {
372
- spec .Tags ["name" ] = string (id )
373
- }
374
- default :
375
- // Set the first character of the "Name" tag to be uppercase to meet platform requirements
376
- if _ , has := spec .Tags ["Name" ]; ! has {
377
- spec .Tags ["Name" ] = string (id )
368
+ match := false
369
+ for key := range spec .Tags {
370
+ if strings .ToLower (key ) == "name" {
371
+ match = true
372
+ break
378
373
}
379
374
}
375
+ if ! match {
376
+ spec .Tags ["Name" ] = string (id )
377
+ }
378
+ }
379
+ // Use tag to store the logical id
380
+ if spec .LogicalID != nil {
381
+ spec .Tags ["LogicalID" ] = string (* spec .LogicalID )
380
382
}
381
383
382
384
p .optionalProcessHostname (vmType , TResourceName (name ), properties )
383
385
386
+ // Merge any user-defined tags and convert to platform specific tag type
384
387
switch vmType {
385
388
case VMAmazon , VMAzure , VMDigitalOcean , VMGoogleCloud :
386
389
if t , exists := properties ["tags" ]; ! exists {
@@ -402,12 +405,6 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
402
405
}
403
406
}
404
407
405
- // Use tag to store the logical id
406
- if spec .LogicalID != nil {
407
- if m , ok := properties ["tags" ].(map [string ]interface {}); ok {
408
- m ["LogicalID" ] = string (* spec .LogicalID )
409
- }
410
- }
411
408
switch vmType {
412
409
case VMAmazon :
413
410
if p , exists := properties ["private_ip" ]; exists {
@@ -444,6 +441,16 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
444
441
addUserData (properties , "metadata_startup_script" , spec .Init )
445
442
}
446
443
444
+ // On Softlayer the tags must be lowercase
445
+ switch vmType {
446
+ case VMSoftLayer :
447
+ tagsLower := []string {}
448
+ for _ , val := range properties ["tags" ].([]string ) {
449
+ tagsLower = append (tagsLower , strings .ToLower (val ))
450
+ }
451
+ properties ["tags" ] = tagsLower
452
+ }
453
+
447
454
// Write out each resource again with the instance name
448
455
for resourceType , resourceObj := range tf .Resource {
449
456
vmList := mapset .NewSetFromSlice (VMTypes )
@@ -656,19 +663,29 @@ func terraformTags(m TResourceProperties, key string) map[string]string {
656
663
}
657
664
return tags
658
665
}
659
- func terraformLogicalID (v interface {}) * instance.LogicalID {
660
- m , ok := v .(map [string ]interface {})
661
- if ! ok {
662
- return nil
663
- }
664
- tags , ok := m ["tags" ].(map [string ]interface {})
665
- if ! ok {
666
- return nil
667
- }
668
- v , exists := tags ["LogicalID" ]
669
- if exists {
670
- id := instance .LogicalID (fmt .Sprintf ("%v" , v ))
671
- return & id
666
+
667
+ // terraformLogicalID parses the LogicalID (case insensitive key check) from
668
+ // either the map of tags or the list of tags
669
+ func terraformLogicalID (props TResourceProperties ) * instance.LogicalID {
670
+ if propsTag , ok := props ["tags" ]; ok {
671
+ if tagsMap , ok := propsTag .(map [string ]interface {}); ok {
672
+ for key , val := range tagsMap {
673
+ if strings .ToLower (key ) == "logicalid" {
674
+ id := instance .LogicalID (fmt .Sprintf ("%v" , val ))
675
+ return & id
676
+ }
677
+ }
678
+ } else if tagsList , ok := propsTag .([]interface {}); ok {
679
+ for _ , tag := range tagsList {
680
+ if tagString , ok := tag .(string ); ok {
681
+ if strings .HasPrefix (strings .ToLower (tagString ), "logicalid:" ) {
682
+ logicalID := strings .SplitN (strings .ToLower (tagString ), ":" , 2 )[1 ]
683
+ id := instance .LogicalID (fmt .Sprintf ("%v" , logicalID ))
684
+ return & id
685
+ }
686
+ }
687
+ }
688
+ }
672
689
}
673
690
return nil
674
691
}
0 commit comments