Add instance_display_name parameter for Cloudstack builder

This change introduce instance_display_name optional parameter
for Cloudstack builder to set custom VM display name.
By default it is set to "Created by Packer".
This commit is contained in:
Michael Bochkaryov 2019-10-26 21:13:45 -07:00
parent 0cb098b713
commit da7e72246c
4 changed files with 11 additions and 1 deletions

View File

@ -78,6 +78,8 @@ type Config struct {
// The name of the instance. Defaults to // The name of the instance. Defaults to
// "packer-UUID" where UUID is dynamically generated. // "packer-UUID" where UUID is dynamically generated.
InstanceName string `mapstructure:"instance_name" required:"false"` InstanceName string `mapstructure:"instance_name" required:"false"`
// The display name of the instance. Defaults to "Created by Packer".
InstanceDisplayName string `mapstructure:"instance_display_name" required:"false"`
// The name or ID of the network to connect the instance // The name or ID of the network to connect the instance
// to. // to.
Network string `mapstructure:"network" required:"true"` Network string `mapstructure:"network" required:"true"`
@ -210,6 +212,10 @@ func NewConfig(raws ...interface{}) (*Config, error) {
c.InstanceName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID()) c.InstanceName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
} }
if c.InstanceDisplayName == "" {
c.InstanceDisplayName = "Created by Packer"
}
if c.TemplateName == "" { if c.TemplateName == "" {
name, err := interpolate.Render("packer-{{timestamp}}", nil) name, err := interpolate.Render("packer-{{timestamp}}", nil)
if err != nil { if err != nil {

View File

@ -74,6 +74,7 @@ type FlatConfig struct {
Expunge *bool `mapstructure:"expunge" required:"false" cty:"expunge"` Expunge *bool `mapstructure:"expunge" required:"false" cty:"expunge"`
Hypervisor *string `mapstructure:"hypervisor" required:"false" cty:"hypervisor"` Hypervisor *string `mapstructure:"hypervisor" required:"false" cty:"hypervisor"`
InstanceName *string `mapstructure:"instance_name" required:"false" cty:"instance_name"` InstanceName *string `mapstructure:"instance_name" required:"false" cty:"instance_name"`
InstanceDisplayName *string `mapstructure:"instance_display_name" required:"false" cty:"instance_display_name"`
Network *string `mapstructure:"network" required:"true" cty:"network"` Network *string `mapstructure:"network" required:"true" cty:"network"`
Project *string `mapstructure:"project" required:"false" cty:"project"` Project *string `mapstructure:"project" required:"false" cty:"project"`
PublicIPAddress *string `mapstructure:"public_ip_address" required:"false" cty:"public_ip_address"` PublicIPAddress *string `mapstructure:"public_ip_address" required:"false" cty:"public_ip_address"`
@ -174,6 +175,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"expunge": &hcldec.AttrSpec{Name: "expunge", Type: cty.Bool, Required: false}, "expunge": &hcldec.AttrSpec{Name: "expunge", Type: cty.Bool, Required: false},
"hypervisor": &hcldec.AttrSpec{Name: "hypervisor", Type: cty.String, Required: false}, "hypervisor": &hcldec.AttrSpec{Name: "hypervisor", Type: cty.String, Required: false},
"instance_name": &hcldec.AttrSpec{Name: "instance_name", Type: cty.String, Required: false}, "instance_name": &hcldec.AttrSpec{Name: "instance_name", Type: cty.String, Required: false},
"instance_display_name": &hcldec.AttrSpec{Name: "instance_display_name", Type: cty.String, Required: false},
"network": &hcldec.AttrSpec{Name: "network", Type: cty.String, Required: false}, "network": &hcldec.AttrSpec{Name: "network", Type: cty.String, Required: false},
"project": &hcldec.AttrSpec{Name: "project", Type: cty.String, Required: false}, "project": &hcldec.AttrSpec{Name: "project", Type: cty.String, Required: false},
"public_ip_address": &hcldec.AttrSpec{Name: "public_ip_address", Type: cty.String, Required: false}, "public_ip_address": &hcldec.AttrSpec{Name: "public_ip_address", Type: cty.String, Required: false},

View File

@ -44,7 +44,7 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
// Configure the instance. // Configure the instance.
p.SetName(config.InstanceName) p.SetName(config.InstanceName)
p.SetDisplayname("Created by Packer") p.SetDisplayname(config.InstanceDisplayName)
if len(config.Comm.SSHKeyPairName) != 0 { if len(config.Comm.SSHKeyPairName) != 0 {
ui.Message(fmt.Sprintf("Using keypair: %s", config.Comm.SSHKeyPairName)) ui.Message(fmt.Sprintf("Using keypair: %s", config.Comm.SSHKeyPairName))

View File

@ -45,6 +45,8 @@
- `instance_name` (string) - The name of the instance. Defaults to - `instance_name` (string) - The name of the instance. Defaults to
"packer-UUID" where UUID is dynamically generated. "packer-UUID" where UUID is dynamically generated.
- `instance_display_name` (string) - The display name of the instance. Defaults to "Created by Packer".
- `project` (string) - The name or ID of the project to deploy the instance - `project` (string) - The name or ID of the project to deploy the instance
to. to.