Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Nomad #116

Closed
radeksimko opened this issue Jun 13, 2022 · 11 comments
Closed

Support for Nomad #116

radeksimko opened this issue Jun 13, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

Formatting would be great. I installed this extension because its description says:

This extension provides HCL syntax highlighting for files that use .hcl as the file extension, for example:

Nomad job specification
Packer template
Waypoint project

I thought this would include formatting as well, specifically for *.nomad files.

Originally posted by @pikeas in #98 (comment)

@radeksimko radeksimko added the enhancement New feature or request label Jun 13, 2022
@radeksimko
Copy link
Member Author

radeksimko commented Jun 13, 2022

I thought this would include formatting as well, specifically for *.nomad files.

You are right that Nomad documentation uses the *.nomad naming convention, but this is currently purely a convention, unlike in Packer, Waypoint or Terraform since Nomad jobs are addressed by the full filename/path in nomad job run <JOB_SPEC_PATH>.

There are conversations about loading multiple jobs in hashicorp/nomad#7954 which would then necessitate a naming convention to be strictly followed.

In the meantime there is nothing preventing you from naming your job files *.nmd.hcl, which is a naming convention similar to the Packer one (*.pkr.hcl & *.pkrvars.hcl), enabling the file to be picked up by this extension and highlighted.

I'll see if we could (re)establish that naming convention with .hcl suffix even before committing to one becomes necessary - I don't see why we couldn't do it, but I will need to talk to the Nomad team which of course owns the docs.

Alternatively we could either publish Nomad extension in some form and shape or consider adding that old convention to this one.

@jpogran
Copy link
Contributor

jpogran commented Jun 13, 2022

@pikeas separate from formatting, you can ensure *.nomad files are highlighted as HCL files by adding this to your user/workspace settings in VS Code:

"files.associations": {
    "*.nomad": "hashicorp.hcl"
  }

This will tell VS Code to use the HCL extension for files with the .nomad extension. This won't provide formatting but it will ensure consistent highlighting. We did not include .nomad in this extension, as Radek notes, because Nomad's file extensions are still under discussion.

@radeksimko
Copy link
Member Author

The Nomad team is inclined to changing the convention to *.nomad.hcl and the work will be tracked under hashicorp/nomad#13350 bearing in mind there's a lot of content to change and not all of it is necessarily easily grep-able.

In the meantime we'd recommend either changing your files to use that proposed convention or modifying your settings as James mentioned above.

@pikeas
Copy link

pikeas commented Jun 13, 2022

Not to overly bikeshed, but how about *.nmd.hcl?

@radeksimko
Copy link
Member Author

@pikeas That sounds like a suggestion for the Nomad team in the linked issue. For the purposes of decent editor experience, I'm fine with *.anything.hcl as long as the anything part is unique and consistent.

@daledude
Copy link

I'm confused by the push back to simply handling .nomad like .hcl. The .nomad file extension has been suggested, documented, blogged about and used for many years. Must be a technical issue I'm missing?

@radeksimko
Copy link
Member Author

radeksimko commented Aug 30, 2022

@daledude There is a few reasons behind the push back:

  • this is HCL extension, rather than Nomad extension, and hence we'd love to keep it focused on the bare-bones HCL, rather than flavours of it
  • VS Code doesn't handle conflicts well e.g. when two extensions attempt to highlight the same file because they both claim the same file, so we want to avoid conflicts as much as we can

One option we may consider however is releasing a separate simple/MVP Nomad extension which simply maps *.nomad (and later *.nomad.hcl) to the grammar we already have. Maintaining that technical debt within that separate extension seems acceptable to me.

@calebschoepp
Copy link

Is there a fix around this? Trying to get my .nomad files highlighted.

@radeksimko
Copy link
Member Author

Nomad now recommends *.nomad.hcl as per hashicorp/nomad#15997 which should be part of the next release. Job spec filenames were always recommendations, which were not enforced in any way by Nomad (unlike e.g. *.tf files by Terraform), given that one has to specify exact path e.g. in nomad job run ./path/to/job-spec.

With that in mind, folks should feel free to rename those files, i.e. append .hcl to existing *.nomad filenames, to have those files claimed by the HCL extension.

@calebschoepp
Copy link

Got it. For anyone who isn't able to change the file extensions because they don't own the code I found a workaround.

You can just force VS Code to treat .nomad files as .hcl files. https://stackoverflow.com/questions/29973619/how-to-make-vs-code-treat-a-file-extensions-as-a-certain-language/51228725#51228725

@aleneum
Copy link

aleneum commented Apr 27, 2023

Just FYI for people coming here from Google/Bing/etc:

Today, I was also looking for a way to format nomad.hcl files with vscode and realised that nomad (v1.5.3) comes with a format method nomad fmt <path_to_file>. So I made a custom formatting function with the help of Run on Save and added the following to my .vscode/settings.json:

{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.nomad\\.hcl",
        "cmd": "nomad fmt ${file}"
      }
    ]
  }
}

Now my job files are formatted every time I save them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants