Class: Terrafying::Components::Service
- Inherits:
-
Terrafying::Context
- Object
- Terrafying::Context
- Terrafying::Components::Service
- Includes:
- Usable
- Defined in:
- lib/terrafying/components/service.rb
Instance Attribute Summary collapse
-
#domain_names ⇒ Object
readonly
Returns the value of attribute domain_names.
-
#instance_set ⇒ Object
readonly
Returns the value of attribute instance_set.
-
#load_balancer ⇒ Object
readonly
Returns the value of attribute load_balancer.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
Class Method Summary collapse
Instance Method Summary collapse
- #create_in(vpc, name, options = {}) ⇒ Object
- #find_in(vpc, name) ⇒ Object
-
#initialize ⇒ Service
constructor
A new instance of Service.
- #with_endpoint_service(options = {}) ⇒ Object
Methods included from Usable
#egress_security_group, #ingress_security_group, #path_mtu_setup!, #pingable_by, #pingable_by_cidr, #security_group, #used_by, #used_by_cidr
Constructor Details
#initialize ⇒ Service
Returns a new instance of Service.
35 36 37 |
# File 'lib/terrafying/components/service.rb', line 35 def initialize() super end |
Instance Attribute Details
#domain_names ⇒ Object (readonly)
Returns the value of attribute domain_names.
23 24 25 |
# File 'lib/terrafying/components/service.rb', line 23 def domain_names @domain_names end |
#instance_set ⇒ Object (readonly)
Returns the value of attribute instance_set.
23 24 25 |
# File 'lib/terrafying/components/service.rb', line 23 def instance_set @instance_set end |
#load_balancer ⇒ Object (readonly)
Returns the value of attribute load_balancer.
23 24 25 |
# File 'lib/terrafying/components/service.rb', line 23 def load_balancer @load_balancer end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/terrafying/components/service.rb', line 23 def name @name end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
23 24 25 |
# File 'lib/terrafying/components/service.rb', line 23 def ports @ports end |
Class Method Details
.create_in(vpc, name, options = {}) ⇒ Object
27 28 29 |
# File 'lib/terrafying/components/service.rb', line 27 def self.create_in(vpc, name, ={}) Service.new.create_in vpc, name, end |
.find_in(vpc, name) ⇒ Object
31 32 33 |
# File 'lib/terrafying/components/service.rb', line 31 def self.find_in(vpc, name) Service.new.find_in vpc, name end |
Instance Method Details
#create_in(vpc, name, options = {}) ⇒ Object
43 44 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/terrafying/components/service.rb', line 43 def create_in(vpc, name, ={}) = { ami: aws.ami("base-image-59a5b709", owners=["136393635417"]), instance_type: "t2.micro", ports: [], instances: [{}], zone: vpc.zone, iam_policy_statements: [], security_groups: [], keypairs: [], volumes: [], units: [], files: [], tags: {}, ssh_group: vpc.ssh_group, subnets: vpc.subnets.fetch(:private, []), startup_grace_period: 300, depends_on: [], audit_role: "arn:aws:iam::#{aws.account_id}:role/auditd_logging" }.merge() unless [:audit_role].nil? fluentd_conf = Auditd.fluentd_conf([:audit_role], [:tags].keys) = .merge_with_arrays_merged(fluentd_conf) end if ! .has_key? :user_data [:user_data] = Ignition.generate() end if ! .has_key?(:loadbalancer_subnets) [:loadbalancer_subnets] = [:subnets] end unless [:instances].is_a?(Hash) or [:instances].is_a?(Array) raise 'Unknown instances option, should be hash or array' end ident = "#{tf_safe(vpc.name)}-#{name}" @name = ident @ports = enrich_ports([:ports]) @domain_names = [ [:zone].qualify(name) ] depends_on = [:depends_on] + [:keypairs].map{ |kp| kp[:resources] }.flatten iam_statements = [:iam_policy_statements] + [:keypairs].map { |kp| kp[:iam_statement] } instance_profile = add! InstanceProfile.create(ident, { statements: iam_statements }) = [:tags].merge({ service_name: name }) set = [:instances].is_a?(Hash) ? DynamicSet : StaticSet wants_load_balancer = (set == DynamicSet && @ports.count > 0) || [:loadbalancer] = { instance_profile: instance_profile, depends_on: depends_on, tags: , } if wants_load_balancer && @ports.any? { |p| p.has_key?(:health_check) } [:health_check] = { type: "ELB", grace_period: [:startup_grace_period] } end @instance_set = add! set.create_in(vpc, name, .merge()) @security_group = @instance_set.security_group if wants_load_balancer @load_balancer = add! LoadBalancer.create_in( vpc, name, .merge( { subnets: [:loadbalancer_subnets], tags: , } ), ) @load_balancer.attach(@instance_set) if @load_balancer.type == "application" @security_group = @load_balancer.security_group @egress_security_group = @instance_set.security_group end vpc.zone.add_alias_in(self, name, @load_balancer.alias_config) elsif set == StaticSet vpc.zone.add_record_in(self, name, @instance_set.instances.map { |i| i.ip_address }) @instance_set.instances.each { |i| @domain_names << vpc.zone.qualify(i.name) vpc.zone.add_record_in(self, i.name, [i.ip_address]) } end \ self end |
#find_in(vpc, name) ⇒ Object
39 40 41 |
# File 'lib/terrafying/components/service.rb', line 39 def find_in(vpc, name) raise 'unimplemented' end |
#with_endpoint_service(options = {}) ⇒ Object
140 141 142 |
# File 'lib/terrafying/components/service.rb', line 140 def with_endpoint_service( = {}) add! EndpointService.create_for(@load_balancer, @name, ) end |