mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-05 05:24:01 +00:00
Fix disk import when VM template has multiple disks (#96)
The disk import operation is not exposed via Proxmox APIs, so implemented as a sequence of commands run as an inline script via ssh. `qm importdisk` is used to import a disk into VM from an external file, however, it auto-generates the disk ID. The following command `qm set` is used to assign the imported disk to a VM, and it requires the disk ID as a parameter. Update the import logic to read the disk ID from the output of `qm importdisk` command rather than trying to assume it from a number of disks defined in the VM.
This commit is contained in:
parent
36dca01676
commit
37fe0e03ff
4
Makefile
4
Makefile
@ -26,7 +26,7 @@ build:
|
|||||||
rm -f "$(TERRAFORM_PLUGIN_EXECUTABLE)"
|
rm -f "$(TERRAFORM_PLUGIN_EXECUTABLE)"
|
||||||
go build -o "$(TERRAFORM_PLUGIN_EXECUTABLE)"
|
go build -o "$(TERRAFORM_PLUGIN_EXECUTABLE)"
|
||||||
|
|
||||||
example: example-build example-init example-apply example-apply example-destroy
|
example: example-build example-init example-apply example-destroy
|
||||||
|
|
||||||
example-apply:
|
example-apply:
|
||||||
export TF_CLI_CONFIG_FILE="$(shell pwd -P)/example.tfrc" \
|
export TF_CLI_CONFIG_FILE="$(shell pwd -P)/example.tfrc" \
|
||||||
@ -36,8 +36,8 @@ example-apply:
|
|||||||
&& terraform apply -auto-approve
|
&& terraform apply -auto-approve
|
||||||
|
|
||||||
example-build:
|
example-build:
|
||||||
|
rm -rf "$(TERRAFORM_PLUGIN_DIRECTORY_EXAMPLE)"
|
||||||
mkdir -p "$(TERRAFORM_PLUGIN_DIRECTORY_EXAMPLE)"
|
mkdir -p "$(TERRAFORM_PLUGIN_DIRECTORY_EXAMPLE)"
|
||||||
rm -f "$(TERRAFORM_PLUGIN_EXECUTABLE_EXAMPLE)"
|
|
||||||
go build -o "$(TERRAFORM_PLUGIN_EXECUTABLE_EXAMPLE)"
|
go build -o "$(TERRAFORM_PLUGIN_EXECUTABLE_EXAMPLE)"
|
||||||
|
|
||||||
example-destroy:
|
example-destroy:
|
||||||
|
@ -1832,7 +1832,6 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(ctx context.Context, d *schem
|
|||||||
`set -e`,
|
`set -e`,
|
||||||
fmt.Sprintf(`datastore_id_image="%s"`, fileIDParts[0]),
|
fmt.Sprintf(`datastore_id_image="%s"`, fileIDParts[0]),
|
||||||
fmt.Sprintf(`datastore_id_target="%s"`, datastoreID),
|
fmt.Sprintf(`datastore_id_target="%s"`, datastoreID),
|
||||||
fmt.Sprintf(`disk_count="%d"`, diskCount+importedDiskCount),
|
|
||||||
fmt.Sprintf(`disk_index="%d"`, i),
|
fmt.Sprintf(`disk_index="%d"`, i),
|
||||||
fmt.Sprintf(`disk_options="%s"`, diskOptions),
|
fmt.Sprintf(`disk_options="%s"`, diskOptions),
|
||||||
fmt.Sprintf(`disk_size="%d"`, size),
|
fmt.Sprintf(`disk_size="%d"`, size),
|
||||||
@ -1849,8 +1848,8 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(ctx context.Context, d *schem
|
|||||||
`dsp_target="$(echo "$dsi_target" | cut -d ";" -f 1)"`,
|
`dsp_target="$(echo "$dsi_target" | cut -d ";" -f 1)"`,
|
||||||
`cp "${dsp_image}${file_path}" "$file_path_tmp"`,
|
`cp "${dsp_image}${file_path}" "$file_path_tmp"`,
|
||||||
`qemu-img resize "$file_path_tmp" "${disk_size}G"`,
|
`qemu-img resize "$file_path_tmp" "${disk_size}G"`,
|
||||||
`qm importdisk "$vm_id" "$file_path_tmp" "$datastore_id_target" -format qcow2`,
|
`imported_disk="$(qm importdisk "$vm_id" "$file_path_tmp" "$datastore_id_target" -format qcow2 | grep "unused0" | cut -d ":" -f 3 | cut -d "'" -f 1)"`,
|
||||||
`disk_id="${datastore_id_target}:$([[ -n "$dsp_target" ]] && echo "${vm_id}/" || echo "")vm-${vm_id}-disk-${disk_count}$([[ -n "$dsp_target" ]] && echo ".qcow2" || echo "")${disk_options}"`,
|
`disk_id="${datastore_id_target}:$([[ -n "$dsp_target" ]] && echo "${vm_id}/" || echo "")$imported_disk$([[ -n "$dsp_target" ]] && echo ".qcow2" || echo "")${disk_options}"`,
|
||||||
`qm set "$vm_id" "-${disk_interface}" "$disk_id"`,
|
`qm set "$vm_id" "-${disk_interface}" "$disk_id"`,
|
||||||
`rm -f "$file_path_tmp"`,
|
`rm -f "$file_path_tmp"`,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user