diff --git a/docs/resources/cloud_init_disk.md b/docs/resources/cloud_init_disk.md index 5cca6e1b..bab7febf 100644 --- a/docs/resources/cloud_init_disk.md +++ b/docs/resources/cloud_init_disk.md @@ -1,7 +1,7 @@ This documentation is about how to manually create a cloud-init CD-ROM image. This is only for unusual situations where the standard cloud-init support is not enough. For a simple cloud-init example, see -[examples/cloudinit_example.tf](../examples/cloudinit_example.tf). +[examples/cloudinit_example.tf](../../examples/cloudinit_example.tf). # Cloud Init Disk Resource diff --git a/docs/resources/vm_qemu.md b/docs/resources/vm_qemu.md index 0ea303ee..0ed8c524 100644 --- a/docs/resources/vm_qemu.md +++ b/docs/resources/vm_qemu.md @@ -88,58 +88,58 @@ The primary options that effect the correct operation of Network PXE boot mode a The following arguments are supported in the top level resource block. -| Argument | Type | Default Value | Description | -| ----------------------------- | -------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `name` | `str` | | **Required** The name of the VM within Proxmox. | -| `target_node` | `str` | | **Required** The name of the Proxmox Node on which to place the VM. | -| `vmid` | `int` | `0` | The ID of the VM in Proxmox. The default value of `0` indicates it should use the next available ID in the sequence. | -| `desc` | `str` | | The description of the VM. Shows as the 'Notes' field in the Proxmox GUI. | -| `define_connection_info` | `bool` | `true` | Whether to let terraform define the (SSH) connection parameters for preprovisioners, see config block below. | -| `bios` | `str` | `"seabios"` | The BIOS to use, options are `seabios` or `ovmf` for UEFI. | -| `onboot` | `bool` | `false` | Whether to have the VM startup after the PVE node starts. | -| `startup` | `string` | `""` | The [startup and shutdown behaviour](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pct_startup_and_shutdown) | -| `vm_state` | `string` | `"running"` | The desired state of the VM, options are `running`, `stopped` and `started`. Do note that `started` will only start the vm on creation and won't fully manage the power state unlike `running` and `stopped` do. | -| `oncreate` | `bool` | `true` | Whether to have the VM startup after the VM is created (deprecated, use `vm_state` instead) | -| `protection` | `bool` | `false` | Enable/disable the VM protection from being removed. The default value of `false` indicates the VM is removable. | -| `tablet` | `bool` | `true` | Enable/disable the USB tablet device. This device is usually needed to allow absolute mouse positioning with VNC. | -| `boot` | `str` | | The boot order for the VM. For example: `order=scsi0;ide2;net0`. The deprecated `legacy=` syntax is no longer supported. See the `boot` option in the [Proxmox manual](https://pve.proxmox.com/wiki/Manual:_qm.conf#_options) for more information. | -| `bootdisk` | `str` | | Enable booting from specified disk. You shouldn't need to change it under most circumstances. | -| `agent` | `int` | `0` | Set to `1` to enable the QEMU Guest Agent. Note, you must run the [`qemu-guest-agent`](https://pve.proxmox.com/wiki/Qemu-guest-agent) daemon in the guest for this to have any effect. | -| `pxe` | `bool` | `false` | If set to `true`, enable PXE boot of the VM. Also requires a `boot` order be set with Network included (eg `boot = "order=scsi0;net0"`). Note that `pxe` is mutually exclusive with `clone` modes. | -| `clone` | `str` | | The base VM from which to clone to create the new VM. Note that `clone` is mutually exclussive with `pxe` modes. | -| `full_clone` | `bool` | `true` | Set to `true` to create a full clone, or `false` to create a linked clone. See the [docs about cloning](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_copy_and_clone) for more info. Only applies when `clone` is set. | -| `hastate` | `str` | | Requested HA state for the resource. One of "started", "stopped", "enabled", "disabled", or "ignored". See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. | -| `hagroup` | `str` | | The HA group identifier the resource belongs to (requires `hastate` to be set!). See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. | -| `qemu_os` | `str` | `"l26"` | The type of OS in the guest. Set properly to allow Proxmox to enable optimizations for the appropriate guest OS. It takes the value from the source template and ignore any changes to resource configuration parameter. | -| `memory` | `int` | `512` | The amount of memory to allocate to the VM in Megabytes. | -| `balloon` | `int` | `0` | The minimum amount of memory to allocate to the VM in Megabytes, when Automatic Memory Allocation is desired. Proxmox will enable a balloon device on the guest to manage dynamic allocation. See the [docs about memory](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_memory) for more info. | -| `sockets` | `int` | `1` | The number of CPU sockets to allocate to the VM. | -| `cores` | `int` | `1` | The number of CPU cores per CPU socket to allocate to the VM. | -| `vcpus` | `int` | `0` | The number of vCPUs plugged into the VM when it starts. If `0`, this is set automatically by Proxmox to `sockets * cores`. | -| `cpu` | `str` | `"host"` | The type of CPU to emulate in the Guest. See the [docs about CPU Types](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_cpu) for more info. | -| `numa` | `bool` | `false` | Whether to enable [Non-Uniform Memory Access](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_cpu) in the guest. | -| `hotplug` | `str` | `"network,disk,usb"` | Comma delimited list of hotplug features to enable. Options: `network`, `disk`, `cpu`, `memory`, `usb`. Set to `0` to disable hotplug. | -| `scsihw` | `str` | `"lsi"` | The SCSI controller to emulate. Options: `lsi`, `lsi53c810`, `megasas`, `pvscsi`, `virtio-scsi-pci`, `virtio-scsi-single`. | -| `pool` | `str` | | The resource pool to which the VM will be added. | -| `tags` | `str` | | Tags of the VM. This is only meta information. | -| `force_create` | `bool` | `false` | If `false`, and a vm of the same name, on the same node exists, terraform will attempt to reconfigure that VM with these settings. Set to true to always create a new VM (note, the name of the VM must still be unique, otherwise an error will be produced.) | -| `os_type` | `str` | | Which provisioning method to use, based on the OS type. Options: `ubuntu`, `centos`, `cloud-init`. | -| `force_recreate_on_change_of` | `str` | | If the value of this string changes, the VM will be recreated. Useful for allowing this resource to be recreated when arbitrary attributes change. An example where this is useful is a cloudinit configuration (as the `cicustom` attribute points to a file not the content). | +| Argument | Type | Default Value | Description | +| ----------------------------- | -------- | -------------------- | ----------- | +| `name` | `str` | | **Required** The name of the VM within Proxmox. | +| `target_node` | `str` | | **Required** The name of the Proxmox Node on which to place the VM. | +| `vmid` | `int` | `0` | The ID of the VM in Proxmox. The default value of `0` indicates it should use the next available ID in the sequence. | +| `desc` | `str` | | The description of the VM. Shows as the 'Notes' field in the Proxmox GUI. | +| `define_connection_info` | `bool` | `true` | Whether to let terraform define the (SSH) connection parameters for preprovisioners, see config block below. | +| `bios` | `str` | `"seabios"` | The BIOS to use, options are `seabios` or `ovmf` for UEFI. | +| `onboot` | `bool` | `false` | Whether to have the VM startup after the PVE node starts. | +| `startup` | `string` | `""` | The [startup and shutdown behaviour](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pct_startup_and_shutdown) | +| `vm_state` | `string` | `"running"` | The desired state of the VM, options are `running`, `stopped` and `started`. Do note that `started` will only start the vm on creation and won't fully manage the power state unlike `running` and `stopped` do. | +| `oncreate` | `bool` | `true` | Whether to have the VM startup after the VM is created (deprecated, use `vm_state` instead) | +| `protection` | `bool` | `false` | Enable/disable the VM protection from being removed. The default value of `false` indicates the VM is removable. | +| `tablet` | `bool` | `true` | Enable/disable the USB tablet device. This device is usually needed to allow absolute mouse positioning with VNC. | +| `boot` | `str` | | The boot order for the VM. For example: `order=scsi0;ide2;net0`. The deprecated `legacy=` syntax is no longer supported. See the `boot` option in the [Proxmox manual](https://pve.proxmox.com/wiki/Manual:_qm.conf#_options) for more information. | +| `bootdisk` | `str` | | Enable booting from specified disk. You shouldn't need to change it under most circumstances. | +| `agent` | `int` | `0` | Set to `1` to enable the QEMU Guest Agent. Note, you must run the [`qemu-guest-agent`](https://pve.proxmox.com/wiki/Qemu-guest-agent) daemon in the guest for this to have any effect. | +| `pxe` | `bool` | `false` | If set to `true`, enable PXE boot of the VM. Also requires a `boot` order be set with Network included (eg `boot = "order=scsi0;net0"`). Note that `pxe` is mutually exclusive with `clone` modes. | +| `clone` | `str` | | The base VM from which to clone to create the new VM. Note that `clone` is mutually exclussive with `pxe` modes. | +| `full_clone` | `bool` | `true` | Set to `true` to create a full clone, or `false` to create a linked clone. See the [docs about cloning](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_copy_and_clone) for more info. Only applies when `clone` is set. | +| `hastate` | `str` | | Requested HA state for the resource. One of "started", "stopped", "enabled", "disabled", or "ignored". See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. | +| `hagroup` | `str` | | The HA group identifier the resource belongs to (requires `hastate` to be set!). See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. | +| `qemu_os` | `str` | `"l26"` | The type of OS in the guest. Set properly to allow Proxmox to enable optimizations for the appropriate guest OS. It takes the value from the source template and ignore any changes to resource configuration parameter. | +| `memory` | `int` | `512` | The amount of memory to allocate to the VM in Megabytes. | +| `balloon` | `int` | `0` | The minimum amount of memory to allocate to the VM in Megabytes, when Automatic Memory Allocation is desired. Proxmox will enable a balloon device on the guest to manage dynamic allocation. See the [docs about memory](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_memory) for more info. | +| `sockets` | `int` | `1` | The number of CPU sockets to allocate to the VM. | +| `cores` | `int` | `1` | The number of CPU cores per CPU socket to allocate to the VM. | +| `vcpus` | `int` | `0` | The number of vCPUs plugged into the VM when it starts. If `0`, this is set automatically by Proxmox to `sockets * cores`. | +| `cpu` | `str` | `"host"` | The type of CPU to emulate in the Guest. See the [docs about CPU Types](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_cpu) for more info. | +| `numa` | `bool` | `false` | Whether to enable [Non-Uniform Memory Access](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_cpu) in the guest. | +| `hotplug` | `str` | `"network,disk,usb"` | Comma delimited list of hotplug features to enable. Options: `network`, `disk`, `cpu`, `memory`, `usb`. Set to `0` to disable hotplug. | +| `scsihw` | `str` | `"lsi"` | The SCSI controller to emulate. Options: `lsi`, `lsi53c810`, `megasas`, `pvscsi`, `virtio-scsi-pci`, `virtio-scsi-single`. | +| `pool` | `str` | | The resource pool to which the VM will be added. | +| `tags` | `str` | | Tags of the VM. This is only meta information. | +| `force_create` | `bool` | `false` | If `false`, and a vm of the same name, on the same node exists, terraform will attempt to reconfigure that VM with these settings. Set to true to always create a new VM (note, the name of the VM must still be unique, otherwise an error will be produced.) | +| `os_type` | `str` | | Which provisioning method to use, based on the OS type. Options: `ubuntu`, `centos`, `cloud-init`. | +| `force_recreate_on_change_of` | `str` | | If the value of this string changes, the VM will be recreated. Useful for allowing this resource to be recreated when arbitrary attributes change. An example where this is useful is a cloudinit configuration (as the `cicustom` attribute points to a file not the content). | | `os_network_config` | `str` | | Only applies when `define_connection_info` is true. Network configuration to be copied into the VM when preprovisioning `ubuntu` or `centos` guests. The specified configuration is added to `/etc/network/interfaces` for Ubuntu, or `/etc/sysconfig/network-scripts/ifcfg-eth0` for CentOS. Forces re-creation on change. | -| `ssh_forward_ip` | `str` | | Only applies when `define_connection_info` is true. The IP (and optional colon separated port), to use to connect to the host for preprovisioning. If using cloud-init, this can be left blank. | -| `ssh_user` | `str` | | Only applies when `define_connection_info` is true. The user with which to connect to the guest for preprovisioning. Forces re-creation on change. | -| `ssh_private_key` | `str` | | Only applies when `define_connection_info` is true. The private key to use when connecting to the guest for preprovisioning. Sensitive. | -| `ci_wait` | `int` | `30` | How to long in seconds to wait for before provisioning. | -| `ciuser` | `str` | | Override the default cloud-init user for provisioning. | -| `cipassword` | `str` | | Override the default cloud-init user's password. Sensitive. | -| `cicustom` | `str` | | Instead specifying ciuser, cipasword, etc... you can specify the path to a custom cloud-init config file here. Grants more flexibility in configuring cloud-init. | -| `cloudinit_cdrom_storage` | `str` | | Set the storage location for the cloud-init drive. Required when using cloud-init. | -| `searchdomain` | `str` | | Sets default DNS search domain suffix. | -| `nameserver` | `str` | | Sets default DNS server for guest. | -| `sshkeys` | `str` | | Newline delimited list of SSH public keys to add to authorized keys file for the cloud-init user. | -| `ipconfig0` | `str` | | The first IP address to assign to the guest. Format: `[gw=] [,gw6=] [,ip=] [,ip6=]`. | -| `ipconfig1` to `ipconfig15` | `str` | | The second IP address to assign to the guest. Same format as `ipconfig0`. | -| `automatic_reboot` | `bool` | `true` | Automatically reboot the VM when parameter changes require this. If disabled the provider will emit a warning when the VM needs to be rebooted. | +| `ssh_forward_ip` | `str` | | Only applies when `define_connection_info` is true. The IP (and optional colon separated port), to use to connect to the host for preprovisioning. If using cloud-init, this can be left blank. | +| `ssh_user` | `str` | | Only applies when `define_connection_info` is true. The user with which to connect to the guest for preprovisioning. Forces re-creation on change. | +| `ssh_private_key` | `str` | | Only applies when `define_connection_info` is true. The private key to use when connecting to the guest for preprovisioning. Sensitive. | +| `ci_wait` | `int` | `30` | How to long in seconds to wait for before provisioning. | +| `ciuser` | `str` | | Override the default cloud-init user for provisioning. | +| `cipassword` | `str` | | Override the default cloud-init user's password. Sensitive. | +| `cicustom` | `str` | | Instead specifying ciuser, cipasword, etc... you can specify the path to a custom cloud-init config file here. Grants more flexibility in configuring cloud-init. | +| `cloudinit_cdrom_storage` | `str` | | Set the storage location for the cloud-init drive. Required when using cloud-init. | +| `searchdomain` | `str` | | Sets default DNS search domain suffix. | +| `nameserver` | `str` | | Sets default DNS server for guest. | +| `sshkeys` | `str` | | Newline delimited list of SSH public keys to add to authorized keys file for the cloud-init user. | +| `ipconfig0` | `str` | | The first IP address to assign to the guest. Format: `[gw=] [,gw6=] [,ip=] [,ip6=]`. | +| `ipconfig1` to `ipconfig15` | `str` | | The second IP address to assign to the guest. Same format as `ipconfig0`. | +| `automatic_reboot` | `bool` | `true` | Automatically reboot the VM when parameter changes require this. If disabled the provider will emit a warning when the VM needs to be rebooted. | ### VGA Block @@ -166,13 +166,13 @@ details. | Argument | Type | Default Value | Description | | ----------- | ------ | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `model` | `str` | | **Required** Network Card Model. The virtio model provides the best performance with very low CPU overhead. If your guest does not support this driver, it is usually best to use e1000. Options: `e1000`, `e1000-82540em`, `e1000-82544gc`, `e1000-82545em`, `i82551`, `i82557b`, `i82559er`, `ne2k_isa`, `ne2k_pci`, `pcnet`, `rtl8139`, `virtio`, `vmxnet3`. | -| `macaddr` | `str` | | Override the randomly generated MAC Address for the VM. Requires the MAC Address be Unicast. | -| `bridge` | `str` | `"nat"` | Bridge to which the network device should be attached. The Proxmox VE standard bridge is called `vmbr0`. | -| `tag` | `int` | `-1` | The VLAN tag to apply to packets on this device. `-1` disables VLAN tagging. | -| `firewall` | `bool` | `false` | Whether to enable the Proxmox firewall on this network device. | -| `rate` | `int` | `0` | Network device rate limit in mbps (megabytes per second) as floating point number. Set to `0` to disable rate limiting. | -| `queues` | `int` | `1` | Number of packet queues to be used on the device. Requires `virtio` model to have an effect. | -| `link_down` | `bool` | `false` | Whether this interface should be disconnected (like pulling the plug). | +| `macaddr` | `str` | | Override the randomly generated MAC Address for the VM. Requires the MAC Address be Unicast. | +| `bridge` | `str` | `"nat"` | Bridge to which the network device should be attached. The Proxmox VE standard bridge is called `vmbr0`. | +| `tag` | `int` | `-1` | The VLAN tag to apply to packets on this device. `-1` disables VLAN tagging. | +| `firewall` | `bool` | `false` | Whether to enable the Proxmox firewall on this network device. | +| `rate` | `int` | `0` | Network device rate limit in mbps (megabytes per second) as floating point number. Set to `0` to disable rate limiting. | +| `queues` | `int` | `1` | Number of packet queues to be used on the device. Requires `virtio` model to have an effect. | +| `link_down` | `bool` | `false` | Whether this interface should be disconnected (like pulling the plug). | ### Disks Block diff --git a/proxmox/provider.go b/proxmox/provider.go index 9c34d3b0..9c50fcbd 100644 --- a/proxmox/provider.go +++ b/proxmox/provider.go @@ -193,7 +193,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { } //permission check - minimum_permissions := []string{ + minimumPermissions := []string{ "Datastore.AllocateSpace", "Datastore.Audit", "Pool.Allocate", @@ -231,8 +231,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { return nil, err } sort.Strings(permlist) - sort.Strings(minimum_permissions) - permDiff := permissions_check(permlist, minimum_permissions) + sort.Strings(minimumPermissions) + permDiff := permissions_check(permlist, minimumPermissions) if len(permDiff) == 0 { // look to see what logging we should be outputting according to the provider configuration logLevels := make(map[string]string) @@ -265,10 +265,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { LogLevels: logLevels, DangerouslyIgnoreUnknownAttributes: d.Get("pm_dangerously_ignore_unknown_attributes").(bool), }, nil - } else { - err = fmt.Errorf("permissions for user/token %s are not sufficient, please provide also the following permissions that are missing: %v", userID.ToString(), permDiff) - return nil, err } + err = fmt.Errorf("permissions for user/token %s are not sufficient, please provide also the following permissions that are missing: %v", userID.ToString(), permDiff) + return nil, err } func getClient(pm_api_url string, @@ -382,6 +381,9 @@ func resourceId(targetNode string, resType string, vmId int) string { } func parseResourceId(resId string) (targetNode string, resType string, vmId int, err error) { + // create a logger for this function + logger, _ := CreateSubLogger("parseResourceId") + if !rxRsId.MatchString(resId) { return "", "", -1, fmt.Errorf("invalid resource format: %s. Must be //", resId) } @@ -389,6 +391,9 @@ func parseResourceId(resId string) (targetNode string, resType string, vmId int, targetNode = idMatch[1] resType = idMatch[2] vmId, err = strconv.Atoi(idMatch[3]) + if err != nil { + logger.Info().Str("error", err.Error()).Msgf("failed to get vmId") + } return } diff --git a/proxmox/resource_lxc.go b/proxmox/resource_lxc.go index 07db1804..93ccd6ba 100644 --- a/proxmox/resource_lxc.go +++ b/proxmox/resource_lxc.go @@ -573,10 +573,6 @@ func resourceLxcCreate(d *schema.ResourceData, meta interface{}) error { config.RootFs["size"] = config_post_resize.RootFs["size"] config.RootFs["volume"] = config_post_resize.RootFs["volume"] - if err != nil { - return err - } - // Update all remaining stuff err = config.UpdateConfig(vmr, client) if err != nil { diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 6f26c9c1..904d693f 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -225,6 +225,12 @@ func resourceVmQemu() *schema.Resource { Optional: true, Description: "Specifies the Qemu machine type.", ValidateDiagFunc: MachineTypeValidator(), + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + if old == new || (old != "" && new == "") { + return true + } + return false + }, }, "memory": { Type: schema.TypeInt, @@ -1499,21 +1505,21 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf // read in the qemu hostpci qemuPCIDevices, _ := FlattenDevicesList(config.QemuPCIDevices) logger.Debug().Int("vmid", vmID).Msgf("Hostpci Block Processed '%v'", config.QemuPCIDevices) - if d.Set("hostpci", qemuPCIDevices); err != nil { + if err = d.Set("hostpci", qemuPCIDevices); err != nil { return diag.FromErr(err) } // read in the qemu hostpci qemuUsbsDevices, _ := FlattenDevicesList(config.QemuUsbs) logger.Debug().Int("vmid", vmID).Msgf("Usb Block Processed '%v'", config.QemuUsbs) - if d.Set("usb", qemuUsbsDevices); err != nil { + if err = d.Set("usb", qemuUsbsDevices); err != nil { return diag.FromErr(err) } // read in the unused disks flatUnusedDisks, _ := FlattenDevicesList(config.QemuUnusedDisks) logger.Debug().Int("vmid", vmID).Msgf("Unused Disk Block Processed '%v'", config.QemuUnusedDisks) - if d.Set("unused_disk", flatUnusedDisks); err != nil { + if err = d.Set("unused_disk", flatUnusedDisks); err != nil { return diag.FromErr(err) }