diff --git a/docs/guides/cloud_init.md b/docs/guides/cloud_init.md index f7d0d946..43cf0b67 100644 --- a/docs/guides/cloud_init.md +++ b/docs/guides/cloud_init.md @@ -172,6 +172,8 @@ EOF the snippets folder in the local storage in the Proxmox VE server. */ cicustom = "user=local:snippets/user_data_vm-${count.index}.yml" + /* Create the cloud-init drive on the "local-lvm" storage */ + cloudinit_cdrom_storage = "local-lvm" provisioner "remote-exec" { inline = [ diff --git a/docs/resources/vm_qemu.md b/docs/resources/vm_qemu.md index 51f569d9..dcc3d00f 100755 --- a/docs/resources/vm_qemu.md +++ b/docs/resources/vm_qemu.md @@ -10,7 +10,7 @@ When creating a VM Qemu resource, you create a `proxmox_vm_qemu` resource block. ```hcl resource "proxmox_vm_qemu" "resource-name" { - name = "VM name" + name = "VM-name" target_node = "Node to create the VM on" iso = "ISO file name" # or @@ -118,6 +118,7 @@ The following arguments are supported in the top level resource block. |`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 specifying `cicustom`.| |`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.| diff --git a/examples/vagrant_example.tf b/examples/vagrant_example.tf index 5953c802..72f75787 100644 --- a/examples/vagrant_example.tf +++ b/examples/vagrant_example.tf @@ -16,7 +16,7 @@ provider "proxmox" { } resource "proxmox_vm_qemu" "example" { - name = "servy_mcserverface" + name = "servy-mcserverface" desc = "A test for using terraform and vagrant" target_node = "pve" } diff --git a/go.mod b/go.mod index 2dbef6bb..f1e8c67e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Telmate/terraform-provider-proxmox go 1.16 require ( - github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9 + github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c github.com/hashicorp/terraform-plugin-sdk/v2 v2.6.1 github.com/rs/zerolog v1.21.0 ) diff --git a/go.sum b/go.sum index 2c9dad0f..06fb54c9 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuN github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9 h1:BR84I9FTOYKO/kgk7y/ikEswpUT1BtrD2Z3fjJFTBC8= -github.com/Telmate/proxmox-api-go v0.0.0-20210429201316-cb769f4e78c9/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw= +github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c h1:s8BXeCeP5hLudxqEVwSScJMS/V25eyatTKpIg7JMSNQ= +github.com/Telmate/proxmox-api-go v0.0.0-20210507143528-c60bbda13c0c/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index fc3dd37b..10eaa458 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -212,6 +212,10 @@ func resourceVmQemu() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "args": { + Type: schema.TypeString, + Optional: true, + }, "memory": { Type: schema.TypeInt, Optional: true, @@ -334,10 +338,10 @@ func resourceVmQemu() *schema.Resource { }, }, "unused_disk": &schema.Schema{ - Type: schema.TypeList, - Computed: true, + Type: schema.TypeList, + Computed: true, //Optional: true, - Description: "Record unused disks in proxmox. This is intended to be read-only for now.", + Description: "Record unused disks in proxmox. This is intended to be read-only for now.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "storage": &schema.Schema{ @@ -409,7 +413,7 @@ func resourceVmQemu() *schema.Resource { "ssd": &schema.Schema{ Type: schema.TypeInt, Optional: true, - Default: 0, + Default: 0, }, "discard": &schema.Schema{ Type: schema.TypeString, @@ -682,8 +686,8 @@ func resourceVmQemu() *schema.Resource { ForceNew: true, }, "reboot_required": { - Type: schema.TypeBool, - Computed: true, + Type: schema.TypeBool, + Computed: true, Description: "Internal variable, true if any of the modified parameters require a reboot to take effect.", }, "default_ipv4_address": { @@ -743,6 +747,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error { HaState: d.Get("hastate").(string), QemuOs: d.Get("qemu_os").(string), Tags: d.Get("tags").(string), + Args: d.Get("args").(string), QemuNetworks: qemuNetworks, QemuDisks: qemuDisks, QemuSerials: qemuSerials, @@ -834,7 +839,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error { // proxmox needs so we can correctly update the existing disks (post-clone) // instead of accidentially causing the existing disk to be detached. // see https://github.com/Telmate/terraform-provider-proxmox/issues/239 - for slot, disk := range(config_post_clone.QemuDisks) { + for slot, disk := range config_post_clone.QemuDisks { // only update the desired configuration if it was not set by the user // we do not want to overwrite the desired config with the results from // proxmox if the user indicates they wish a particular file or volume config @@ -997,6 +1002,7 @@ func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error { HaState: d.Get("hastate").(string), QemuOs: d.Get("qemu_os").(string), Tags: d.Get("tags").(string), + Args: d.Get("args").(string), QemuNetworks: qemuNetworks, QemuDisks: qemuDisks, QemuSerials: qemuSerials, @@ -1229,6 +1235,7 @@ func _resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error { d.Set("hastate", vmr.HaState()) d.Set("qemu_os", config.QemuOs) d.Set("tags", config.Tags) + d.Set("args", config.Args) // Cloud-init. d.Set("ciuser", config.CIuser) // we purposely use the password from the terraform config here @@ -1243,12 +1250,15 @@ func _resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error { d.Set("ipconfig2", config.Ipconfig2) // Some dirty hacks to populate undefined keys with default values. - checkedKeys := []string{"clone_wait", "additional_wait", "force_create", "full_clone", "define_connection_info", "preprovision"} + checkedKeys := []string{"clone_wait", "additional_wait", "force_create", "define_connection_info", "preprovision"} for _, key := range checkedKeys { if _, ok := d.GetOk(key); !ok { d.Set(key, thisResource.Schema[key].Default) } } + // Check "full_clone" separately, as it causes issues in loop above due to how GetOk returns values on false bools. + // Since "full_clone" has a default of true, it will always be in the configuration, so no need to verify. + d.Set("full_clone", d.Get("full_clone")) // Disks. // add an explicit check that the keys in the config.QemuDisks map are a strict subset of