diff --git a/builder/cloudstack/config.go b/builder/cloudstack/config.go index 3d15d27a2..98292ccfd 100644 --- a/builder/cloudstack/config.go +++ b/builder/cloudstack/config.go @@ -38,6 +38,7 @@ type Config struct { Network string `mapstructure:"network"` Project string `mapstructure:"project"` PublicIPAddress string `mapstructure:"public_ip_address"` + PublicSSHPort int `mapstructure:"public_ssh_port"` SecurityGroups []string `mapstructure:"security_groups"` ServiceOffering string `mapstructure:"service_offering"` PreventFirewallChanges bool `mapstructure:"prevent_firewall_changes"` diff --git a/builder/cloudstack/step_configure_networking.go b/builder/cloudstack/step_configure_networking.go index 577b4b1f2..8b628b0ff 100644 --- a/builder/cloudstack/step_configure_networking.go +++ b/builder/cloudstack/step_configure_networking.go @@ -31,9 +31,13 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m return multistep.ActionContinue } - // Generate a random public port used to configure our port forward. - rand.Seed(time.Now().UnixNano()) - s.publicPort = 50000 + rand.Intn(10000) + if config.PublicSSHPort != 0 { + s.publicPort = config.PublicSSHPort + } else { + // Generate a random public port used to configure our port forward. + rand.Seed(time.Now().UnixNano()) + s.publicPort = 50000 + rand.Intn(10000) + } state.Put("commPort", s.publicPort) // Set the currently configured port to be the private port. diff --git a/website/source/docs/builders/cloudstack.html.md b/website/source/docs/builders/cloudstack.html.md index 22b9f91d1..3de58d85f 100644 --- a/website/source/docs/builders/cloudstack.html.md +++ b/website/source/docs/builders/cloudstack.html.md @@ -126,6 +126,10 @@ builder. connecting any provisioners to. If not provided, a temporary public IP address will be associated and released during the Packer run. +- `public_ssh_port` (number) - The fixed port you want to configure in the port + forwarding rule. Set this attribute if you do not want to use the a random + public port. + - `security_groups` (array of strings) - A list of security group IDs or names to associate the instance with.