{"record":{"id":"4e522bc1294de1d8","repo":"hashicorp/nomad","slug":"invalid-attachment-mode-q","errorCode":null,"errorMessage":"invalid attachment mode: %q","messagePattern":"invalid attachment mode: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/host_volumes.go","lineNumber":326,"sourceCode":"func (hvc *HostVolumeCapability) Copy() *HostVolumeCapability {\n\tif hvc == nil {\n\t\treturn nil\n\t}\n\n\tnhvc := *hvc\n\treturn &nhvc\n}\n\nfunc (hvc *HostVolumeCapability) Validate() error {\n\tif hvc == nil {\n\t\treturn errors.New(\"validate called on nil host volume capability\")\n\t}\n\n\tswitch hvc.AttachmentMode {\n\tcase HostVolumeAttachmentModeBlockDevice,\n\t\tHostVolumeAttachmentModeFilesystem:\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid attachment mode: %q\", hvc.AttachmentMode)\n\t}\n\n\tswitch hvc.AccessMode {\n\tcase HostVolumeAccessModeSingleNodeReader,\n\t\tHostVolumeAccessModeSingleNodeWriter,\n\t\tHostVolumeAccessModeSingleNodeSingleWriter,\n\t\tHostVolumeAccessModeSingleNodeMultiWriter:\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid access mode: %q\", hvc.AccessMode)\n\t}\n\n\treturn nil\n}\n\n// HostVolumeAttachmentModes choose the type of storage API that will be used to\n// interact with the device.\nconst (\n\tHostVolumeAttachmentModeUnknown     VolumeAttachmentMode = \"\"","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/host_volumes.go#L308-L344","documentation":"HostVolume capability validation ensures AttachmentMode is one of the supported values: block-device or filesystem. Any other string fails with this error, preventing invalid storage API selections from reaching nodes.","triggerScenarios":"Registering or validating a host volume (HostVolume.Validate / validateVolumeUpdate) whose Capabilities entry has an AttachmentMode not in {HostVolumeAttachmentModeBlockDevice, HostVolumeAttachmentModeFilesystem}.","commonSituations":"Typo in HCL (e.g. attachment_mode = \"block\"); csi vs host volume config confusion; older configs using values valid only for CSI plugin volumes.","solutions":["Set attachment_mode to exactly \"block-device\" or \"filesystem\"","Check 'nomad volume validate' or docs for accepted values","Fix client-side templating generating the mode string"],"exampleFix":"// before\ncapability { attachment_mode = \"block\" access_mode = \"single-node-writer\" }\n// after\ncapability { attachment_mode = \"block-device\" access_mode = \"single-node-writer\" }","handlingStrategy":"validation","validationCode":"validModes := map[string]bool{\"block-device\": true, \"filesystem\": true}\nif !validModes[cap.AttachmentMode] {\n  return fmt.Errorf(\"bad attachment_mode %q\", cap.AttachmentMode)\n}","typeGuard":"func validAttachmentMode(m string) bool {\n  return m == \"block-device\" || m == \"filesystem\"\n}","tryCatchPattern":null,"preventionTips":["Use the structs constants instead of raw strings in tooling","Keep a shared template of valid host volume capabilities","Validate specs with nomad volume validate before apply"],"tags":["nomad","validation","host-volume","attachment-mode"],"backgroundTag":"invalid-enum-value","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"}