terrafying-components 1.15.26 → 1.16.3
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 +4 -4
- data/lib/terrafying/components/dynamicset.rb +6 -9
- data/lib/terrafying/components/instance.rb +1 -8
- data/lib/terrafying/components/loadbalancer.rb +20 -20
- data/lib/terrafying/components/service.rb +2 -6
- data/lib/terrafying/components/staticset.rb +2 -2
- data/lib/terrafying/components/usable.rb +4 -4
- data/lib/terrafying/components/version.rb +1 -1
- data/lib/terrafying/components/vpc.rb +4 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9983c19cd686106f44dbb89fc3b6183e9d0ae3901f5b12726047dadf1765bcfb
|
4
|
+
data.tar.gz: bf3276537d3f02d679e6125cd3d121ecdc066cde8378cf7c0fcd9432fac0a305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c19b489486496916e5e2b23ecbdfc4459f5098e705621f3e752f849b91e20a3f29890452a05db06b89042ced288fe1619666f5521652af82a1b8c6d40a1a28b
|
7
|
+
data.tar.gz: 0ac3a558be454d86b75b9f28aa036eb2e057aff44d33664d8d9ffa8735ed22a21ff3ee3019b4b048eb0d05340f11c2b243272ec804c7147cdaa8c5e7a000c2f9
|
@@ -33,7 +33,7 @@ module Terrafying
|
|
33
33
|
options = {
|
34
34
|
public: false,
|
35
35
|
eip: false,
|
36
|
-
ami: aws.ami('base-image-fc-
|
36
|
+
ami: aws.ami('base-image-fc-b4b2c239', owners = ['477284023816']),
|
37
37
|
instance_type: 't3a.micro',
|
38
38
|
instances: { min: 1, max: 1, desired: 1, tags: {} },
|
39
39
|
ports: [],
|
@@ -44,12 +44,9 @@ module Terrafying
|
|
44
44
|
subnets: vpc.subnets.fetch(:private, []),
|
45
45
|
depends_on: [],
|
46
46
|
rolling_update: :simple,
|
47
|
-
metadata_options: nil,
|
48
47
|
vpc_endpoints_egress: []
|
49
48
|
}.merge(options)
|
50
49
|
|
51
|
-
metadata_options = options[:metadata_options]
|
52
|
-
|
53
50
|
ident = "#{tf_safe(vpc.name)}-#{name}"
|
54
51
|
|
55
52
|
@name = ident
|
@@ -88,7 +85,6 @@ module Terrafying
|
|
88
85
|
lifecycle: {
|
89
86
|
create_before_destroy: true
|
90
87
|
},
|
91
|
-
metadata_options: options[:metadata_options],
|
92
88
|
depends_on: resource_name_from(options[:instance_profile])
|
93
89
|
|
94
90
|
if options[:instances][:track]
|
@@ -142,7 +138,7 @@ module Terrafying
|
|
142
138
|
protocol: -1,
|
143
139
|
prefix_list_ids: prefix_ids
|
144
140
|
end
|
145
|
-
|
141
|
+
|
146
142
|
def default_egress_rule(ident, security_group)
|
147
143
|
resource :aws_security_group_rule, "#{ident}-default-egress",
|
148
144
|
security_group_id: security_group,
|
@@ -163,7 +159,7 @@ module Terrafying
|
|
163
159
|
|
164
160
|
def attach_load_balancer(load_balancer)
|
165
161
|
load_balancer.targets.each.with_index do |target, i|
|
166
|
-
resource :aws_autoscaling_attachment, "#{load_balancer.name}-#{@name}-#{i}",
|
162
|
+
resource :aws_autoscaling_attachment, "#{load_balancer.name}-#{@name}-#{i}".gsub(%r{^(\d)}, '_\1'),
|
167
163
|
autoscaling_group_name: @asg,
|
168
164
|
alb_target_group_arn: target.target_group
|
169
165
|
end
|
@@ -173,13 +169,14 @@ module Terrafying
|
|
173
169
|
|
174
170
|
def autoscale_on_load_balancer(load_balancer, target_value:, disable_scale_in:)
|
175
171
|
load_balancer.targets.each.with_index do |target, i|
|
172
|
+
policy_ident = "#{load_balancer.name}-#{@name}-#{i}".gsub(%r{^(\d)}, '_\1')
|
176
173
|
policy_name = "#{load_balancer.name}-#{@name}-#{i}"
|
177
174
|
lb_arn = load_balancer.id.to_s.gsub(/id/, 'arn_suffix')
|
178
175
|
tg_arn = target.target_group.to_s.gsub(/id/, 'arn_suffix')
|
179
176
|
listener = "aws_lb_listener.#{target.listener.to_s.split('.')[1]}"
|
180
|
-
autoscaling_attachment = "aws_autoscaling_attachment.#{
|
177
|
+
autoscaling_attachment = "aws_autoscaling_attachment.#{policy_ident}"
|
181
178
|
|
182
|
-
resource :aws_autoscaling_policy,
|
179
|
+
resource :aws_autoscaling_policy, policy_ident,
|
183
180
|
name: policy_name,
|
184
181
|
autoscaling_group_name: @asg,
|
185
182
|
policy_type: 'TargetTrackingScaling',
|
@@ -36,7 +36,6 @@ module Terrafying
|
|
36
36
|
instance_profile: nil,
|
37
37
|
ports: [],
|
38
38
|
tags: {},
|
39
|
-
metadata_options: nil,
|
40
39
|
security_groups: [],
|
41
40
|
depends_on: []
|
42
41
|
}.merge(options)
|
@@ -56,12 +55,7 @@ module Terrafying
|
|
56
55
|
from_port: 0,
|
57
56
|
to_port: 0,
|
58
57
|
protocol: -1,
|
59
|
-
cidr_blocks: ['0.0.0.0/0']
|
60
|
-
ipv6_cidr_blocks: nil,
|
61
|
-
prefix_list_ids: nil,
|
62
|
-
security_groups: nil,
|
63
|
-
self: nil,
|
64
|
-
description: nil
|
58
|
+
cidr_blocks: ['0.0.0.0/0']
|
65
59
|
}
|
66
60
|
]
|
67
61
|
|
@@ -105,7 +99,6 @@ module Terrafying
|
|
105
99
|
vpc.internal_ssh_security_group
|
106
100
|
].push(*options[:security_groups]),
|
107
101
|
user_data: options[:user_data],
|
108
|
-
metadata_options: options[:metadata_options],
|
109
102
|
lifecycle: {
|
110
103
|
create_before_destroy: true
|
111
104
|
},
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'digest/bubblebabble'
|
4
3
|
require 'terrafying/components/usable'
|
5
4
|
require 'terrafying/generator'
|
6
5
|
require 'digest'
|
@@ -36,14 +35,15 @@ module Terrafying
|
|
36
35
|
rescue StandardError
|
37
36
|
@type = 'application'
|
38
37
|
ident = make_identifier(@type, vpc.name, name)
|
38
|
+
name = make_name(@type, vpc.name, name)
|
39
39
|
|
40
|
-
lb = aws.lb_by_name(
|
40
|
+
lb = aws.lb_by_name(name)
|
41
41
|
|
42
|
-
@security_group = aws.security_group_by_tags(loadbalancer_name:
|
42
|
+
@security_group = aws.security_group_by_tags(loadbalancer_name: name)
|
43
43
|
end
|
44
44
|
|
45
45
|
@id = lb.load_balancer_arn
|
46
|
-
@name =
|
46
|
+
@name = name
|
47
47
|
|
48
48
|
target_groups = aws.target_groups_by_lb(@id)
|
49
49
|
|
@@ -93,14 +93,14 @@ module Terrafying
|
|
93
93
|
@type = l4_ports.count == 0 ? 'application' : 'network'
|
94
94
|
|
95
95
|
ident = make_identifier(@type, vpc.name, name)
|
96
|
-
@name =
|
96
|
+
@name = make_name(@type, vpc.name, name)
|
97
97
|
|
98
98
|
if application?
|
99
99
|
@security_group = resource :aws_security_group, ident,
|
100
|
-
name: "loadbalancer-#{
|
101
|
-
description: "Describe the ingress and egress of the load balancer #{
|
100
|
+
name: "loadbalancer-#{@name}",
|
101
|
+
description: "Describe the ingress and egress of the load balancer #{@name}",
|
102
102
|
tags: @tags.merge(
|
103
|
-
loadbalancer_name:
|
103
|
+
loadbalancer_name: @name
|
104
104
|
),
|
105
105
|
vpc_id: vpc.id
|
106
106
|
|
@@ -112,7 +112,7 @@ module Terrafying
|
|
112
112
|
end
|
113
113
|
|
114
114
|
@id = resource :aws_lb, ident, {
|
115
|
-
name:
|
115
|
+
name: @name,
|
116
116
|
load_balancer_type: type,
|
117
117
|
internal: !options[:public],
|
118
118
|
tags: @tags
|
@@ -125,8 +125,9 @@ module Terrafying
|
|
125
125
|
|
126
126
|
@ports.each do |port|
|
127
127
|
port_ident = "#{ident}-#{port[:downstream_port]}"
|
128
|
+
port_name = "#{@name}-#{port[:downstream_port]}"
|
128
129
|
|
129
|
-
default_action = port.key?(:action) ? port[:action] : forward_to_tg(port, port_ident, vpc)
|
130
|
+
default_action = port.key?(:action) ? port[:action] : forward_to_tg(port, port_ident, port_name, vpc)
|
130
131
|
|
131
132
|
ssl_options = alb_certs(port, port_ident)
|
132
133
|
|
@@ -148,9 +149,9 @@ module Terrafying
|
|
148
149
|
self
|
149
150
|
end
|
150
151
|
|
151
|
-
def forward_to_tg(port, port_ident, vpc)
|
152
|
+
def forward_to_tg(port, port_ident, port_name, vpc)
|
152
153
|
target_group = resource :aws_lb_target_group, port_ident, {
|
153
|
-
name:
|
154
|
+
name: port_name,
|
154
155
|
port: port[:downstream_port],
|
155
156
|
protocol: port[:type].upcase,
|
156
157
|
vpc_id: vpc.id
|
@@ -215,17 +216,16 @@ module Terrafying
|
|
215
216
|
set.autoscale_on_load_balancer(self, target_value: target_value, disable_scale_in: disable_scale_in)
|
216
217
|
end
|
217
218
|
|
218
|
-
def
|
219
|
+
def make_name(type, vpc_name, name)
|
220
|
+
gen_id = "#{type}-#{tf_safe(vpc_name)}-#{name}"
|
221
|
+
return Digest::SHA2.hexdigest(gen_id)[0..24] if @hex_ident || gen_id.size > 26
|
219
222
|
|
220
|
-
gen_id = "#{type}-#{vpc_name}-#{name}"
|
221
|
-
hex = Digest::SHA2.hexdigest(gen_id)[0..24]
|
222
|
-
if hex[0..0] =~ /[a-z]/
|
223
|
-
return hex if @hex_ident || gen_id.size > 26
|
224
|
-
else return Digest::SHA256.bubblebabble(gen_id)[0..15]
|
225
|
-
end
|
226
|
-
|
227
223
|
gen_id[0..31]
|
228
224
|
end
|
225
|
+
|
226
|
+
def make_identifier(type, vpc_name, name)
|
227
|
+
make_name(type, vpc_name, name).gsub(%r{^(\d)}, '_\1')
|
228
|
+
end
|
229
229
|
end
|
230
230
|
end
|
231
231
|
end
|
@@ -41,7 +41,7 @@ module Terrafying
|
|
41
41
|
|
42
42
|
def create_in(vpc, name, options = {})
|
43
43
|
options = {
|
44
|
-
ami: aws.ami('base-image-fc-
|
44
|
+
ami: aws.ami('base-image-fc-b4b2c239', owners = ['477284023816']),
|
45
45
|
instance_type: 't3a.micro',
|
46
46
|
ports: [],
|
47
47
|
instances: [{}],
|
@@ -59,7 +59,6 @@ module Terrafying
|
|
59
59
|
subnets: vpc.subnets.fetch(:private, []),
|
60
60
|
startup_grace_period: 300,
|
61
61
|
depends_on: [],
|
62
|
-
metadata_options: nil,
|
63
62
|
audit_role: "arn:aws:iam::#{aws.account_id}:role/auditd_logging",
|
64
63
|
metrics_ports: [],
|
65
64
|
vpc_endpoints_egress: []
|
@@ -97,8 +96,6 @@ module Terrafying
|
|
97
96
|
@instance_profile = add! InstanceProfile.create(ident, statements: iam_statements)
|
98
97
|
end
|
99
98
|
|
100
|
-
metadata_options = options[:metadata_options]
|
101
|
-
|
102
99
|
tags = options[:tags].merge(service_name: name)
|
103
100
|
|
104
101
|
set = options[:instances].is_a?(Hash) ? DynamicSet : StaticSet
|
@@ -115,7 +112,6 @@ module Terrafying
|
|
115
112
|
instance_set_options = {
|
116
113
|
instance_profile: @instance_profile,
|
117
114
|
depends_on: depends_on,
|
118
|
-
metadata_options: metadata_options,
|
119
115
|
tags: tags
|
120
116
|
}
|
121
117
|
|
@@ -170,7 +166,7 @@ module Terrafying
|
|
170
166
|
prom = Prometheus.find_in(vpc: vpc)
|
171
167
|
ports.each do |port|
|
172
168
|
sg_rule_ident = Digest::SHA256.hexdigest("#{vpc.name}-#{port}-#{security_group}-#{prom.security_group}")
|
173
|
-
resource :aws_security_group_rule, sg_rule_ident,
|
169
|
+
resource :aws_security_group_rule, sg_rule_ident.gsub(%r{^(\d)}, '_\1'),
|
174
170
|
security_group_id: security_group,
|
175
171
|
type: 'ingress',
|
176
172
|
from_port: port,
|
@@ -38,7 +38,7 @@ module Terrafying
|
|
38
38
|
options = {
|
39
39
|
public: false,
|
40
40
|
eip: false,
|
41
|
-
ami: aws.ami('base-image-fc-
|
41
|
+
ami: aws.ami('base-image-fc-b4b2c239', owners = ['136393635417']),
|
42
42
|
instance_type: 't3a.micro',
|
43
43
|
subnets: vpc.subnets.fetch(:private, []),
|
44
44
|
ports: [],
|
@@ -161,7 +161,7 @@ module Terrafying
|
|
161
161
|
|
162
162
|
def attach_load_balancer(load_balancer)
|
163
163
|
@instances.product(load_balancer.targets).each.with_index do |(instance, target), i|
|
164
|
-
resource :aws_lb_target_group_attachment, "#{load_balancer.name}-#{@name}-#{i}",
|
164
|
+
resource :aws_lb_target_group_attachment, "#{load_balancer.name}-#{@name}-#{i}".gsub(%r{^(\d)}, '_\1'),
|
165
165
|
target_group_arn: target.target_group,
|
166
166
|
target_id: instance.id
|
167
167
|
end
|
@@ -16,7 +16,7 @@ module Terrafying
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def path_mtu_setup!
|
19
|
-
resource :aws_security_group_rule, "#{@name}-path-mtu",
|
19
|
+
resource :aws_security_group_rule, "#{@name}-path-mtu".gsub(%r{^(\d)}, '_\1'),
|
20
20
|
security_group_id: egress_security_group,
|
21
21
|
type: 'ingress',
|
22
22
|
protocol: 1, # icmp
|
@@ -42,7 +42,7 @@ module Terrafying
|
|
42
42
|
cidr_ident = cidr.tr('./', '-')
|
43
43
|
|
44
44
|
@ports.select(&block).map do |port|
|
45
|
-
resource :aws_security_group_rule, "#{@name}-to-#{cidr_ident}-#{port[:name]}",
|
45
|
+
resource :aws_security_group_rule, "#{@name}-to-#{cidr_ident}-#{port[:name]}".gsub(%r{^(\d)}, '_\1'),
|
46
46
|
security_group_id: ingress_security_group,
|
47
47
|
type: 'ingress',
|
48
48
|
from_port: from_port(port[:upstream_port]),
|
@@ -92,7 +92,7 @@ module Terrafying
|
|
92
92
|
def used_by(*other_resources, &block)
|
93
93
|
other_resources.map do |other_resource|
|
94
94
|
@ports.select(&block).map.map do |port|
|
95
|
-
resource :aws_security_group_rule, "#{@name}-to-#{other_resource.name}-#{port[:name]}",
|
95
|
+
resource :aws_security_group_rule, "#{@name}-to-#{other_resource.name}-#{port[:name]}".gsub(%r{^(\d)}, '_\1'),
|
96
96
|
security_group_id: ingress_security_group,
|
97
97
|
type: 'ingress',
|
98
98
|
from_port: from_port(port[:upstream_port]),
|
@@ -100,7 +100,7 @@ module Terrafying
|
|
100
100
|
protocol: port[:type] == 'udp' ? 'udp' : 'tcp',
|
101
101
|
source_security_group_id: other_resource.egress_security_group
|
102
102
|
|
103
|
-
resource :aws_security_group_rule, "#{other_resource.name}-to-#{@name}-#{port[:name]}",
|
103
|
+
resource :aws_security_group_rule, "#{other_resource.name}-to-#{@name}-#{port[:name]}".gsub(%r{^(\d)}, '_\1'),
|
104
104
|
security_group_id: other_resource.egress_security_group,
|
105
105
|
type: 'egress',
|
106
106
|
from_port: from_port(port[:downstream_port]),
|
@@ -5,7 +5,6 @@ require 'netaddr'
|
|
5
5
|
require 'terrafying/components/subnet'
|
6
6
|
require 'terrafying/components/zone'
|
7
7
|
require 'terrafying/generator'
|
8
|
-
require 'digest/bubblebabble'
|
9
8
|
|
10
9
|
module Terrafying
|
11
10
|
module Components
|
@@ -185,12 +184,7 @@ module Terrafying
|
|
185
184
|
from_port: 22,
|
186
185
|
to_port: 22,
|
187
186
|
protocol: 'tcp',
|
188
|
-
cidr_blocks: [@cidr]
|
189
|
-
description: nil,
|
190
|
-
ipv6_cidr_blocks: nil,
|
191
|
-
prefix_list_ids: nil,
|
192
|
-
security_groups: nil,
|
193
|
-
self: nil
|
187
|
+
cidr_blocks: [@cidr]
|
194
188
|
}
|
195
189
|
],
|
196
190
|
egress: [
|
@@ -198,12 +192,7 @@ module Terrafying
|
|
198
192
|
from_port: 22,
|
199
193
|
to_port: 22,
|
200
194
|
protocol: 'tcp',
|
201
|
-
cidr_blocks: [@cidr]
|
202
|
-
description: nil,
|
203
|
-
ipv6_cidr_blocks: nil,
|
204
|
-
prefix_list_ids: nil,
|
205
|
-
security_groups: nil,
|
206
|
-
self: nil
|
195
|
+
cidr_blocks: [@cidr]
|
207
196
|
}
|
208
197
|
]
|
209
198
|
self
|
@@ -244,7 +233,7 @@ module Terrafying
|
|
244
233
|
subnets: @subnets.values.flatten
|
245
234
|
}.merge(options)
|
246
235
|
|
247
|
-
ident = tf_safe(
|
236
|
+
ident = tf_safe(ip_address)
|
248
237
|
|
249
238
|
if options[:tunnels].count > 2
|
250
239
|
raise 'You can only define a max of two tunnels'
|
@@ -294,7 +283,7 @@ module Terrafying
|
|
294
283
|
route_tables.product(cidrs).each do |route_table, cidr|
|
295
284
|
hash = Digest::SHA2.hexdigest "#{route_table}-#{tf_safe(cidr)}"
|
296
285
|
|
297
|
-
resource :aws_route, "#{@name}-to-#{
|
286
|
+
resource :aws_route, "#{@name}-to-#{ident}-peer-#{hash}",
|
298
287
|
route_table_id: route_table,
|
299
288
|
destination_cidr_block: cidr,
|
300
289
|
gateway_id: vpn_gateway
|
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.
|
4
|
+
version: 1.16.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uSwitch Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|