class Chef::Provider::AwsRdsParameterGroup

inspiration taken from providers/aws_rds_subnet_group.rb but different enough that I'm not sure there is easy abstraction

Public Instance Methods

create_aws_object() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 11
def create_aws_object
  converge_create_message = "create RDS parameter group #{new_resource.name} in #{region}"
  if update_parameters
    converge_notes = [converge_create_message, "  set group parameters to #{desired_options[:parameters]}"]
  else
    converge_notes = converge_create_message
  end

  converge_by converge_notes do
    driver.create_db_parameter_group(desired_create_options)

    if update_parameters
      driver.modify_db_parameter_group(desired_update_options)
    end
  end
end
desired_create_options() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 43
def desired_create_options
  result = {}
  full_options = desired_options
  result[:db_parameter_group_name] = full_options[:db_parameter_group_name]
  result[:db_parameter_group_family] = full_options[:db_parameter_group_family]
  result[:description] = full_options[:description]
  result
end
desired_options() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 60
def desired_options
  @desired_options ||= begin
                         opts = {}
                         opts[:db_parameter_group_name] = new_resource.name
                         opts[:db_parameter_group_family] = new_resource.db_parameter_group_family
                         opts[:description] = new_resource.description
                         opts[:parameters] = new_resource.parameters
                         AWSResource.lookup_options(opts, resource: new_resource)
                       end
end
desired_update_options() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 52
def desired_update_options
  result = {}
  full_options = desired_options
  result[:db_parameter_group_name] = full_options[:db_parameter_group_name]
  result[:parameters] = full_options[:parameters]
  result
end
destroy_aws_object(_parameter_group) click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 28
def destroy_aws_object(_parameter_group)
  converge_by "delete RDS parameter group #{new_resource.name} in #{region}" do
    driver.delete_db_parameter_group(db_parameter_group_name: new_resource.name)
  end
end
required_updates() click to toggle source

Given an existing parameter group, return an array of update descriptions representing the updates that need to be made.

Also returns Chef warnings for all the fields required for create that are not updateable, which is currently every field but parameters :(

If no updates are needed, an empty array is returned.

# File lib/chef/provider/aws_rds_parameter_group.rb, line 78
def required_updates
  # this is the only updateable field
  ret = []
  if update_parameters
    ret << "  set group parameters to #{desired_options[:parameters]}"
  end

  unless desired_options[:db_parameter_group_family].nil?
    # modify_db_parameter_group doesn't support updating the db_parameter_group_family  according to
    # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/RDS/Client.html#modify_db_parameter_group-instance_method
    # which is frustrating because it is required for create
    Chef::Log.warn "Updating description for RDS parameter groups is not supported by RDS client."
  end

  unless desired_options[:description].nil?
    # modify_db_parameter_group doesn't support updating the description according to
    # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/RDS/Client.html#modify_db_parameter_group-instance_method
    # which is frustrating because it is required for create
    Chef::Log.warn "Updating description for RDS parameter groups is not supported by RDS client."
  end

  unless desired_options[:aws_tags].nil? || desired_options[:aws_tags].empty?
    # modify_db_parameter_group doesn't support the tags key according to
    # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/RDS/Client.html#modify_db_parameter_group-instance_method
    Chef::Log.warn "Updating tags for RDS parameter groups is not supported by RDS client."
  end

  ret.unshift("update RDS parameter group #{new_resource.name} in #{region}") unless ret.empty?
  ret
end
update_aws_object(_parameter_group) click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 34
def update_aws_object(_parameter_group)
  updates = required_updates
  unless updates.empty?
    converge_by updates do
      driver.modify_db_parameter_group(desired_update_options)
    end
  end
end

Private Instance Methods

driver() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 124
def driver
  new_resource.driver.rds
end
update_parameters() click to toggle source
# File lib/chef/provider/aws_rds_parameter_group.rb, line 111
def update_parameters
  # We cannot properly check for idempotence here due to errors in the RDS API's describe_db_parameters endpoint
  # describe_db_parameters is supposed to return every field for every entry, but it does not return apply_method,
  # which is a required field to modify_db_parameter_group.
  #
  # Therefore, we cannot have idempotence on users updating the value of apply_method, so we must either
  # break in the case that the user specifies apply_method for a parameter and then later specified a different
  # value for apply_method for that parameter later in a recipe, or not be itempotent.
  #
  # Breaking the user is never the right option, so we have elected to not be itempotent.
  !(desired_options[:parameters].nil? || desired_options[:parameters].empty?)
end