Class: GeoEngineer::Resources::AwsRoute53Record

Inherits:
GeoEngineer::Resource show all
Defined in:
lib/geoengineer/resources/aws_route53_record.rb

Overview

Note: Currently, 'name' must be the fully qualified domain name.

Constant Summary

Constants inherited from GeoEngineer::Resource

GeoEngineer::Resource::DEFAULT_PROVIDER

Constants included from HasValidations

HasValidations::MAX_POLICY_LENGTH

Instance Attribute Summary

Attributes inherited from GeoEngineer::Resource

#environment, #id, #project, #template, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GeoEngineer::Resource

_deep_symbolize_keys, #_find_remote_resource, _ignore_remote_resource?, #_json_file, #_normalize_json, _resources_to_ignore, build, #build_individual_remote_resource, clear_remote_resource_cache, #depends_on, #duplicate, #duplicate_resource, #fetch_provider, fetch_remote_resources, #find_remote_as_individual?, #for_resource, #in_project, #initialize, #matched_remote_resource, #merge_parent_tags, #merge_tags, #new?, #remote_resource, #remote_resource_params, #reset, #setup_tags_if_needed, #short_id, #short_name, #short_type, #terraform_name, #to_id_or_ref, #to_ref, #to_s, #to_terraform, #to_terraform_json, type_from_class_name, #validate_has_tag, #validate_required_subresource, #validate_subresource_required_attributes

Methods included from HasLifecycle

#execute_lifecycle, included

Methods included from HasValidations

#errors, included, #validate_at_least_one_present, #validate_cidr_block, #validate_only_one_present, #validate_policy_length, #validate_required_attributes

Methods included from HasSubResources

#assign_block, #attribute_missing, #delete_all_subresources, #delete_subresources_where, #subresources

Methods included from HasAttributes

#[], #[]=, #assign_attribute, #assign_block, #attribute_missing, #attribute_procs, #attributes, #delete, #eager_load_attributes, #method_missing, #reset_attributes, #retrieve_attribute, #terraform_attribute_ref, #terraform_attributes, #timeout

Constructor Details

This class inherits a constructor from GeoEngineer::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HasAttributes

Class Method Details

._fetch_name(record, zone) ⇒ Object


67
68
69
70
71
72
73
74
75
76
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 67

def self._fetch_name(record, zone)
  # Need to trim the trailing dot, as well as convert ASCII 42 (Octal 52) to
  # the wildcard star. Route53 uses that for wildcard records.
  name = record[:name].downcase.gsub(/\.$/, '').gsub(/^\\052/, '*')
  zone_name = zone[:name].gsub(/\.$/, '')
  if name !~ /#{zone_name}$/
    name = name.empty? ? zone_name : "#{name}.#{zone_name}"
  end
  name
end

._fetch_records_for_zone(provider, zone) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 51

def self._fetch_records_for_zone(provider, zone)
  zone_id = zone[:id].gsub(%r{^/hostedzone/}, '')
  response = AwsClients.route53(provider).list_resource_record_sets({ hosted_zone_id: zone_id })

  records = []
  response.each do |page|
    records += page.resource_record_sets.map(&:to_h).map do |record|
      name = _fetch_name(record, zone)
      id = "#{zone_id}_#{name}_#{record[:type]}"
      record.merge({ fqdn: name, _terraform_id: id, _geo_id: id })
    end
  end

  records
end

._fetch_remote_resources(provider) ⇒ Object


43
44
45
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 43

def self._fetch_remote_resources(provider)
  _fetch_zones(provider).map { |zone| _fetch_records_for_zone(provider, zone) }.flatten.compact
end

._fetch_zones(provider) ⇒ Object


47
48
49
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 47

def self._fetch_zones(provider)
  AwsClients.route53(provider).list_hosted_zones.hosted_zones.map(&:to_h)
end

Instance Method Details

#fqdnObject


35
36
37
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 35

def fqdn
  self["name"].downcase
end

#record_type(val = nil) ⇒ Object


31
32
33
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 31

def record_type(val = nil)
  val ? self["type"] = val : self["type"]
end

#support_tags?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 39

def support_tags?
  false
end

#to_terraform_stateObject


21
22
23
24
25
26
27
28
29
# File 'lib/geoengineer/resources/aws_route53_record.rb', line 21

def to_terraform_state
  tfstate = super
  tfstate[:primary][:attributes] = {
    'id' => _terraform_id,
    'name' => name,
    'type' => record_type
  }
  tfstate
end