Skip to content

Commit

Permalink
fix(vm): unable to clone as non-root due to hook_script (#756)
Browse files Browse the repository at this point in the history
* fix(vm): unable to clone as non-root due to `hook_script`

Signed-off-by: Pavel Boldyrev <[email protected]>

* fix linter error

Signed-off-by: Pavel Boldyrev <[email protected]>

---------

Signed-off-by: Pavel Boldyrev <[email protected]>
  • Loading branch information
bpg authored Nov 30, 2023
1 parent cd24cf2 commit 728eceb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"qcow",
"virtio"
],
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast",
],
"go.testEnvFile": "${workspaceFolder}/test.env",
}
16 changes: 9 additions & 7 deletions proxmoxtf/resource/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,18 +2001,18 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
}
}

vmConfig, err := vmAPI.GetVM(ctx)
if err != nil {
return diag.FromErr(err)
}

if len(initialization) > 0 {
tflog.Trace(ctx, "Preparing the CloudInit configuration")

initializationBlock := initialization[0].(map[string]interface{})
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
initializationInterface := initializationBlock[mkResourceVirtualEnvironmentVMInitializationInterface].(string)

vmConfig, err := vmAPI.GetVM(ctx)
if err != nil {
return diag.FromErr(err)
}

existingInterface := findExistingCloudInitDrive(vmConfig, vmID, "ide2")
if initializationInterface == "" {
initializationInterface = existingInterface
Expand Down Expand Up @@ -2131,9 +2131,11 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
}

hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
currentHookScript := vmConfig.HookScript

if len(hookScript) > 0 {
updateBody.HookScript = &hookScript
} else {
} else if currentHookScript != nil {
del = append(del, "hookscript")
}

Expand All @@ -2147,7 +2149,7 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
disk := d.Get(mkResourceVirtualEnvironmentVMDisk).([]interface{})
efiDisk := d.Get(mkResourceVirtualEnvironmentVMEFIDisk).([]interface{})

vmConfig, e := vmAPI.GetVM(ctx)
vmConfig, e = vmAPI.GetVM(ctx)
if e != nil {
if strings.Contains(e.Error(), "HTTP 404") ||
(strings.Contains(e.Error(), "HTTP 500") && strings.Contains(e.Error(), "does not exist")) {
Expand Down

0 comments on commit 728eceb

Please sign in to comment.