Class: Chef::Resource::AwsRoute53RecordSet
- Inherits:
-
Provisioning::AWSDriver::SuperLWRP
- Object
- LWRPBase
- Provisioning::AWSDriver::SuperLWRP
- Chef::Resource::AwsRoute53RecordSet
- Defined in:
- lib/chef/resource/aws_route53_record_set.rb
Class Method Summary collapse
Instance Method Summary collapse
- #aws_key ⇒ Object
- #fqdn ⇒ Object
-
#initialize(name, *args) ⇒ AwsRoute53RecordSet
constructor
A new instance of AwsRoute53RecordSet.
- #to_aws_change_struct(aws_action) ⇒ Object
- #to_aws_struct ⇒ Object
-
#validate! ⇒ Object
because these resources can’t actually converge themselves, we have to trigger the validations.
- #validate_rr_type!(type, rr_list) ⇒ Object
- #validate_zone_name!(rr_name, zone_name) ⇒ Object
Methods inherited from Provisioning::AWSDriver::SuperLWRP
Constructor Details
#initialize(name, *args) ⇒ AwsRoute53RecordSet
57 58 59 60 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 57 def initialize(name, *args) rr_name(name) unless @rr_name super(name, *args) end |
Class Method Details
.verify_unique!(record_sets) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 134 def self.verify_unique!(record_sets) seen = {} record_sets.each do |rs| key = rs.aws_key if seen.key?(key) raise Chef::Exceptions::ValidationFailed, "Duplicate RecordSet found in resource: [#{key}]" else seen[key] = 1 end end # TODO: be helpful and print out all duplicates, not just the first. true end |
Instance Method Details
#aws_key ⇒ Object
104 105 106 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 104 def aws_key fqdn.to_s end |
#fqdn ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 108 def fqdn if rr_name !~ /#{aws_route53_zone_name}\.?$/ "#{rr_name}.#{aws_route53_zone_name}" else rr_name end end |
#to_aws_change_struct(aws_action) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 125 def to_aws_change_struct(aws_action) # there are more elements which are optional, notably 'weight' and 'region': see the API doc at # http://redirx.me/?t3zo { action: aws_action, resource_record_set: to_aws_struct } end |
#to_aws_struct ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 116 def to_aws_struct { name: fqdn, type: type, ttl: ttl, resource_records: resource_records.map { |rr| { value: rr } } } end |
#validate! ⇒ Object
because these resources can’t actually converge themselves, we have to trigger the validations.
97 98 99 100 101 102 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 97 def validate! i{rr_name type ttl resource_records aws_route53_zone_name}.each { |f| send(f) } # this was in an :is validator, but didn't play well with inheriting default values. validate_rr_type!(type, resource_records) end |
#validate_rr_type!(type, rr_list) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 62 def validate_rr_type!(type, rr_list) case type # we'll check for integers, but leave the user responsible for valid DNS names. when "A" rr_list.all? { |v| v =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ } || raise(::Chef::Exceptions::ValidationFailed, "A records are of the form '141.2.25.3'") when "MX" rr_list.all? { |v| v =~ /^\d+\s+[^ ]+/ } || raise(::Chef::Exceptions::ValidationFailed, "MX records must have a priority and mail server, of the form '15 mail.example.com.'") when "SRV" rr_list.all? { |v| v =~ /^\d+\s+\d+\s+\d+\s+[^ ]+$/ } || raise(::Chef::Exceptions::ValidationFailed, "SRV records must have a priority, weight, port, and hostname, of the form '15 10 25 service.example.com.'") when "CNAME" rr_list.size == 1 || raise(::Chef::Exceptions::ValidationFailed, "CNAME records may only have a single value (a hostname).") when "SOA", "NS", "TXT", "PTR", "AAAA", "SPF" true else raise ArgumentError, "Argument '#{type}' must be one of %w(SOA NS A MX SRV CNAME TXT PTR AAAA SPF)" end end |
#validate_zone_name!(rr_name, zone_name) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/chef/resource/aws_route53_record_set.rb', line 89 def validate_zone_name!(rr_name, zone_name) if rr_name.end_with?(".") && rr_name !~ /#{zone_name}\.$/ raise(::Chef::Exceptions::ValidationFailed, "RecordSet name #{rr_name} does not match parent HostedZone name #{zone_name}.") end true end |