I am trying to detach a disk from GCP vm. I am using the google_cloud_cpp apis to do this. I am passing all the values properly. Attaching the output of parameters I am passing to DetachDisk here for reference. When I see the VM logs, There is no device name at all.
DetachDiskRequest:
device_name: "test-dev-disk-1"
instance: "test-dev"
project: "r1-sd-test-lgbow"
zone: "us-east4-b"
google:☁️:cpp::compute::instances::v1::DetachDiskRequest request;
request.set_device_name(disk_name);
request.set_project(projectId);
request.set_zone(zone);
request.set_instance(instanceName);
// print the request
std::cout << "DetachDiskRequest: " << request.DebugString() << std::endl;
auto detach_result = instance_client.DetachDisk(request).get();
if (!detach_result.status().ok()) {
std::ostringstream error_message;
error_message << "Failed to detach disk: " << detach_result.status().message();
std::cerr << error_message.str() << std::endl;
throw std::runtime_error(error_message.str());
} else {
std::cout << "Disk Detach operation initiated successfully" << std::endl;
}
This function always throws an error "Failed to detach disk: Error in non-idempotent operation: Invalid value for field 'deviceName': ''. Device name must be provided.
Error: Failed to detach disk: Error in non-idempotent operation: Invalid value for field 'deviceName': ''. Device name must be provided."
Hi lbyathapatalaia,
Welcome to Google Cloud Community!
It seems that device_name field is either empty or not properly set. Have you verified the device_name parameter in the instance?
Run the following command:
gcloud compute instances describe INSTANCE_NAME --zone ZONE
Example output:
disks:
- architecture: X86_64
autoDelete: true
boot: true
deviceName: instance-custom-4-6
diskSizeGb: '10'
std::string disk_name = "DEVICE_NAME";
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.