Skip to content

Instantly share code, notes, and snippets.

@tmclaugh
Forked from dragosboca/ec2tags.rb
Created April 7, 2015 22:20
Show Gist options
  • Select an option

  • Save tmclaugh/6a0ff5013ce10e5a0cd5 to your computer and use it in GitHub Desktop.

Select an option

Save tmclaugh/6a0ff5013ce10e5a0cd5 to your computer and use it in GitHub Desktop.
require 'facter'
require 'json'
instance_id = Facter.value("ec2_instance_id")
tags = Facter::Util::Resolution.exec("aws ec2 describe-tags --filters \"name=resource-id,values=#{instance_id}\" --region sa-east-1 | jq '[.Tags[] | {key: .Key, value: .Value}]'")
parsed_tags = JSON.parse(tags)
parsed_tags.each do |tag|
fact = "ec2_tag_#{tag["key"]}"
Facter.add(fact) { setcode { tag["value"] } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment