@@ -288,30 +288,36 @@ func ensureUniqueFile(dir string) string {
288288// Special processing of hostname on some platforms. Where supported, you can
289289// add a special @hostname_prefix that will allow the setting of hostname in given format
290290// 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 ) {
292292
293293 if properties == nil {
294294 return
295295 }
296296
297297 switch vmType {
298- case TResourceType ( "softlayer_virtual_guest" ) : // # list the platforms here
298+ case VMSoftLayer : // # List the supported platforms here
299299 default :
300300 return
301301 }
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+ }
303309 // Use the given hostname value as a prefix if it is a non-empty string
304310 if hostnamePrefix , is := properties ["@hostname_prefix" ].(string ); is {
305311 hostnamePrefix = strings .Trim (hostnamePrefix , " " )
306312 // Use the default behavior if hostnamePrefix was either not a string, or an empty string
307313 if hostnamePrefix == "" {
308- properties ["hostname" ] = string ( name )
314+ properties ["hostname" ] = hostname
309315 } else {
310316 // 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 ))
312318 }
313319 } else {
314- properties ["hostname" ] = name
320+ properties ["hostname" ] = hostname
315321 }
316322 // Delete hostnamePrefix so it will not be written in the *.tf.json file
317323 delete (properties , "@hostname_prefix" )
@@ -381,7 +387,8 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
381387 spec .Tags ["LogicalID" ] = string (* spec .LogicalID )
382388 }
383389
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 )
385392
386393 // Merge any user-defined tags and convert to platform specific tag type
387394 switch vmType {
0 commit comments