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

feature request: add setting dynamic node metadata #485

Closed
Kamilcuk opened this issue Oct 21, 2024 · 3 comments
Closed

feature request: add setting dynamic node metadata #485

Kamilcuk opened this issue Oct 21, 2024 · 3 comments

Comments

@Kamilcuk
Copy link

Proposal

Please add manipulating of dynamic Nomad node metadata. nomad_node_meta

It would be great, if terraform would only modify the metadata mentioned in configuration without touching metadata set manually. So kind of work like incremental on top of existing dynamic metadata, instead of wiping all existing dynamic metadata and replacing them all. This could be an option, for example.

Use-cases

The use case is when you want to do exactly that - change Nomad node metadata.

Attempted Solutions

Python scripts using https://developer.hashicorp.com/nomad/api-docs/client#update-dynamic-node-metadata

https://developer.hashicorp.com/nomad/docs/commands/node/meta

Thanks!

@Juanadelacuesta
Copy link
Member

Hello @Kamilcuk than you for taking the time to propose some improvements. Can you expand a little bit more on what you want to achieve? How is terraform involved in your proposal? Having a better understanding on what is your need helps us come up with better solutions. Also feel free to implement it and open a PR, we will be happy to review it.

@Kamilcuk
Copy link
Author

Kamilcuk commented Oct 24, 2024

Hi @Juanadelacuesta . Please feel free to ask me more questions.

Nomad allows setting node dynamic metadata using /v1/client/metadata endpoint documented here https://developer.hashicorp.com/nomad/api-docs/client#update-dynamic-node-metadata .

That is not possible to provision from terraform using this plugin. I am proposing to add such functionality.

Can you expand a little bit more on what you want to achieve?

Ideally, I would want to achieve the following resource. I am proposing to name the resource nomad_node_meta.

resource "nomad_node_meta" "example" {
   id = "f7476465-4d6e-c0de-26d0-e383c49be941"
   meta = {
      "foo": "bar",
      "key_to_unset": null,
   }
}

Terraform, when applying such resource, would execute POST /v1/client/metadata?NodeID=f7476465-4d6e-c0de-26d0-e383c49be941 with payload {"Meta":{"foo": "bar", "key_to_unset": null}}.

The resource would support the following arguments:

  • id - (Required) The node ID to apply changes on.
  • meta - (Required, map) Key/value pairs of node metadata.

How is terraform involved in your proposal?

Terraform is the tool that this plugin is written for. It is involved in such a way, that once this proposal would be implemented, terraform would be able to use this plugin to provision dynamic Nomad node metadata.

Please kindly ask more questions if there are any confusion.

( Additionally, it would be nice to have a data "nomad_list_nodes" "temp" { filter = "Name = \"node_name\"" } that uses https://developer.hashicorp.com/nomad/api-docs/nodes#list-nodes and would allow converting node name to ID. So that I could use id = data.nomad_list_nodes.temp[0].ID, but this would be a separate PR. )

@Juanadelacuesta
Copy link
Member

Hello @Kamilcuk! Adding and updating a node's metadata on the fly is a good idea, but terraform might not be the best tool to do so, values like the node ID are dynamic and meant to be replaceable, the terraform resource is supposed to represent nodes, not a particular node, and using it to do can lead you to unmaintainable configurations. In the meantime we recommend a scrip or even a nomad batch job, hopes this help you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants