Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Forked from tmclaugh/ec2tags.rb
Last active February 16, 2016 22:30
Show Gist options
  • Save pmoranga/aead3d48671df84783f7 to your computer and use it in GitHub Desktop.
Save pmoranga/aead3d48671df84783f7 to your computer and use it in GitHub Desktop.
require 'facter'
require 'aws-sdk'
if Facter.value("ec2_instance_id") != nil
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
ec2 = Aws::EC2::Client.new(region:region)
tags = ec2.describe_tags(filters: [{ name: "resource-id", values: [instance_id] }]).tags
tags.each do |tag|
fact = "ec2_tag_#{tag["key"].gsub(/\-|\/|:/, '_')}"
Facter.add(fact) { setcode { tag["value"] } }
end
Facter.add("ec2_region") { setcode { region } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment