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, #generate_tfstate, #name_from_tag, #normalize_module_name, #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
# File 'lib/terraforming/resource/route53_record.rb', line 22

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

    attributes = {
      "id"=> record_id,
      "name"=> name_of(record.name),
      "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.to_s if record.weight
    attributes["set_identifier"] = record.set_identifier if record.set_identifier

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

    result
  end

  generate_tfstate(resources)
end