@@ -288,30 +288,36 @@ func ensureUniqueFile(dir string) string {
288
288
// Special processing of hostname on some platforms. Where supported, you can
289
289
// add a special @hostname_prefix that will allow the setting of hostname in given format
290
290
// TODO - expand this to formatting string
291
- func (p * plugin ) optionalProcessHostname (vmType TResourceType , name TResourceName , properties TResourceProperties ) {
291
+ func (p * plugin ) optionalProcessHostname (vmType TResourceType , name TResourceName , logicalID * instance. LogicalID , properties TResourceProperties ) {
292
292
293
293
if properties == nil {
294
294
return
295
295
}
296
296
297
297
switch vmType {
298
- case TResourceType ( "softlayer_virtual_guest" ) : // # list the platforms here
298
+ case VMSoftLayer : // # List the supported platforms here
299
299
default :
300
300
return
301
301
}
302
-
302
+ // Use the LogicalID (if set), else the name
303
+ var hostname string
304
+ if logicalID == nil {
305
+ hostname = string (name )
306
+ } else {
307
+ hostname = string (* logicalID )
308
+ }
303
309
// Use the given hostname value as a prefix if it is a non-empty string
304
310
if hostnamePrefix , is := properties ["@hostname_prefix" ].(string ); is {
305
311
hostnamePrefix = strings .Trim (hostnamePrefix , " " )
306
312
// Use the default behavior if hostnamePrefix was either not a string, or an empty string
307
313
if hostnamePrefix == "" {
308
- properties ["hostname" ] = string ( name )
314
+ properties ["hostname" ] = hostname
309
315
} else {
310
316
// Remove "instance-" from "instance-XXXX", then append that string to the hostnamePrefix to create the new hostname
311
- properties ["hostname" ] = fmt .Sprintf ("%s-%s" , hostnamePrefix , strings .Replace (string ( name ) , "instance-" , "" , - 1 ))
317
+ properties ["hostname" ] = fmt .Sprintf ("%s-%s" , hostnamePrefix , strings .Replace (hostname , "instance-" , "" , - 1 ))
312
318
}
313
319
} else {
314
- properties ["hostname" ] = name
320
+ properties ["hostname" ] = hostname
315
321
}
316
322
// Delete hostnamePrefix so it will not be written in the *.tf.json file
317
323
delete (properties , "@hostname_prefix" )
@@ -381,7 +387,8 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
381
387
spec .Tags ["LogicalID" ] = string (* spec .LogicalID )
382
388
}
383
389
384
- p .optionalProcessHostname (vmType , TResourceName (name ), properties )
390
+ // Optionally append either part of the name or the logical ID to the given hostname
391
+ p .optionalProcessHostname (vmType , TResourceName (name ), spec .LogicalID , properties )
385
392
386
393
// Merge any user-defined tags and convert to platform specific tag type
387
394
switch vmType {
0 commit comments