convection 2.2.6 → 2.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 486c187ed6d2866b20482f3a6f9372fc55fe5221
4
- data.tar.gz: cea1c54e561e17833b76268a28aaf087a0cc55c2
3
+ metadata.gz: 6bddc9ee70240274d2d53091ce1a716994cb62c5
4
+ data.tar.gz: 7bfd13c612923a219054c045b689e6dbfb29a4e7
5
5
  SHA512:
6
- metadata.gz: 492e23623acbebb0995c788c64b6cceebb576ef9cae1cb034408e8b8f980fb770e2c74874e947a7da0351a9be14ca383c96181b60bc65c151f12535d20ccc766
7
- data.tar.gz: d818dafdaeff98149a200dc97588b7eb85313d1a7c93af01e307a069ad0e7e66ebb6ec65e666d2d9c0a2a15777cefba0fa3378a8c567f069ce81651daf608d04
6
+ metadata.gz: fe5142078018772cb99ccca5871f84426c6b01339ded1ce404b169c742b6d082ac2b6a8e55c46915ce15527e5357d3d9a5268e918711221c1cb91b0768ac38e6
7
+ data.tar.gz: cb4cbaa7a1c2fb71fece9ab855df289df6b88ba9cace85556852202515b23e3b5b5f08f7e9dd14442ef9e7f38c52ce8db9868c935d7fc21eb8c0d2b3fb50875e
data/.rubocop.yml CHANGED
@@ -3,12 +3,12 @@ inherit_from: .rubocop_todo.yml
3
3
  AllCops:
4
4
  Include:
5
5
  - lib/**/*
6
- - bin/**/*
7
6
  - Gemfile
8
7
  - Rakefile
9
8
  - Thorfile
10
9
  Exclude:
11
10
  - example/**/*
11
+ - bin/convection
12
12
  - 'lib/convection/model/template/mapping.rb' # Something is causing this file to fail
13
13
 
14
14
  Encoding:
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-11-20 16:26:30 +0000 using RuboCop version 0.49.1.
3
+ # on 2017-12-12 19:16:51 +0000 using RuboCop version 0.49.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -20,12 +20,6 @@ Layout/EmptyLineAfterMagicComment:
20
20
  Exclude:
21
21
  - 'convection.gemspec'
22
22
 
23
- # Offense count: 1
24
- # Cop supports --auto-correct.
25
- Layout/EmptyLinesAroundExceptionHandlingKeywords:
26
- Exclude:
27
- - 'lib/convection/control/stack.rb'
28
-
29
23
  # Offense count: 1
30
24
  # Cop supports --auto-correct.
31
25
  # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
@@ -52,38 +46,36 @@ Lint/UselessAssignment:
52
46
  Exclude:
53
47
  - 'lib/convection/model/template.rb'
54
48
 
55
- # Offense count: 29
49
+ # Offense count: 33
56
50
  Metrics/AbcSize:
57
- Max: 63
51
+ Max: 81
58
52
 
59
- # Offense count: 34
53
+ # Offense count: 35
60
54
  # Configuration parameters: CountComments, ExcludedMethods.
61
55
  Metrics/BlockLength:
62
- ExcludedMethods:
63
- - no_commands
64
- Max: 140
56
+ Max: 162
65
57
 
66
58
  # Offense count: 5
67
59
  # Configuration parameters: CountComments.
68
60
  Metrics/ClassLength:
69
61
  Max: 372
70
62
 
71
- # Offense count: 14
63
+ # Offense count: 17
72
64
  Metrics/CyclomaticComplexity:
73
65
  Max: 19
74
66
 
75
- # Offense count: 366
67
+ # Offense count: 398
76
68
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
77
69
  # URISchemes: http, https
78
70
  Metrics/LineLength:
79
71
  Max: 236
80
72
 
81
- # Offense count: 36
73
+ # Offense count: 39
82
74
  # Configuration parameters: CountComments.
83
75
  Metrics/MethodLength:
84
- Max: 41
76
+ Max: 58
85
77
 
86
- # Offense count: 12
78
+ # Offense count: 15
87
79
  Metrics/PerceivedComplexity:
88
80
  Max: 20
89
81
 
@@ -126,7 +118,7 @@ Style/EmptyMethod:
126
118
  Exclude:
127
119
  - 'lib/convection/model/template/resource_collection.rb'
128
120
 
129
- # Offense count: 233
121
+ # Offense count: 235
130
122
  # Cop supports --auto-correct.
131
123
  # Configuration parameters: EnforcedStyle, SupportedStyles.
132
124
  # SupportedStyles: when_needed, always, never
@@ -141,16 +133,7 @@ Style/MultilineIfModifier:
141
133
  - 'lib/convection/model/template/resource.rb'
142
134
  - 'spec/convection/model/template/resource_collection_spec.rb'
143
135
 
144
- # Offense count: 1
145
- # Cop supports --auto-correct.
146
- # Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
147
- # SupportedStyles: predicate, comparison
148
- Style/NumericPredicate:
149
- Exclude:
150
- - 'spec/**/*'
151
- - 'lib/convection/control/stack.rb'
152
-
153
- # Offense count: 29
136
+ # Offense count: 30
154
137
  # Cop supports --auto-correct.
155
138
  # Configuration parameters: PreferredDelimiters.
156
139
  Style/PercentLiteralDelimiters:
data/bin/convection CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'thor'
3
3
  require_relative '../lib/convection/control/cloud'
4
+ require 'fileutils'
4
5
  require 'thread'
5
6
  require 'yaml'
6
7
 
@@ -154,6 +155,87 @@ module Convection
154
155
  template.resources.each(&method(:import_resources))
155
156
  end
156
157
 
158
+ desc 'terraform-import-lambda-permissions', 'Import state for a lambda permission resource into terraform management'
159
+ option :cloudfile, desc: 'The cloudfile to load', default: 'Cloudfile'
160
+ option :module_path, desc: 'The module path prefix for terraform', default: DEFAULT_MODULE_PATH
161
+ option :state, desc: 'The source terraform state file', required: true
162
+ option :state_out, desc: 'The destination state file (default: --state)'
163
+ def terraform_import_lambda_permissions(stack_name)
164
+ # Lazy load this since we only want this in the terraform subcommand.
165
+ require 'active_support/core_ext/string/inflections'
166
+
167
+ state = File.expand_path(options[:state])
168
+ state_out = File.expand_path(options[:state_out]) if options[:state_out]
169
+ unless state_out
170
+ state_out = state
171
+ FileUtils.cp(state, "#{state}.#{Time.now.to_i}.backup")
172
+ end
173
+
174
+ tfstate = JSON.parse(File.read(options[:state]))
175
+ module_path = options[:module_path].split('.')
176
+ # If the user typed "module" as the prefix use "root" since that is what is written to state
177
+ # (not the module.NAME target format used for plans/applies).
178
+ module_path[0] = 'root' if module_path[0] == 'module'
179
+ module_state = tfstate.fetch('modules').find { |mod| mod['path'] == module_path }
180
+ unless module_state
181
+ warn "No module found with path #{module_path} defined in #{options[:state]}."
182
+ exit 1
183
+ end
184
+ tf_resources = module_state.fetch('resources')
185
+
186
+ init_cloud
187
+ stack = @cloud.stacks.fetch(stack_name)
188
+ stack.template.all_resources.each do |name, resource|
189
+ # Skip over this convection Resource unless it maps to a function permission.
190
+ next unless resource.type == 'AWS::Lambda::Permission'
191
+
192
+ # Get the function and permission resource summaries.
193
+ permission_resource_summary = stack.resources[name]
194
+ function_resource_summary = stack.resources[name.sub(/Permission.*$/, 'Lambda')]
195
+ unless permission_resource_summary && function_resource_summary
196
+ warn 'ERROR: Either the lambda permission or function you were trying to import have not been created in cloudformation. These resources are expected to exist in the same template.'
197
+ exit 1
198
+ end
199
+
200
+ # Skip creation of state if state for this permission already exists.
201
+ if tf_resources["aws_lambda_permission.#{permission_resource_summary.logical_resource_id.underscore}"]
202
+ warn "WARNING: Skipping resource that was found in state: aws_lambda_permission.#{permission_resource_summary.logical_resource_id.underscore}"
203
+ next
204
+ end
205
+
206
+ function_name = resource.function_name.is_a?(Hash) ? function_resource_summary.physical_resource_id : resource.function_name
207
+ source_logical_name = resource.source_arn.fetch('Fn::GetAtt').first
208
+ source_resource_summary = stack.resources[source_logical_name] && stack.resources[source_logical_name].physical_resource_id
209
+ source_arn = resource.source_arn.is_a?(Hash) ? source_resource_summary : resource.source_arn
210
+ unless source_arn
211
+ warn "Unable to determine source arn from #{resource.source_arn}"
212
+ end
213
+
214
+ tf_resources["aws_lambda_permission.#{permission_resource_summary.logical_resource_id.underscore}"] = {
215
+ type: 'aws_lambda_permission',
216
+ depends_on: [],
217
+ primary: {
218
+ id: permission_resource_summary.physical_resource_id,
219
+ attributes: {
220
+ action: resource.action,
221
+ function_name: function_name,
222
+ id: permission_resource_summary.physical_resource_id,
223
+ principal: resource.principal,
224
+ qualifer: resource.qualifer,
225
+ source_arn: source_arn,
226
+ statement_id: permission_resource_summary.physical_resource_id
227
+ }.reject { |_key, value| value.nil? },
228
+ meta: {},
229
+ tainted: false
230
+ },
231
+ deposed: [],
232
+ provider: ''
233
+ }
234
+ end
235
+
236
+ create_file state_out, JSON.pretty_generate(tfstate)
237
+ end
238
+
157
239
  # rubocop:enable Style/AsciiComments
158
240
 
159
241
  no_commands do
@@ -162,14 +244,21 @@ module Convection
162
244
  private
163
245
 
164
246
  def import_resources(_resource_name, resource)
247
+ empty_directory options[:output_directory] if resource.respond_to?(:to_hcl_json) || resource.respond_to?(:additional_hcl_files)
165
248
  if resource.respond_to?(:to_hcl_json)
166
- empty_directory options[:output_directory]
167
- destination = File.join(options[:output_directory], "#{resource.name.downcase}.tf.json")
249
+ destination = File.join(options[:output_directory], "#{resource.name.underscore}.tf.json")
168
250
  create_file destination, resource.to_hcl_json, force: options[:overwrite], skip: options[:skip_existing]
169
251
  else
170
252
  say "# Unable to generate terraform configuration for #{resource.class}. Define #{resource.class}#to_hcl_json to do so.", :yellow
171
253
  end
172
254
 
255
+ if resource.respond_to?(:additional_hcl_files)
256
+ resource.additional_hcl_files.each do |file, content|
257
+ destination = File.join(options[:output_directory], file)
258
+ create_file destination, content, force: options[:overwrite], skip: options[:skip_existing]
259
+ end
260
+ end
261
+
173
262
  if resource.respond_to?(:terraform_import_commands)
174
263
  resource.terraform_import_commands(module_path: options[:module_path]).each do |line|
175
264
  comment = line.start_with?('#')
@@ -24,6 +24,8 @@ module Convection
24
24
  property :network_interfaces, 'NetworkInterfaces', :type => :list
25
25
  property :block_devices, 'BlockDeviceMappings', :type => :list
26
26
  property :volumes, 'Volumes', :type => :list
27
+ property :ebs_optimized, 'EbsOptimized'
28
+ property :monitoring, 'Monitoring'
27
29
 
28
30
  # Append a network interface to network_interfaces
29
31
  def network_interface(&block)
@@ -14,6 +14,7 @@ module Convection
14
14
  property :principal, 'Principal'
15
15
  property :source_account, 'SourceAccount'
16
16
  property :source_arn, 'SourceArn'
17
+ property :qualifer, 'Qualifer'
17
18
  end
18
19
  end
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convection
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.6
4
+ version: 2.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Manero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport