terrafying-components 2.0.5 → 2.0.10

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: 82d21aa59af747b2463c10fab573348d579483f2e6f6ce78e8632d2accaacc7c
4
- data.tar.gz: 0bbb3d8b15e0089e2f81e217a869337cc0081f6563bee2290861b1c711619a1f
3
+ metadata.gz: 3d751cc6be7a7a3a29dd3e588cc120ec3fa1d8b3ea3b0155888551d4c74a0f6d
4
+ data.tar.gz: a55c971cf8196a9ce42f3ae5b57d35219aa1b7d6e42a0b43107866095a1a4621
5
5
  SHA512:
6
- metadata.gz: f17fc4428503038066f3a9287be5d1d5a34a109d6812cd116999bf680e320fa8387603d49cd1060a5dae3f60c374a2f4b16beaa9ee20a54968b4b89ee93b5312
7
- data.tar.gz: a9343d58ca92d4d5595bbbef4139a4c9159a32105bc0fe0f70941d27117f6d53bb166f2e3ad6d51790db228db736795b06594d1101fa4e9a69621d5a70073b14
6
+ metadata.gz: c2b2a37884426731df2c879547a3df0bf314e1314f2ec52c706606082b53520c0170cfdcfbfc64e1a3faf3c6bb720f2a76c2fcc74f106436d9f28f4030b4cc63
7
+ data.tar.gz: 4222b381c2056081c80c1a47f03376921e361129ff00979614ca52fbb6464934a565661778ba66ff4ff6bf7b73e71422b1221546ea3e73c5fa5cc3be4f1780a6
@@ -163,7 +163,7 @@ module Terrafying
163
163
 
164
164
  def attach_load_balancer(load_balancer)
165
165
  load_balancer.targets.each.with_index do |target, i|
166
- resource :aws_autoscaling_attachment, "#{load_balancer.name}-#{@name}-#{i}",
166
+ resource :aws_autoscaling_attachment, "#{load_balancer.name}-#{@name}-#{i}".gsub(%r{^(\d)}, '_\1'),
167
167
  autoscaling_group_name: @asg,
168
168
  alb_target_group_arn: target.target_group
169
169
  end
@@ -173,13 +173,14 @@ module Terrafying
173
173
 
174
174
  def autoscale_on_load_balancer(load_balancer, target_value:, disable_scale_in:)
175
175
  load_balancer.targets.each.with_index do |target, i|
176
+ policy_ident = "#{load_balancer.name}-#{@name}-#{i}".gsub(%r{^(\d)}, '_\1')
176
177
  policy_name = "#{load_balancer.name}-#{@name}-#{i}"
177
178
  lb_arn = load_balancer.id.to_s.gsub(/id/, 'arn_suffix')
178
179
  tg_arn = target.target_group.to_s.gsub(/id/, 'arn_suffix')
179
180
  listener = "aws_lb_listener.#{target.listener.to_s.split('.')[1]}"
180
- autoscaling_attachment = "aws_autoscaling_attachment.#{policy_name}"
181
+ autoscaling_attachment = "aws_autoscaling_attachment.#{policy_ident}"
181
182
 
182
- resource :aws_autoscaling_policy, policy_name,
183
+ resource :aws_autoscaling_policy, policy_ident,
183
184
  name: policy_name,
184
185
  autoscaling_group_name: @asg,
185
186
  policy_type: 'TargetTrackingScaling',
@@ -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(ident)
40
+ lb = aws.lb_by_name(name)
41
41
 
42
- @security_group = aws.security_group_by_tags(loadbalancer_name: ident)
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 = ident
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 = ident
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-#{ident}",
101
- description: "Describe the ingress and egress of the load balancer #{ident}",
100
+ name: "loadbalancer-#{@name}",
101
+ description: "Describe the ingress and egress of the load balancer #{@name}",
102
102
  tags: @tags.merge(
103
- loadbalancer_name: ident
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: ident,
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: port_ident,
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 make_identifier(type, vpc_name, name)
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
@@ -20,9 +20,9 @@ module Terrafying
20
20
  def initialize(
21
21
  vpc:,
22
22
  thanos_name: 'thanos',
23
- thanos_version: 'v0.10.1',
23
+ thanos_version: 'v0.17.2',
24
24
  prom_name: 'prometheus',
25
- prom_version: 'v2.15.2',
25
+ prom_version: 'v2.23.0',
26
26
  instances: 2,
27
27
  instance_type: 't3a.small',
28
28
  thanos_instance_type: 't3a.small',
@@ -42,7 +42,7 @@ module Terrafying
42
42
  provider: @provider,
43
43
  role: role["name"],
44
44
  policy_arn: "arn:aws:iam::aws:policy/service-role/AWSConfigRoleForOrganizations",
45
- }
45
+ }.compact
46
46
 
47
47
  source = {}
48
48
 
@@ -120,7 +120,7 @@ module Terrafying
120
120
  "logs:CreateLogStream"
121
121
  ],
122
122
  Resource: [
123
- @log_group["arn"],
123
+ "#{@log_group["arn"]}:*",
124
124
  ]
125
125
  },
126
126
  {
@@ -130,7 +130,7 @@ module Terrafying
130
130
  "logs:PutLogEvents"
131
131
  ],
132
132
  Resource: [
133
- @log_group["arn"],
133
+ "#{@log_group["arn"]}:*",
134
134
  ]
135
135
  }
136
136
  ]
@@ -152,7 +152,7 @@ module Terrafying
152
152
  enable_log_file_validation: true,
153
153
  kms_key_id: store.key_arn,
154
154
 
155
- cloud_watch_logs_group_arn: @log_group["arn"],
155
+ cloud_watch_logs_group_arn: "#{@log_group["arn"]}:*",
156
156
  cloud_watch_logs_role_arn: log_role["arn"],
157
157
 
158
158
  event_selector: [
@@ -170,7 +170,7 @@ module Terrafying
170
170
  prom = Prometheus.find_in(vpc: vpc)
171
171
  ports.each do |port|
172
172
  sg_rule_ident = Digest::SHA256.hexdigest("#{vpc.name}-#{port}-#{security_group}-#{prom.security_group}")
173
- resource :aws_security_group_rule, sg_rule_ident,
173
+ resource :aws_security_group_rule, sg_rule_ident.gsub(%r{^(\d)}, '_\1'),
174
174
  security_group_id: security_group,
175
175
  type: 'ingress',
176
176
  from_port: port,
@@ -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]),
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Terrafying
4
4
  module Components
5
- VERSION = '2.0.5'
5
+ VERSION = '2.0.10'
6
6
  end
7
7
  end
@@ -134,7 +134,12 @@ module Terrafying
134
134
  from_port: 0,
135
135
  to_port: 0,
136
136
  protocol: -1,
137
- security_groups: [@service.egress_security_group]
137
+ security_groups: [@service.egress_security_group],
138
+ ipv6_cidr_blocks: nil,
139
+ prefix_list_ids: nil,
140
+ cidr_blocks: nil,
141
+ self: nil,
142
+ description: nil
138
143
  }
139
144
  ]
140
145
 
@@ -143,7 +148,12 @@ module Terrafying
143
148
  from_port: 0,
144
149
  to_port: 0,
145
150
  protocol: -1,
146
- cidr_blocks: ["#{@ip_address}/32"]
151
+ cidr_blocks: ["#{@ip_address}/32"],
152
+ ipv6_cidr_blocks: nil,
153
+ prefix_list_ids: nil,
154
+ security_groups: nil,
155
+ self: nil,
156
+ description: nil
147
157
  }
148
158
  end
149
159
 
@@ -134,7 +134,12 @@ module Terrafying
134
134
  from_port: 0,
135
135
  to_port: 0,
136
136
  protocol: -1,
137
- security_groups: [@service.egress_security_group]
137
+ security_groups: [@service.egress_security_group],
138
+ ipv6_cidr_blocks: nil,
139
+ prefix_list_ids: nil,
140
+ cidr_blocks: nil,
141
+ self: nil,
142
+ description: nil,
138
143
  }
139
144
  ]
140
145
 
@@ -143,7 +148,12 @@ module Terrafying
143
148
  from_port: 0,
144
149
  to_port: 0,
145
150
  protocol: -1,
146
- cidr_blocks: ["#{@ip_address}/32"]
151
+ cidr_blocks: ["#{@ip_address}/32"],
152
+ ipv6_cidr_blocks: nil,
153
+ prefix_list_ids: nil,
154
+ security_groups: nil,
155
+ self: nil,
156
+ description: nil
147
157
  }
148
158
  end
149
159
 
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: 2.0.5
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - uSwitch Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake