class Chef::Provisioning::AWSDriver::TaggingStrategy::EC2

Attributes

aws_object_id[R]
desired_tags[R]
ec2_client[R]

Public Class Methods

new(ec2_client, aws_object_id, desired_tags) click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb, line 26
def initialize(ec2_client, aws_object_id, desired_tags)
  @ec2_client = ec2_client
  @aws_object_id = aws_object_id
  @desired_tags = desired_tags
end

Public Instance Methods

current_tags() click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb, line 32
def current_tags
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#describe_tags-instance_method
  resp = ec2_client.describe_tags(
    filters: [
      {
        name: "resource-id",
        values: [aws_object_id]
      }
    ]
  )
  Hash[resp.tags.map { |t| [t.key, t.value] }]
end
delete_tags(tag_keys) click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb, line 55
def delete_tags(tag_keys)
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#delete_tags-instance_method
  ec2_client.delete_tags(
    resources: [aws_object_id],
    tags: tag_keys.map { |k| { key: k } }
  )
end
set_tags(tags) click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb, line 45
def set_tags(tags)
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#create_tags-instance_method
  # "The value parameter is required, but if you don't want the tag to have a value, specify
  #   the parameter with no value, and we set the value to an empty string."
  ec2_client.create_tags(
    resources: [aws_object_id],
    tags: tags.map { |k, v| { key: k, value: v } }
  )
end