Class: Jets::Resource::Route53::RecordSet

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/resource/route53/record_set.rb

Instance Method Summary collapse

Methods inherited from Base

#replacements, #resource

Instance Method Details

#cnameObject



63
64
65
66
67
68
69
# File 'lib/jets/resource/route53/record_set.rb', line 63

def cname
  if endpoint_types.include?("REGIONAL")
    "!GetAtt DomainName.RegionalDomainName"
  else
    "!GetAtt DomainName.DistributionDomainName"
  end
end

#definitionObject



17
18
19
20
21
22
23
24
# File 'lib/jets/resource/route53/record_set.rb', line 17

def definition
  {
    dns_record: {
      type: "AWS::Route53::RecordSet",
      properties: record_set_properties
    }
  }
end

#domain_nameObject



71
72
73
# File 'lib/jets/resource/route53/record_set.rb', line 71

def domain_name
  Jets::Resource::ApiGateway::DomainName.new
end

#domain_name_hosted_zoneObject



55
56
57
58
59
60
61
# File 'lib/jets/resource/route53/record_set.rb', line 55

def domain_name_hosted_zone
  if endpoint_types.include?("REGIONAL")
    "!GetAtt DomainName.RegionalHostedZoneId"
  else
    "!GetAtt DomainName.DistributionHostedZoneId"
  end
end

#endpoint_typesObject



76
77
78
# File 'lib/jets/resource/route53/record_set.rb', line 76

def endpoint_types
  domain_name.endpoint_types
end

#hosted_zone_nameObject

IE: mydomain.com



87
88
89
90
# File 'lib/jets/resource/route53/record_set.rb', line 87

def hosted_zone_name
  name = Jets.config.domain.hosted_zone_name
  name.ends_with?('.') ? name : "#{name}." # add trailing period if missing
end

#nameObject

IE: demo-dev.mydomain.com



81
82
83
84
# File 'lib/jets/resource/route53/record_set.rb', line 81

def name
  # Weird looking but correct: domain_name is object and domain_name is also method
  domain_name.domain_name
end

#outputsObject



92
93
94
95
96
# File 'lib/jets/resource/route53/record_set.rb', line 92

def outputs
  {
    "DnsRecord" => "!Ref DnsRecord",
  }
end

#record_set_propertiesObject



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
# File 'lib/jets/resource/route53/record_set.rb', line 26

def record_set_properties
  base = {
    comment: "DNS record managed by Jets",
    name: name,
  }
  hosted_zone_id = Jets.config.domain.hosted_zone_id
  if hosted_zone_id
    base[:hosted_zone_id] = hosted_zone_id
  else
    base[:hosted_zone_name] = hosted_zone_name
  end

  if Jets.config.domain.apex
    base.merge(
      alias_target: {
        dns_name: cname,
        hosted_zone_id: domain_name_hosted_zone,
      },
      type: "A",
    )
  else
    base.merge({
      type: "CNAME",
      ttl: "60",
      resource_records: [cname],
    })
  end
end