Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google_cloud_cpp compute instances DetachDisk

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."

0 1 212
1 REPLY 1

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'
  • For another recommendation, Try explicitly set the value of disk_name 
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.