@@ -332,6 +332,34 @@ func ensureUniqueFile(dir string) string {
332
332
return n
333
333
}
334
334
335
+ // Special processing of hostname on some platforms. Where supported, you can
336
+ // add a special @hostname_prefix that will allow the setting of hostname in given format
337
+ // TODO - expand this to formatting string
338
+ func (p * plugin ) optionalProcessHostname (properties * SpecPropertiesFormat , name string ) {
339
+ switch properties .Type {
340
+ case "softlayer_virtual_guest" : // # list the platforms here
341
+ default :
342
+ return
343
+ }
344
+
345
+ // Use the given hostname value as a prefix if it is a non-empty string
346
+ if hostnamePrefix , is := properties .Value ["@hostname_prefix" ].(string ); is {
347
+ hostnamePrefix = strings .Trim (hostnamePrefix , " " )
348
+ // Use the default behavior if hostnamePrefix was either not a string, or an empty string
349
+ if hostnamePrefix == "" {
350
+ properties .Value ["hostname" ] = name
351
+ } else {
352
+ // Remove "instance-" from "instance-XXXX", then append that string to the hostnamePrefix to create the new hostname
353
+ properties .Value ["hostname" ] = fmt .Sprintf ("%s-%s" , hostnamePrefix , strings .Replace (name , "instance-" , "" , - 1 ))
354
+ }
355
+ } else {
356
+ properties .Value ["hostname" ] = name
357
+ }
358
+ // Delete hostnamePrefix so it will not be written in the *.tf.json file
359
+ delete (properties .Value , "@hostname_prefix" )
360
+ log .Debugln ("Adding hostname to properties: hostname=" , properties .Value ["hostname" ])
361
+ }
362
+
335
363
// Provision creates a new instance based on the spec.
336
364
func (p * plugin ) Provision (spec instance.Spec ) (* instance.ID , error ) {
337
365
// Simply writes a file and call terraform apply
@@ -359,22 +387,7 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
359
387
}
360
388
}
361
389
362
- // Use the given hostname value as a prefix if it is a non-empty string
363
- if hostnamePrefix , is := properties .Value ["@hostname_prefix" ].(string ); is {
364
- hostnamePrefix = strings .Trim (hostnamePrefix , " " )
365
- // Use the default behavior if hostnamePrefix was either not a string, or an empty string
366
- if hostnamePrefix == "" {
367
- properties .Value ["hostname" ] = name
368
- } else {
369
- // Remove "instance-" from "instance-XXXX", then append that string to the hostnamePrefix to create the new hostname
370
- properties .Value ["hostname" ] = fmt .Sprintf ("%s-%s" , hostnamePrefix , strings .Replace (name , "instance-" , "" , - 1 ))
371
- }
372
- } else {
373
- properties .Value ["hostname" ] = name
374
- }
375
- // Delete hostnamePrefix so it will not be written in the *.tf.json file
376
- delete (properties .Value , "@hostname_prefix" )
377
- log .Debugln ("Adding hostname to properties: hostname=" , properties .Value ["hostname" ])
390
+ p .optionalProcessHostname (& properties , name )
378
391
379
392
switch properties .Type {
380
393
case "aws_instance" , "azurerm_virtual_machine" , "digitalocean_droplet" , "google_compute_instance" :
0 commit comments