This weekend I decided that I’d had enough with reusing the same pattern for manipulating tags on EC2 instances across multiple recipes. Since Opscode already publishes an aws
cookbook with providers for other AWS resources, I figured it would be worthwhile to create a provider for manipulating these tags and contribute it back upstream.
The result of this Saturday project is the resource_tag
LWRP. Source available here, Opscode ticket here.
Actions
add
- Add tags to a resource.update
- Add or modify existing tags on a resource – this is the default action.remove
- Remove tags from a resource, but only if the specified values match the existing ones.force_remove
- Remove tags from a resource, regardless of their values.
Attribute Parameters
aws_secret_access_key
,aws_access_key
- passed toOpscode::AWS:Ec2
to authenticate, required.tags
- a hash of key value pairs to be used as resource tags, (e.g.{ "Name" => "foo", "Environment" => node.chef_environment }
,) required.resource_id
- resources whose tags will be modified. The value may be a single ID as a string or multiple IDs in an array. If noresource_id
is specified the name attribute will be used.
Usage
resource_tag
can be used to manipulate the tags assigned to one or more AWS resources, i.e. ec2 instances, ebs volumes or ebs volume snapshots.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
When setting tags on the node’s own EC2 instance, I recommend wrapping resource_tag
resources in a conditional like if node.has_key?('ec2')
so that your recipe will still run on Chef nodes outside of EC2 as well.