nomad
nomad copied to clipboard
Add AWS instance tags to client metadata
Since January 2022 AWS Instance tags are available in EC2 metadata. Would it be possible to add Instance tags to Nomad client metadata?
Tags in metadata must be enabled first.
Then tags can be accessed from metadata endpoint:
nahsi@i-0f8c34d628a7cae51:~$ curl http://169.254.169.254/latest/meta-data/tags/instance
Name
aws:autoscaling:groupName
aws:ec2:fleet-id
aws:ec2launchtemplate:id
aws:ec2launchtemplate:version
class
env
role
terraform_managed
Proposal
Pupulate Nomad client metadata with Instance tags collected from AWS metadata endpoint
Use-cases
Ability to constraint jobs based on AWS tags.
Hi @nahsi
It seems like it should be possible. The AWS SDK mod might need to be updated. It looks like we are using v1.42.27 which came out Jan 4, so I don't know if it includes the new functionality or not. I suspect the changes would need to be made in the AWS fingerprinter. Do you feel like taking a pass at it? Pull requests are always welcome 😄
@DerekStrickland I will try!
That's fantastic! Thanks for being willing. I'll look for the incoming PR.
@nahsi Are you still working on this? If not, I'd like to send a PR for the same. :smile:
@nahsi Are you still working on this? If not, I'd like to send a PR for the same. :smile:
Hi. Not working on this 😅
@mr-karan Have you implemented PR for this?
Not sure, but it look like it is related: https://github.com/hashicorp/nomad/issues/6744
I also found this question: https://discuss.hashicorp.com/t/list-out-all-platform-variables/1731/7
Probably curl http://169.254.169.254/latest/meta-data/tags/instance/Name
could be aliased to $unique.platform.aws.tags.Name
, eg. when I refer this name a call to the AWS API is made.
Usage example:
job "exec-job" {
region = "planitar"
datacenters = ["dc1"]
type = "sysbatch"
group "exec" {
task "exec-task" {
driver = "exec"
config {
command = "/bin/bash"
args = ["local/exec.sh"]
}
constraint {
attribute = "${meta.aws.tag.Name}"
operator = "equal"
value = "worker"
}
template {
destination = "local/exec.sh"
data = <<-EOH
set -ex
echo "Hello ${meta.aws.tag.Name}" # As was proposed by ChatGPT )
EOH
}
}
}
}