Class: Terraforming::Resource::Route53Record

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/route53_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ Route53Record

Returns a new instance of Route53Record.



14
15
16
# File 'lib/terraforming/resource/route53_record.rb', line 14

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::Route53::Client.new) ⇒ Object



6
7
8
# File 'lib/terraforming/resource/route53_record.rb', line 6

def self.tf(client: Aws::Route53::Client.new)
  self.new(client).tf
end

.tfstate(client: Aws::Route53::Client.new) ⇒ Object



10
11
12
# File 'lib/terraforming/resource/route53_record.rb', line 10

def self.tfstate(client: Aws::Route53::Client.new)
  self.new(client).tfstate
end

Instance Method Details

#tfObject



18
19
20
# File 'lib/terraforming/resource/route53_record.rb', line 18

def tf
  apply_template(@client, "tf/route53_record")
end

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/terraforming/resource/route53_record.rb', line 22

def tfstate
  records.inject({}) do |resources, r|
    record, zone_id = r[:record], r[:zone_id]
    counter = r[:counter]
    record_id = record_id_of(record, zone_id)

    attributes = {
      "id" => record_id,
      "name" => name_of(record.name.gsub(/\\052/, '*')),
      "type" => record.type,
      "zone_id" => zone_id,
    }

    attributes["alias.#"] = "1" if record.alias_target
    attributes["records.#"] = record.resource_records.length.to_s unless record.resource_records.empty?
    attributes["ttl"] = record.ttl.to_s if record.ttl
    attributes["weight"] = record.weight ? record.weight.to_s : "-1"
    attributes["region"] = record.region if record.region

    if record.geo_location
      attributes["continent"] = record.geo_location.continent_code if record.geo_location.continent_code
      attributes["country"] = record.geo_location.country_code if record.geo_location.country_code
      attributes["subdivision"] = record.geo_location.subdivision_code if record.geo_location.subdivision_code
    end

    attributes["set_identifier"] = record.set_identifier if record.set_identifier

    resources["aws_route53_record.#{module_name_of(record, counter)}"] = {
      "type" => "aws_route53_record",
      "primary" => {
        "id" => record_id,
        "attributes" => attributes,
      }
    }

    resources
  end
end