Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/provider/hypercore_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (r *HypercoreDiskResource) Create(ctx context.Context, req resource.CreateR

var diskUUID string
var disk map[string]any
var err error
isAttachingISO := data.IsoUUID.ValueString() != ""

diagDiskType := utils.ValidateDiskType(data.Type.ValueString(), data.IsoUUID.ValueString())
Expand Down Expand Up @@ -202,12 +203,17 @@ func (r *HypercoreDiskResource) Create(ctx context.Context, req resource.CreateR
},
}

diskUUID, disk = utils.AttachVirtualDisk(
diskUUID, disk, err = utils.AttachVirtualDisk(
*r.client,
attachPayload,
sourceVirtualDiskID,
data.VmUUID.ValueString(),
ctx,
)
if err != nil {
resp.Diagnostics.AddError(err.Error(), fmt.Sprintf("Error: %s", err.Error()))
return
}
tflog.Debug(ctx, fmt.Sprintf(
"TTRT Attach: Attached with original size - vm_uuid=%s, disk_uuid=%s, original_size=%v (GB), source_virtual_disk_uuid=%s",
data.VmUUID.ValueString(), diskUUID, float64(originalVDSizeBytes/1000/1000/1000), sourceVirtualDiskID),
Expand Down
14 changes: 10 additions & 4 deletions internal/utils/virtual_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func UploadVirtualDisk(
fmt.Sprintf("Please retry apply after Terraform finishes it's current operation or consider using the `-parallelism=1` terraform option. HC3 response message: %v", err.Error()),
)
}

if taskTag == nil {
return "", nil, diag.NewErrorDiagnostic("Failed to upload virtual disk "+name+" from source "+sourceURL,
"There was a problem uploading virtual disk "+name+" from source "+sourceURL+", check input parameters")
}
taskTag.WaitTask(restClient, ctx)
vdUUID := taskTag.CreatedUUID
vd := GetVirtualDiskByUUID(restClient, vdUUID)
Expand All @@ -107,16 +110,19 @@ func AttachVirtualDisk(
restClient RestClient,
payload map[string]any,
sourceVirtualDiskUUID string,
sourceVMUUID string,
ctx context.Context,
) (string, map[string]any) {
) (string, map[string]any, error) {
taskTag, _, _ := restClient.CreateRecord(
fmt.Sprintf("/rest/v1/VirtualDisk/%s/attach", sourceVirtualDiskUUID),
payload,
-1,
)

if taskTag == nil {
return "", nil, fmt.Errorf("there was a problem attaching the virtual disk %s to the VM %s, check input parameters", sourceVirtualDiskUUID, sourceVMUUID)
}
taskTag.WaitTask(restClient, ctx)
diskUUID := taskTag.CreatedUUID
disk := GetDiskByUUID(restClient, diskUUID)
return diskUUID, *disk
return diskUUID, *disk, nil
}
1 change: 0 additions & 1 deletion internal/utils/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func (vc *VM) SendImportRequest(restClient RestClient, source map[string]any) *T
payload,
-1,
)
//panic(fmt.Sprintf("neki neki: %d, %v", statusCode, err))
return taskTag
}
func (vc *VM) Import(restClient RestClient, source map[string]any, ctx context.Context) map[string]any {
Expand Down
Loading