Class: Terrafying::Components::Zone
- Inherits:
-
Terrafying::Context
- Object
- Terrafying::Context
- Terrafying::Components::Zone
- Defined in:
- lib/terrafying/components/zone.rb
Instance Attribute Summary collapse
-
#fqdn ⇒ Object
readonly
Returns the value of attribute fqdn.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #add_alias(name, config) ⇒ Object
- #add_alias_in(ctx, name, config) ⇒ Object
- #add_cname(name, *records) ⇒ Object
- #add_cname_in(ctx, name, *records) ⇒ Object
- #add_record(name, records) ⇒ Object
- #add_record_in(ctx, name, records) ⇒ Object
- #add_srv(name, service_name, port, type, hosts) ⇒ Object
- #add_srv_in(ctx, name, service_name, port, type, hosts) ⇒ Object
- #create(fqdn, options = {}) ⇒ Object
- #find(fqdn) ⇒ Object
- #find_by_tag(tag) ⇒ Object
-
#initialize ⇒ Zone
constructor
A new instance of Zone.
- #qualify(name) ⇒ Object
Constructor Details
#initialize ⇒ Zone
Returns a new instance of Zone.
23 24 25 |
# File 'lib/terrafying/components/zone.rb', line 23 def initialize() super end |
Instance Attribute Details
#fqdn ⇒ Object (readonly)
Returns the value of attribute fqdn.
9 10 11 |
# File 'lib/terrafying/components/zone.rb', line 9 def fqdn @fqdn end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/terrafying/components/zone.rb', line 9 def id @id end |
Class Method Details
.create(fqdn, options = {}) ⇒ Object
19 20 21 |
# File 'lib/terrafying/components/zone.rb', line 19 def self.create(fqdn, ={}) Zone.new.create fqdn, end |
Instance Method Details
#add_alias(name, config) ⇒ Object
88 89 90 |
# File 'lib/terrafying/components/zone.rb', line 88 def add_alias(name, config) add_alias_in(self, name, config) end |
#add_alias_in(ctx, name, config) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/terrafying/components/zone.rb', line 92 def add_alias_in(ctx, name, config) fqdn = qualify(name) ctx.resource :aws_route53_record, tf_safe(fqdn), { zone_id: @id, name: fqdn, type: "A", alias: config, } end |
#add_cname(name, *records) ⇒ Object
119 120 121 |
# File 'lib/terrafying/components/zone.rb', line 119 def add_cname(name, *records) add_cname_in(self, name, *records) end |
#add_cname_in(ctx, name, *records) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/terrafying/components/zone.rb', line 123 def add_cname_in(ctx, name, *records) fqdn = qualify(name) ident = fqdn.tr('.', '-') ctx.resource :aws_route53_record, ident, { zone_id: @id, name: fqdn, type: 'CNAME', ttl: 300, records: records } end |
#add_record(name, records) ⇒ Object
73 74 75 |
# File 'lib/terrafying/components/zone.rb', line 73 def add_record(name, records) add_record_in(self, name,records) end |
#add_record_in(ctx, name, records) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/terrafying/components/zone.rb', line 77 def add_record_in(ctx, name,records) fqdn = qualify(name) ctx.resource :aws_route53_record, tf_safe(fqdn), { zone_id: @id, name: fqdn, type: "A", ttl: 300, records: records, } end |
#add_srv(name, service_name, port, type, hosts) ⇒ Object
102 103 104 |
# File 'lib/terrafying/components/zone.rb', line 102 def add_srv(name, service_name, port, type, hosts) add_srv_in(self, name, service_name, port, type, hosts) end |
#add_srv_in(ctx, name, service_name, port, type, hosts) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/terrafying/components/zone.rb', line 106 def add_srv_in(ctx, name, service_name, port, type, hosts) fqdn = qualify(name) ident = tf_safe(fqdn) ctx.resource :aws_route53_record, "srv-#{ident}-#{service_name}", { zone_id: @id, name: "_#{service_name}._#{type}.#{fqdn}", type: "SRV", ttl: "60", records: hosts.map { |host| "0 0 #{port} #{host}" } } end |
#create(fqdn, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/terrafying/components/zone.rb', line 45 def create(fqdn, ={}) = { tags: {}, }.merge() ident = tf_safe(fqdn) @fqdn = fqdn @id = resource :aws_route53_zone, ident, { name: fqdn, tags: [:tags], } if [:parent_zone] ns = (0..3).map{ |i| output_of(:aws_route53_zone, ident, "name_servers.#{i}") } resource :aws_route53_record, "#{ident}-ns", { zone_id: [:parent_zone].id, name: fqdn, type: "NS", ttl: "30", records: ns, } end self end |
#find(fqdn) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/terrafying/components/zone.rb', line 28 def find(fqdn) zone = aws.hosted_zone(fqdn) @id = zone.id @fqdn = fqdn self end |
#find_by_tag(tag) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/terrafying/components/zone.rb', line 37 def find_by_tag(tag) zone = aws.hosted_zone_by_tag(tag) @id = zone.id @fqdn = zone.name.chomp(".") self end |
#qualify(name) ⇒ Object
136 137 138 |
# File 'lib/terrafying/components/zone.rb', line 136 def qualify(name) "#{name}.#{@fqdn}" end |