terrafying-components 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55faf0808fc9982431b901ab4a2bf8faedf8eb471f040340b1075e5982d61aa0
4
- data.tar.gz: f81aec1f8b7236d05d9e234531827c9f7f05e9e06c2e927b42368e5d5cba3bf7
3
+ metadata.gz: 62751638a41d97b8677d5e6821fea20a95d7f5db08382238504f0ed647c43f88
4
+ data.tar.gz: 7b87dab5a5740196d4e0f4af1e4994a35e0e2b774ee3ad5519d1d1dace1ddecc
5
5
  SHA512:
6
- metadata.gz: 0c0012e3b2469b6de2cc9c9de6c8d4ce995e07d3f5b3ec17ad3cfd5e78f9c5b08d31784f6d538963623c46ee6c81c3a81a27ba6f1dbe16a73dbda91957a0d82e
7
- data.tar.gz: d7eba0ca0c56aae91f8cab7b9bdd726cebe07ed1a3de09645667d1424583d2afa97dbbd31b857bd35106cc6d37e09fec574602f9c1ae8dd30823e6252411e4ff
6
+ metadata.gz: 8a4fee0f8eb676ae6f30b2e72b807625b88d6ce2902d467c55a74bcb3bde2cb553443324d5126bb7cee45e392016e7e56b6d549ba50249415c43a367000bd8d4
7
+ data.tar.gz: 9d06d16c3a1dab348ba05c629e85e30f869c3e8fb3b4e20c06cc3bb29e71efdb6cc7e0241ef3c4a9b8d193939954ef67d76b8b89fd4e72fdadf6f3c0ea7f4137
@@ -74,7 +74,7 @@ module Terrafying
74
74
  image_id: options[:ami],
75
75
  instance_type: options[:instance_type],
76
76
  user_data: options[:user_data],
77
- iam_instance_profile: options[:instance_profile] && options[:instance_profile].id,
77
+ iam_instance_profile: profile_from(options[:instance_profile]),
78
78
  associate_public_ip_address: options[:public],
79
79
  root_block_device: {
80
80
  volume_type: 'gp2',
@@ -87,7 +87,7 @@ module Terrafying
87
87
  lifecycle: {
88
88
  create_before_destroy: true,
89
89
  },
90
- depends_on: options[:instance_profile] ? options[:instance_profile].resource_names : [],
90
+ depends_on: resources_from(options[:instance_profile]),
91
91
  }
92
92
 
93
93
  if options[:instances][:track]
@@ -123,6 +123,14 @@ module Terrafying
123
123
  self
124
124
  end
125
125
 
126
+ def profile_from(profile)
127
+ profile.respond_to?(:id) ? profile.id : profile
128
+ end
129
+
130
+ def resources_from(profile)
131
+ profile.respond_to?(:resource_names) ? profile.resource_names : []
132
+ end
133
+
126
134
  def attach_load_balancer(load_balancer)
127
135
  load_balancer.target_groups.each.with_index { |target_group, i|
128
136
  resource :aws_autoscaling_attachment, "#{load_balancer.name}-#{@name}-#{i}", {
@@ -84,7 +84,7 @@ module Terrafying
84
84
  @id = resource :aws_instance, ident, {
85
85
  ami: options[:ami],
86
86
  instance_type: options[:instance_type],
87
- iam_instance_profile: options[:instance_profile] && options[:instance_profile].id,
87
+ iam_instance_profile: profile_from(options[:instance_profile]),
88
88
  subnet_id: @subnet.id,
89
89
  associate_public_ip_address: options[:public],
90
90
  root_block_device: {
@@ -109,6 +109,9 @@ module Terrafying
109
109
  self
110
110
  end
111
111
 
112
+ def profile_from(profile)
113
+ profile.respond_to?(:id) ? profile.id : profile
114
+ end
112
115
  end
113
116
  end
114
117
  end
@@ -1,3 +1,4 @@
1
+ require 'digest'
1
2
  require 'terrafying/components/usable'
2
3
  require 'terrafying/generator'
3
4
 
@@ -62,9 +63,13 @@ module Terrafying
62
63
  ports: [],
63
64
  public: false,
64
65
  subnets: vpc.subnets.fetch(:private, []),
65
- tags: {},
66
+ tags: {
67
+ Name: name
68
+ },
69
+ hex_ident: false
66
70
  }.merge(options)
67
71
 
72
+ @hex_ident = options[:hex_ident]
68
73
  @ports = enrich_ports(options[:ports])
69
74
 
70
75
  l4_ports = @ports.select{ |p| is_l4_port(p) }
@@ -78,7 +83,7 @@ module Terrafying
78
83
  ident = make_identifier(@type, vpc.name, name)
79
84
  @name = ident
80
85
 
81
- if @type == "application"
86
+ if application?
82
87
  @security_group = resource :aws_security_group, ident, {
83
88
  name: "loadbalancer-#{ident}",
84
89
  description: "Describe the ingress and egress of the load balancer #{ident}",
@@ -94,14 +99,12 @@ module Terrafying
94
99
  end
95
100
 
96
101
  @id = resource :aws_lb, ident, {
97
- name: ident,
98
- load_balancer_type: type,
99
- internal: !options[:public],
100
- subnet_mapping: options[:subnets].map{ |subnet|
101
- {subnet_id: subnet.id}
102
- },
103
- tags: options[:tags],
104
- }.merge(@type == "application" ? { security_groups: [@security_group] } : {})
102
+ name: ident,
103
+ load_balancer_type: type,
104
+ internal: !options[:public],
105
+ tags: options[:tags],
106
+ }.merge(subnets_for(options[:subnets]))
107
+ .merge(application? ? { security_groups: [@security_group] } : {})
105
108
 
106
109
  @target_groups = []
107
110
 
@@ -145,24 +148,30 @@ module Terrafying
145
148
  self
146
149
  end
147
150
 
148
- def attach(set)
149
- if set.respond_to?(:attach_load_balancer)
150
- set.attach_load_balancer(self)
151
+ def application?
152
+ @type == 'application'
153
+ end
151
154
 
152
- if @type == "network"
153
- @security_group = set.ingress_security_group
154
- end
155
- else
156
- raise "Dont' know how to attach object to LB"
157
- end
155
+ def subnets_for(subnets)
156
+ return { subnets: subnets.map(&:id) } if application?
157
+ { subnet_mapping: subnets.map { |subnet| { subnet_id: subnet.id } } }
158
158
  end
159
159
 
160
- def make_identifier(type, vpc_name, name)
161
- "#{type}-#{tf_safe(vpc_name)}-#{name}"[0..31]
160
+ def network?
161
+ @type == 'network'
162
162
  end
163
163
 
164
- end
164
+ def attach(set)
165
+ raise "Dont' know how to attach object to LB" unless set.respond_to?(:attach_load_balancer)
166
+ set.attach_load_balancer(self)
167
+ @security_group = set.ingress_security_group if network?
168
+ end
165
169
 
170
+ def make_identifier(type, vpc_name, name)
171
+ gen_id = "#{type}-#{tf_safe(vpc_name)}-#{name}"
172
+ return Digest::SHA2.hexdigest(gen_id)[0..24] if @hex_ident || gen_id.size > 26
173
+ gen_id[0..31]
174
+ end
175
+ end
166
176
  end
167
-
168
177
  end
@@ -86,9 +86,12 @@ module Terrafying
86
86
  @domain_names = [ options[:zone].qualify(name) ]
87
87
 
88
88
  depends_on = options[:depends_on] + options[:keypairs].map{ |kp| kp[:resources] }.flatten
89
-
90
- iam_statements = options[:iam_policy_statements] + options[:keypairs].map { |kp| kp[:iam_statement] }
91
- @instance_profile = add! InstanceProfile.create(ident, { statements: iam_statements })
89
+ if options.key? :instance_profile
90
+ @instance_profile = options[:instance_profile]
91
+ else
92
+ iam_statements = options[:iam_policy_statements] + options[:keypairs].map { |kp| kp[:iam_statement] }
93
+ @instance_profile = add! InstanceProfile.create(ident, { statements: iam_statements })
94
+ end
92
95
 
93
96
  tags = options[:tags].merge({ service_name: name })
94
97
 
@@ -1,5 +1,5 @@
1
1
  module Terrafying
2
2
  module Components
3
- VERSION = "1.8.0"
3
+ VERSION = "1.8.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terrafying-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uSwitch Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler