{"record":{"id":"f3db705b8039317f","repo":"hashicorp/nomad","slug":"cannot-update-volume-q-volume-does-not-exist","errorCode":null,"errorMessage":"cannot update volume %q: volume does not exist","messagePattern":"cannot update volume %q: volume does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/host_volume_endpoint.go","lineNumber":438,"sourceCode":"\t}\n\n\tns, err := snap.NamespaceByName(nil, vol.Namespace)\n\tif err != nil {\n\t\treturn nil, err // should never hit, bail out\n\t}\n\tif ns == nil {\n\t\treturn nil, fmt.Errorf(\"volume validation failed: no such namespace %q\", vol.Namespace)\n\t}\n\n\t// validate any update we're making\n\tvar existing *structs.HostVolume\n\tif vol.ID != \"\" {\n\t\texisting, err = snap.HostVolumeByID(nil, vol.Namespace, vol.ID, true)\n\t\tif err != nil {\n\t\t\treturn nil, err // should never hit, bail out\n\t\t}\n\t\tif existing == nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot update volume %q: volume does not exist\", vol.ID)\n\t\t}\n\t\terr = vol.ValidateUpdate(existing)\n\t\tif err != nil {\n\t\t\treturn existing, fmt.Errorf(\"validating volume %q update failed: %v\", vol.ID, err)\n\t\t}\n\t}\n\treturn existing, nil\n}\n\n// validateVolumeForState ensures that any references to node IDs or node pools are valid\nfunc (v *HostVolume) validateVolumeForState(vol *structs.HostVolume, snap *state.StateSnapshot) error {\n\tvar poolFromExistingNode string\n\tif vol.NodeID != \"\" {\n\t\tnode, err := snap.NodeByID(nil, vol.NodeID)\n\t\tif err != nil {\n\t\t\treturn err // should never hit, bail out\n\t\t}\n\t\tif node == nil {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/host_volume_endpoint.go#L420-L456","documentation":"When the submitted volume carries an explicit ID, validateVolumeUpdate treats the request as an update and looks up the existing volume. If no volume with that ID exists in the namespace, Nomad rejects the request with this message rather than silently creating a new volume. Updates and creates are distinguished solely by the presence of vol.ID.","triggerScenarios":"Calling Create or Register with args.Volume.ID set to an ID that does not exist in the target namespace — e.g. updating a deleted volume, or a UUID from a different cluster/namespace.","commonSituations":"Automation pipelines holding stale volume IDs after deletion; cross-namespace moves without changing the ID; copy-pasted specs from other environments; CI re-running against a cleaned state store.","solutions":["Clear the ID field to perform a fresh create instead of an update.","Recreate the volume with the original ID if it was deleted unintentionally.","Confirm the volume exists in the target namespace (`nomad volume status <id>`).","Re-fetch current volume IDs from the API instead of caching them in automation."],"exampleFix":"// before\nvol := &nomad.HostVolume{ ID: \"3f2a...\", Name: \"web-data\" } // ID not in state\n// after (intent: create new volume)\nvol := &nomad.HostVolume{ Name: \"web-data\" } // omit ID","handlingStrategy":"validation","validationCode":"if vol.ID != \"\" {\n    _, _, err := client.HostVolumes().Get(vol.Namespace, vol.ID, nil)\n    if err != nil { return fmt.Errorf(\"volume %q not found; clear ID to create\", vol.ID) }\n}","typeGuard":"func volumeExists(id, ns string, client *api.Client) bool {\n    v, _, err := client.HostVolumes().Get(ns, id, nil)\n    return err == nil && v != nil\n}","tryCatchPattern":"if strings.Contains(err.Error(), \"volume does not exist\") {\n    // decide: drop ID to create anew, or recreate the deleted volume\n}","preventionTips":["Fetch fresh volume IDs from the API rather than caching","Only set ID for genuine updates","Track volume deletions in automation state","Scope IDs to the correct cluster/namespace"],"tags":["nomad","host-volumes","update","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}