module Chef::Provisioning::AWSDriver::TaggingStrategy::RDSConvergeTags

Public Instance Methods

aws_tagger() click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb, line 12
def aws_tagger
  @aws_tagger ||= begin
    rds_strategy = Chef::Provisioning::AWSDriver::TaggingStrategy::RDS.new(
      new_resource.driver.rds,
      construct_arn(new_resource),
      new_resource.aws_tags
    )
    Chef::Provisioning::AWSDriver::AWSTagger.new(rds_strategy, action_handler)
  end
end
construct_arn(new_resource) click to toggle source

docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Tagging.html#USER_Tagging.ARN

# File lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb, line 28
def construct_arn(new_resource)
  @arn ||= begin
    region = new_resource.driver.aws_config[:region]
    name = new_resource.name
    rds_type = new_resource.rds_tagging_type
    # Taken from example on https://forums.aws.amazon.com/thread.jspa?threadID=108012
    account_id = begin
      u = new_resource.driver.iam.get_user
      # We've got an AWS account root credential or an IAM admin with access rights
      u[:user][:arn].match("^arn:aws:iam::([0-9]{12}):.*$")[1]
    rescue ::Aws::IAM::Errors::AccessDenied => e
      # We've got an AWS IAM Credential
      e.to_s.match("^User: arn:aws:iam::([0-9]{12}):.*$")[1]
    end
    # arn:aws:rds:<region>:<account number>:<resourcetype>:<name>
    "arn:aws:rds:#{region}:#{account_id}:#{rds_type}:#{name}"
  end
end
converge_tags() click to toggle source
# File lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb, line 23
def converge_tags
  aws_tagger.converge_tags
end