1.3.0
This commit is contained in:
@@ -51,7 +51,6 @@ func (r *resourceDisk) Create(ctx context.Context, req resource.CreateRequest, r
|
||||
"account_id": plan.AccountID.ValueInt64(),
|
||||
"disk_name": plan.DiskName.ValueString(),
|
||||
"size_max": plan.SizeMax.ValueInt64(),
|
||||
"gid": plan.GID.ValueInt64(),
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceDisk: got plan successfully", contextCreateMap)
|
||||
tflog.Info(ctx, "Create resourceDisk: start creating", contextCreateMap)
|
||||
@@ -67,7 +66,6 @@ func (r *resourceDisk) Create(ctx context.Context, req resource.CreateRequest, r
|
||||
"account_id": plan.AccountID.ValueInt64(),
|
||||
"disk_name": plan.DiskName.ValueString(),
|
||||
"size_max": plan.SizeMax.ValueInt64(),
|
||||
"gid": plan.GID.ValueInt64(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
@@ -93,7 +91,7 @@ func (r *resourceDisk) Create(ctx context.Context, req resource.CreateRequest, r
|
||||
)
|
||||
return
|
||||
}
|
||||
plan.Id = types.StringValue(strconv.Itoa(int(diskId)))
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(diskId)))
|
||||
tflog.Info(ctx, "Create resourceDisk: disk created", map[string]any{"diskId": diskId, "disk_name": plan.DiskName.ValueString()})
|
||||
|
||||
// additional settings after disk creation: in case of failures, warnings are added to resp.Diagnostics,
|
||||
@@ -137,7 +135,7 @@ func (r *resourceDisk) Read(ctx context.Context, req resource.ReadRequest, resp
|
||||
tflog.Error(ctx, "Read resourceDisk: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceDisk: got state successfully", map[string]any{"disk_id": state.Id.ValueString()})
|
||||
tflog.Info(ctx, "Read resourceDisk: got state successfully", map[string]any{"disk_id": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
@@ -147,7 +145,7 @@ func (r *resourceDisk) Read(ctx context.Context, req resource.ReadRequest, resp
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceDisk: set timeouts successfully", map[string]any{
|
||||
"disk_id": state.Id.ValueString(),
|
||||
"disk_id": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
@@ -185,7 +183,7 @@ func (r *resourceDisk) Update(ctx context.Context, req resource.UpdateRequest, r
|
||||
tflog.Error(ctx, "Update resourceDisk: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceDisk: got plan successfully", map[string]any{"disk_id": plan.Id.ValueString()})
|
||||
tflog.Info(ctx, "Update resourceDisk: got plan successfully", map[string]any{"disk_id": plan.ID.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceDiskModel
|
||||
@@ -194,7 +192,7 @@ func (r *resourceDisk) Update(ctx context.Context, req resource.UpdateRequest, r
|
||||
tflog.Error(ctx, "Update resourceDisk: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceDisk: got state successfully", map[string]any{"disk_id": state.Id.ValueString()})
|
||||
tflog.Info(ctx, "Update resourceDisk: got state successfully", map[string]any{"disk_id": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
@@ -204,22 +202,22 @@ func (r *resourceDisk) Update(ctx context.Context, req resource.UpdateRequest, r
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceDisk: set timeouts successfully", map[string]any{
|
||||
"disk_id": state.Id.ValueString(),
|
||||
"disk_id": state.ID.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking if inputs are valid
|
||||
tflog.Info(ctx, "Update resourceDisk: starting input checks", map[string]any{"disk_id": plan.Id.ValueString()})
|
||||
tflog.Info(ctx, "Update resourceDisk: starting input checks", map[string]any{"disk_id": plan.ID.ValueString()})
|
||||
resp.Diagnostics.Append(resourceDiskUpdateInputChecks(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceDisk: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceDisk: input checks successful", map[string]any{"disk_id": state.Id.ValueString()})
|
||||
tflog.Info(ctx, "Update resourceDisk: input checks successful", map[string]any{"disk_id": state.ID.ValueString()})
|
||||
|
||||
diskId, err := strconv.Atoi(state.Id.ValueString())
|
||||
diskId, err := strconv.Atoi(state.ID.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Update resourceDisk: Cannot parse disk ID from state", err.Error())
|
||||
return
|
||||
@@ -261,7 +259,7 @@ func (r *resourceDisk) Update(ctx context.Context, req resource.UpdateRequest, r
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update resourceDisk: disk update is completed", map[string]any{"disk_id": plan.Id.ValueString()})
|
||||
tflog.Info(ctx, "Update resourceDisk: disk update is completed", map[string]any{"disk_id": plan.ID.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.DiskResource(ctx, &plan, r.client)...)
|
||||
@@ -288,7 +286,7 @@ func (r *resourceDisk) Delete(ctx context.Context, req resource.DeleteRequest, r
|
||||
tflog.Error(ctx, "Delete resourceDisk: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceDisk: got state successfully", map[string]any{"disk_id": state.Id.ValueString()})
|
||||
tflog.Info(ctx, "Delete resourceDisk: got state successfully", map[string]any{"disk_id": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
deleteTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
@@ -298,7 +296,7 @@ func (r *resourceDisk) Delete(ctx context.Context, req resource.DeleteRequest, r
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceDisk: set timeouts successfully", map[string]any{
|
||||
"disk_id": state.Id.ValueString(),
|
||||
"disk_id": state.ID.ValueString(),
|
||||
"deleteTimeout": deleteTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
|
||||
@@ -306,7 +304,7 @@ func (r *resourceDisk) Delete(ctx context.Context, req resource.DeleteRequest, r
|
||||
|
||||
// Delete existing resource group
|
||||
delReq := disks.DeleteRequest{
|
||||
DiskID: uint64(state.DiskId.ValueInt64()),
|
||||
DiskID: uint64(state.DiskID.ValueInt64()),
|
||||
Detach: state.Detach.ValueBool(), // default false
|
||||
Permanently: state.Permanently.ValueBool(), // default false
|
||||
}
|
||||
@@ -318,7 +316,7 @@ func (r *resourceDisk) Delete(ctx context.Context, req resource.DeleteRequest, r
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resourceDisk", map[string]any{"disk_id": state.Id.ValueString()})
|
||||
tflog.Info(ctx, "End delete resourceDisk", map[string]any{"disk_id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
// Schema defines the schema for the resource.
|
||||
|
||||
Reference in New Issue
Block a user