@@ -16,11 +16,17 @@ import (
1616 "github.com/hashicorp/packer-plugin-sdk/template/interpolate"
1717)
1818
19+ type InterfaceType string
20+
1921const (
20- DefaultTemplatePrefix = "custom-image"
21- DefaultSSHUsername = "root"
22- DefaultStorageSize = 25
23- DefaultTimeout = 5 * time .Minute
22+ DefaultTemplatePrefix = "custom-image"
23+ DefaultSSHUsername = "root"
24+ DefaultCommunicator = "ssh"
25+ DefaultStorageSize = 25
26+ DefaultTimeout = 5 * time .Minute
27+ InterfaceTypePublic InterfaceType = upcloud .IPAddressAccessPublic
28+ InterfaceTypeUtility InterfaceType = upcloud .IPAddressAccessUtility
29+ InterfaceTypePrivate InterfaceType = upcloud .IPAddressAccessPrivate
2430)
2531
2632var (
@@ -38,13 +44,24 @@ var (
3844
3945// for config type convertion
4046type NetworkInterface struct {
47+ // List of IP Addresses
4148 IPAddresses []IPAddress `mapstructure:"ip_addresses"`
42- Type string `mapstructure:"type"`
43- Network string `mapstructure:"network,omitempty"`
49+
50+ // Network type (e.g. public, utility, private)
51+ Type InterfaceType `mapstructure:"type"`
52+
53+ // Network UUID when connecting private network
54+ Network string `mapstructure:"network,omitempty"`
4455}
4556
4657type IPAddress struct {
47- Family string `mapstructure:"family"`
58+ // Default IP address. When set to `true` SSH communicator will connect to this IP after boot.
59+ Default bool `mapstructure:"default"`
60+
61+ // IP address family (IPv4 or IPv6)
62+ Family string `mapstructure:"family"`
63+
64+ // IP address. Note that at the moment using floating IPs is not supported.
4865 Address string `mapstructure:"address,omitempty"`
4966}
5067
@@ -89,6 +106,9 @@ type Config struct {
89106 // The amount of time to wait for resource state changes. Defaults to `5m`.
90107 Timeout time.Duration `mapstructure:"state_timeout_duration"`
91108
109+ // The amount of time to wait after booting the server. Defaults to '0s'
110+ BootWait time.Duration `mapstructure:"boot_wait"`
111+
92112 // The array of extra zones (locations) where created templates should be cloned.
93113 // Note that default `state_timeout_duration` is not enough for cloning, better to increase a value depending on storage size.
94114 CloneZones []string `mapstructure:"clone_zones"`
@@ -105,6 +125,18 @@ type Config struct {
105125 ctx interpolate.Context
106126}
107127
128+ // DefaultIPaddress returns default IP address and its type (public,private,utility)
129+ func (c * Config ) DefaultIPaddress () (* IPAddress , InterfaceType ) {
130+ for _ , iface := range c .NetworkInterfaces {
131+ for _ , addr := range iface .IPAddresses {
132+ if addr .Default {
133+ return & addr , iface .Type
134+ }
135+ }
136+ }
137+ return nil , ""
138+ }
139+
108140func (c * Config ) Prepare (raws ... interface {}) ([]string , error ) {
109141 err := config .Decode (c , & config.DecodeOpts {
110142 Interpolate : true ,
@@ -130,7 +162,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
130162 c .Timeout = DefaultTimeout
131163 }
132164
133- if c .Comm .SSHUsername == "" {
165+ if c .Comm .Type == "" {
166+ c .Comm .Type = DefaultCommunicator
167+ }
168+
169+ if c .Comm .Type == "ssh" && c .Comm .SSHUsername == "" {
134170 c .Comm .SSHUsername = DefaultSSHUsername
135171 }
136172
0 commit comments