Skip to content

Commit 11eee96

Browse files
sebastian-delbajolet-hashicorp
authored andcommitted
clone: Add dhcp and auto options for ipconfig
DHCP doesn't get enabled automatically when no option is given. Add and document the options to enable DHCP or SLAAC.
1 parent 45abe61 commit 11eee96

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

builder/proxmox/clone/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {
6666
}
6767
}
6868
for _, i := range c.Ipconfigs {
69-
if i.Ip != "" {
69+
if i.Ip != "" && i.Ip != "dhcp" {
7070
_, _, err := net.ParseCIDR(i.Ip)
7171
if err != nil {
7272
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("could not parse ipconfig.ip: %s", err))
@@ -78,7 +78,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {
7878
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("could not parse ipconfig.gateway: %s", err))
7979
}
8080
}
81-
if i.Ip6 != "" {
81+
if i.Ip6 != "" && i.Ip6 != "auto" && i.Ip6 != "dhcp" {
8282
_, _, err := net.ParseCIDR(i.Ip6)
8383
if err != nil {
8484
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("could not parse ipconfig.ip6: %s", err))

builder/proxmox/clone/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,22 @@ func TestIpconfig(t *testing.T) {
237237
},
238238
},
239239
},
240+
{
241+
name: "ipconfig DHCP, no error",
242+
expectFailure: false,
243+
ipconfigs: []cloudInitIpconfig{
244+
{
245+
Ip: "dhcp",
246+
Ip6: "dhcp",
247+
},
248+
},
249+
nics: []proxmox.NICConfig{
250+
{
251+
Model: "virtio",
252+
Bridge: "vmbr0",
253+
},
254+
},
255+
},
240256
}
241257

242258
for _, tt := range ipconfigTest {

docs/builders/clone.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ or responding to pattern `/dev/.+`. Example:
257257
If not given, the same setting as on the host is used.
258258

259259
- `ipconfig` (array of objects) - Set IP address and gateway via Cloud-Init.
260-
If no options are given, DHCP will be used.
261260
If you have configured more than one network interface, make sure to match the order of
262261
`network_adapters` and `ipconfig`.
263262

@@ -274,13 +273,13 @@ or responding to pattern `/dev/.+`. Example:
274273
]
275274
```
276275

277-
- `ip` (string) IPv4 address (CIDR notation).
276+
- `ip` (string) - Either an IPv4 address (CIDR notation) or `dhcp`.
278277

279-
- `gateway` (string) IPv4 gateway.
278+
- `gateway` (string) - IPv4 gateway.
280279

281-
- `ip6` (string) IPv6 address (CIDR notation).
280+
- `ip6` (string) - Can be an IPv6 address (CIDR notation), `auto` (enables SLAAC), or `dhcp`.
282281

283-
- `gateway6` (string) IPv6 gateway.
282+
- `gateway6` (string) - IPv6 gateway.
284283

285284
- `additional_iso_files` (array of objects) - Additional ISO files attached to the virtual machine.
286285
Example:

0 commit comments

Comments
 (0)