Can Chef AWS cookbook query EC2 instance tags

amazon ec2amazon-web-serviceschef

Chef has the official AWS cookbook (https://github.com/opscode-cookbooks/aws), which allows for spinning up of AWS resources, as well as updating of resource tags.

Can the custom resources introduced by the AWS cookbook be used within recipes to READ the AWS resource tags? The only resources listed in help docs are used to update/create/delete those tags.

My goal is to be able to determine the Chef environment based on a specific AWS tag.

Best Answer

You can use the same method that is used by the tag LWRP. Take a look at https://github.com/opscode-cookbooks/aws/blob/master/providers/resource_tag.rb#L90-L92

ec2.describe_tags(:filters => { 'resource-id' => @current_resource.resource_id }).map do |tag|   
  chef-environment = tag[:my_tag_name]
end

Something like that ^^

Related Topic