Skip to content

Commit

Permalink
allow using dynamic list for ipconfig instead of hardcoding the index…
Browse files Browse the repository at this point in the history
… in the key (Telmate#866)

* allow using dynamic list for ipconfig instead of hardcoding the index in the key

* adding documentation

---------

Co-authored-by: sammy <[email protected]>
  • Loading branch information
spettinichi and sammy committed Mar 12, 2024
1 parent cacddc5 commit 9ad492a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/resources/vm_qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ The `ipconfig` block is used to configure multiple static IP addresses. It may b
| Argument | Type | Default Value | Description |
| `config` | `str` | | IP address to assign to the guest. Format: [gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]. |

### Ipconfig Block

The `ipconfig` block is used to configure multiple static IP addresses. It may be specified multiple times.
| Argument | Type | Default Value | Description |
| `config` | `str` | | IP address to assign to the guest. Format: [gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]. |

### Disk Block
The `disks` block is used to configure the disk devices. It may be specified once. There are four types of disk `ide`,`sata`,`scsi` and `virtio`. Configuration for these sub types can be found in their respective chapters:

Expand Down
27 changes: 27 additions & 0 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,13 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
Ipconfig: qemuIpconfig,
}

<<<<<<< HEAD
config.Disks = mapToStruct_QemuStorages(d)
setIso(d, &config)
setCloudInitDisk(d, &config)

=======
>>>>>>> d02bb5d (allow using dynamic list for ipconfig instead of hardcoding the index in the key (#866))
if len(qemuVgaList) > 0 {
config.QemuVga = qemuVgaList[0].(map[string]interface{})
}
Expand Down Expand Up @@ -1403,6 +1406,20 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
iface := fmt.Sprintf("ipconfig%d", i)
if v, ok := d.GetOk(iface); ok {
qemuIpconfig[i] = v.(string)
<<<<<<< HEAD
=======
}
}
}

d.Partial(true)
if d.HasChange("target_node") {
// check if it must be migrated manually or it has been migrated by the promox high availability system
if vmr.Node() != d.Get("target_node").(string) {
_, err := client.MigrateNode(vmr, d.Get("target_node").(string), true)
if err != nil {
return diag.FromErr(err)
>>>>>>> d02bb5d (allow using dynamic list for ipconfig instead of hardcoding the index in the key (#866))
}
}
}
Expand Down Expand Up @@ -1493,6 +1510,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
"searchdomain",
"nameserver",
"sshkeys",
"ipconfig",
"ipconfig0",
"ipconfig1",
"ipconfig2",
Expand Down Expand Up @@ -1741,6 +1759,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("searchdomain", config.Searchdomain)
d.Set("nameserver", config.Nameserver)
d.Set("sshkeys", config.Sshkeys)
d.Set("ipconfig", config.Ipconfig)
d.Set("ipconfig0", config.Ipconfig[0])
d.Set("ipconfig1", config.Ipconfig[1])
d.Set("ipconfig2", config.Ipconfig[2])
Expand Down Expand Up @@ -2316,9 +2335,17 @@ func initConnInfo(ctx context.Context,
logger.Debug().Int("vmid", vmr.VmId()).Msgf("vmstate error %s", err.Error())
return diag.FromErr(err)
}
<<<<<<< HEAD
if d.Get("ipconfig0").(string) != "ip=dhcp" || vmState["agent"] == nil || vmState["agent"].(float64) != 1 {
// parse IP address out of ipconfig0
ipMatch := rxIPconfig.FindStringSubmatch(d.Get("ipconfig0").(string))
=======

ipConfig := d.Get("ipconfig").(map[int]string)
if ipConfig[0] != "ip=dhcp" || vmState["agent"] == nil || vmState["agent"].(float64) != 1 {
// parse IP address out of ipconfig
ipMatch := rxIPconfig.FindStringSubmatch(ipConfig[0])
>>>>>>> d02bb5d (allow using dynamic list for ipconfig instead of hardcoding the index in the key (#866))
if sshHost == "" {
sshHost = ipMatch[1]
}
Expand Down

0 comments on commit 9ad492a

Please sign in to comment.