terraform-aws-ec2-autoscale-group icon indicating copy to clipboard operation
terraform-aws-ec2-autoscale-group copied to clipboard

Expose metadata_options {instance_metadata_tags}

Open zen opened this issue 2 years ago • 0 comments

Describe the Feature

For some time AWS allows to enable instance tags in metadata through:

  metadata_options {
    instance_metadata_tags = "enabled"
  }

See: https://aws.amazon.com/about-aws/whats-new/2022/01/instance-tags-amazon-ec2-instance-metadata-service/

Expected Behavior

Ability to enable instance_metadata_tags

Use Case

This is very hand for setting up a hostname from "Tag:Name" and other useful automations without AWS SDK installed e.g. following cloud init example old way:

set -x
r=$(exec curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ | jq -r .region)
i=$(exec curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ | jq -r .instanceId)
n=$(aws ec2 --region "$r" describe-instances --instance-ids "$i" | jq -r '.Reservations[].Instances[].Tags[] | select(.Key=="Name") | .Value')
if [[ -n "$n" ]]; then
    hostnamectl set-hostname --static "$n" 
fi

Simpler way:

set -x

n=$(curl http://169.254.169.254/latest/meta-data/tags/instance)
if [[ -n "$n" ]]; then
    hostnamectl set-hostname --static "$n" 
fi

Describe Ideal Solution

Just add it to the TF ;)

Alternatives Considered

There are no alternatives.

zen avatar Mar 28 '22 13:03 zen