convection 2.2.0 → 2.2.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +2 -0
  3. data/README.md +1 -1
  4. data/bin/convection +50 -0
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a392fc50dc24347f0d9d1d2c053c60452012456
4
- data.tar.gz: a507193b6289edd3ae3e66d2dc6f4a1e18e567b1
3
+ metadata.gz: 8931d15c79795527491f73c4440eb25decfbf0c1
4
+ data.tar.gz: '0318b27b08e66eca49fe8c459a1036ef9d421a3f'
5
5
  SHA512:
6
- metadata.gz: ba1be75c5946facbc993de9e60dbaf156246a5dc6d005ccadab022ab394216224355750c0005124e2fbd031aca40278d83c6d171c3a2ec19b5e9735537a1c832
7
- data.tar.gz: 5ef6b2ca93239b47cc53b0ae802f3dcc6fdd942097cc842d840156a8298d8fdecab76f67146827c219dbc587e046fdd9a9aad23c178d6fe36363ae6db1c82863
6
+ metadata.gz: c233b5c721e0d9701529748010627cb237d368b247902ef3a3b616fd1060d0e2319bb2d20eec338793604e55a2deb2d7bc16554651c92d6a9ea63df7f4a8d9eb
7
+ data.tar.gz: 2bcf5644dd5d20986c96635276fbac598cef484ee4e5d3e670c214272624c95e0dc62e4ec974e0ccf048092c862f306d3ad42ee7dce396dcd0690911fcc4c5cc
data/.rubocop_todo.yml CHANGED
@@ -59,6 +59,8 @@ Metrics/AbcSize:
59
59
  # Offense count: 34
60
60
  # Configuration parameters: CountComments, ExcludedMethods.
61
61
  Metrics/BlockLength:
62
+ ExcludedMethods:
63
+ - no_commands
62
64
  Max: 140
63
65
 
64
66
  # Offense count: 5
data/README.md CHANGED
@@ -1 +1 @@
1
- docs/index.md
1
+ ./docs/index.md
data/bin/convection CHANGED
@@ -9,6 +9,10 @@ module Convection
9
9
  # Convection CLI
10
10
  ##
11
11
  class CLI < Thor
12
+ include Thor::Actions
13
+
14
+ DEFAULT_MODULE_PATH = 'root'.freeze
15
+
12
16
  def initialize(*args)
13
17
  super
14
18
  @cwd = Dir.getwd
@@ -114,11 +118,57 @@ module Convection
114
118
  describe_stack_resources(options[:stack], options[:format], options[:properties], options[:type])
115
119
  end
116
120
 
121
+ desc 'terraform-export STACK', 'Create terraform configuration for a given stack (including `terraform import` commands)'
122
+ option :module_path, desc: 'The module path prefix for terraform', default: DEFAULT_MODULE_PATH
123
+ option :output_directory, desc: 'The directory to create configuration files under', aliases: %w(-d --dir), default: '.'.freeze
124
+ option :cloudfile, desc: 'The cloudfile to load', default: 'Cloudfile'
125
+ def terraform_export(stack_name)
126
+ if options[:output_directory].empty?
127
+ say_status :error, '--output-directory must not be empty.', :red
128
+ exit 1
129
+ end
130
+
131
+ if options[:module_path] == DEFAULT_MODULE_PATH
132
+ say_status :warning, '--module-path was set to "root".', :yellow
133
+ exit 0 unless yes?('Are you sure you want to generate terraform import commands in the root namespace?')
134
+ end
135
+
136
+ init_cloud
137
+ template = @cloud.stacks.fetch(stack_name).template
138
+ template.resource_collections.each(&method(:import_resources))
139
+ template.resources.each(&method(:import_resources))
140
+ end
141
+
117
142
  no_commands do
118
143
  attr_accessor :last_event
119
144
 
120
145
  private
121
146
 
147
+ def import_resources(_resource_name, resource)
148
+ if resource.respond_to?(:to_hcl_json)
149
+ empty_directory options[:output_directory]
150
+ create_file File.join(options[:output_directory], "#{resource.name.downcase}.tf.json"), resource.to_hcl_json
151
+ else
152
+ say "# Unable to generate terraform configuration for #{resource.class}. Define #{resource.class}#to_hcl_json to do so.", :yellow
153
+ end
154
+
155
+ if resource.respond_to?(:terraform_import_commands)
156
+ resource.terraform_import_commands(module_path: options[:module_path]).each do |line|
157
+ comment = line.start_with?('#')
158
+ if options[:omit_comments]
159
+ next if comment || line.strip.empty?
160
+ end
161
+
162
+ color = comment ? :bold : :cyan
163
+ say line, color
164
+ end
165
+ else
166
+ say "# Unable to determine terraform import commands for #{resource.class}. Define #{resource.class}#terraform_import_commands to do so.", :yellow
167
+ end
168
+
169
+ puts # Print an additional new line
170
+ end
171
+
122
172
  def operation(task_name, stack)
123
173
  work_q = Queue.new
124
174
  semaphore = Mutex.new
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.0
4
+ version: 2.2.1
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-11-20 00:00:00.000000000 Z
11
+ date: 2017-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -363,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
363
363
  version: '0'
364
364
  requirements: []
365
365
  rubyforge_project:
366
- rubygems_version: 2.5.1
366
+ rubygems_version: 2.6.13
367
367
  signing_key:
368
368
  specification_version: 4
369
369
  summary: A fully generic, modular DSL for AWS CloudFormation