Class: Chef::Provider::AwsRdsParameterGroup

Inherits:
Chef::Provisioning::AWSDriver::AWSProvider show all
Includes:
Chef::Provisioning::AWSDriver::TaggingStrategy::RDSConvergeTags
Defined in:
lib/chef/provider/aws_rds_parameter_group.rb

Overview

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

Constant Summary

Constants inherited from Chef::Provisioning::AWSDriver::AWSProvider

Chef::Provisioning::AWSDriver::AWSProvider::AWSResource

Instance Attribute Summary

Attributes inherited from Chef::Provisioning::AWSDriver::AWSProvider

#purging

Instance Method Summary collapse

Methods included from Chef::Provisioning::AWSDriver::TaggingStrategy::RDSConvergeTags

#aws_tagger, #construct_arn, #converge_tags

Methods inherited from Chef::Provisioning::AWSDriver::AWSProvider

#action_handler, #converge_by, #region, #whyrun_supported?

Instance Method Details

#create_aws_objectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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_optionsObject



43
44
45
46
47
48
49
50
# 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_optionsObject



60
61
62
63
64
65
66
67
68
69
# 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_optionsObject



52
53
54
55
56
57
58
# 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) ⇒ Object



28
29
30
31
32
# 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_updatesObject

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.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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) ⇒ Object



34
35
36
37
38
39
40
41
# 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