terradactyl 0.15.0 → 0.15.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: f2a88b521150fa75bede628b6a89642b308b873439b8ab1c321c5c0c4f223670
4
- data.tar.gz: ac90f280fec5f7f3ce98b734c407f335b158863df5c324b577dce98e34878f91
3
+ metadata.gz: 0bc592a89bdefefae6460b67cf305a20c9a204f7960d8f7adc060e6b45352d20
4
+ data.tar.gz: c2f4083336586251254b15970c97c00f63dd0d07c5354e14f00b2c9ee6fb840c
5
5
  SHA512:
6
- metadata.gz: 525638ac61294ee05b8cbc0618b467fb4b32910c09bb5c6f8269e690ae2f70ae9764543bc2923fa3d1629591a5b9d952019fbfee0326202f39514bdf234c087a
7
- data.tar.gz: ff919fb3c9b2bc11227d0c1d6668aa270d05e273af136a96d85d7afe67139c26979d1e375f51a69792101c50d8acf400f2e3f6629b009b928491f07c43213aa6
6
+ metadata.gz: 48283e55d2f375e71b4aef40e831cb4f973f98a42382972db7a2b099735725f633348995fd1cc8e4a9075799add4a1ce8ac0b41ad755fee08e5bcdd6e709499a
7
+ data.tar.gz: 3eb7984c57b37fc6a72dd350a8deeed2b77b228cf5f7e0ace79cde86b5c3004fb4bc9f78d651a059b0a769ba2572a06db93a58b2c75ace1c7140b3091a930f95
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.15.1 (2021-04-28)
4
+
5
+ BUG FIXES:
6
+
7
+ * repair broken `upgrade` subcommand
8
+ * fix malformed HCL substitution
9
+ * fix regex match order of operations bug
10
+ * make the feature more robust
11
+ * add better feedback
12
+
3
13
  ## 0.15.0 (2021-04-27)
4
14
 
5
15
  NEW FEATURES:
@@ -67,6 +67,20 @@ module Terradactyl
67
67
  def terraform_latest
68
68
  Terradactyl::Terraform::VersionManager.latest
69
69
  end
70
+
71
+ def upgrade_stack(name)
72
+ @stack ||= Stack.new(name)
73
+ print_warning "Upgrading: #{@stack.name}"
74
+ if @stack.upgrade.zero?
75
+ print_ok "Upgraded: #{@stack.name}"
76
+ else
77
+ Stacks.error!(@stack)
78
+ print_crit "Failed to upgrade: #{@stack.name}"
79
+ end
80
+ rescue Terradactyl::Terraform::Commands::UnsupportedCommandError => e
81
+ print_crit "Error: #{e.message}"
82
+ exit 1
83
+ end
70
84
  end
71
85
  # rubocop:enable Metrics/BlockLength
72
86
 
@@ -153,6 +167,14 @@ module Terradactyl
153
167
  # the `quickplan` task is an exception to this rule.
154
168
  #################################################################
155
169
 
170
+ desc 'upgrade NAME', 'Cleans, inits, upgrades and formats an individual stack, by name'
171
+ def upgrade(name)
172
+ clean(name)
173
+ init(name)
174
+ upgrade_stack(name)
175
+ fmt(name)
176
+ end
177
+
156
178
  desc 'quickplan NAME', 'Clean, init and plan a stack, by name'
157
179
  def quickplan(name)
158
180
  print_header "Quick planning #{name} ..."
@@ -358,16 +380,21 @@ module Terradactyl
358
380
 
359
381
  desc 'install COMPONENT', 'Installs specified component'
360
382
  long_desc <<~LONGDESC
361
- The `terradactyl install COMPONENT` subcommand perfoms installations of
383
+ The `terradactyl install COMPONENT` subcommand perfoms installations of
362
384
  prerequisties. At present, only Terraform binaries are supported.
363
- Here are a few examples:
364
- # Install latest
385
+
386
+ Here are a few examples:
387
+
388
+ # Install latest
365
389
  `terradactyl install terraform`
366
- # Install pessimistic version
390
+
391
+ # Install pessimistic version
367
392
  `terradactyl install terraform --version="~> 0.13.0"`
368
- # Install ranged version
393
+
394
+ # Install ranged version
369
395
  `terradactyl install terraform --version=">= 0.14.5, <= 0.14.7"`
370
- # Install explicit version
396
+
397
+ # Install explicit version
371
398
  `terradactyl install terraform --version=0.15.0-beta2`
372
399
 
373
400
  LONGDESC
@@ -391,21 +418,6 @@ module Terradactyl
391
418
  end
392
419
  end
393
420
  # rubocop:enable Metrics/AbcSize
394
-
395
- desc 'upgrade NAME', 'Upgrade an individual stack, by name'
396
- def upgrade(name)
397
- @stack ||= Stack.new(name)
398
- print_warning "Upgrading: #{@stack.name}"
399
- if @stack.upgrade.zero?
400
- print_ok "Upgraded: #{@stack.name}"
401
- else
402
- Stacks.error!(@stack)
403
- print_crit "Failed to upgrade: #{@stack.name}"
404
- end
405
- rescue Terradactyl::Terraform::Commands::UnsupportedCommandError => e
406
- print_crit "Error: #{e.message}"
407
- exit 1
408
- end
409
421
  end
410
422
  # rubocop:enable Metrics/ClassLength
411
423
  end
@@ -187,21 +187,70 @@ module Terradactyl
187
187
 
188
188
  private
189
189
 
190
+ def settings_files
191
+ Terradactyl::ConfigStack::TERRAFORM_SETTINGS_FILES.select do |file|
192
+ File.exist?(file)
193
+ end
194
+ end
195
+
196
+ def update_required_version(upgrade_version)
197
+ replace_me = /(?<assignment>(?:\n\s)*required_version\s+=\s+)(?<value>".*?")/m
198
+
199
+ settings_files.each do |file|
200
+ settings = File.read(file)
201
+ substitution = nil.to_s
202
+
203
+ if (req_version = settings.match(replace_me))
204
+ if file == 'versions.tf'
205
+ substitution = %(#{req_version[:assignment]}"~> #{upgrade_version}")
206
+ end
207
+ end
208
+
209
+ settings.sub!(replace_me, substitution)
210
+
211
+ File.write(file, settings)
212
+ end
213
+ end
214
+
215
+ def upgrade_notice
216
+ output = File.read('versions.tf')
217
+ insert = output.strip.split("\n").map { |l| " #{l}" }.join($INPUT_RECORD_SEPARATOR)
218
+
219
+ <<~NOTICE
220
+ This stack has been upgraded to version the described below and its
221
+ Terradactly config file (if it existed) has been removed.
222
+
223
+ #{insert}
224
+
225
+ NOTES:
226
+
227
+ • ALL Terraform version constraints are now specified in `versions.tf` using
228
+ the `required_version` directive.
229
+
230
+ • If your stack already containedo one or more `required_version` directives,
231
+ they have been consolidated into a single directive in `versions.tf`.
232
+
233
+ • Terraform provider version contraints ARE NOT upgraded automatically. You
234
+ will need to edit these MANUALLY.
235
+
236
+ • Before proceeding. please perform a `terradactyl quickplan` on your stack
237
+ to ensure the upgraded stack functions.
238
+ NOTICE
239
+ end
240
+
190
241
  def perform_upgrade
191
242
  options = command_options.tap { |dat| dat.yes = true }
192
243
  upgrade = Upgrade.new(dir_or_plan: nil, options: options)
193
- req_ver = /((?:\n\s)*required_version\s=\s)".*"/m
194
- result = upgrade.execute
195
244
 
196
- if result.zero?
197
- settings = File.read('versions.tf').lstrip
198
- settings.sub!(req_ver, %(#{Regexp.last_match(1)}"~> #{upgrade.version}"))
245
+ update_required_version(upgrade.version)
199
246
 
200
- if File.write('versions.tf', settings)
201
- FileUtils.rm_rf('terradactyl.yaml') if File.exist?('terradactyl.yaml')
202
- end
247
+ if (result = upgrade.execute).zero?
248
+ update_required_version(upgrade.version)
249
+ FileUtils.rm_rf('terradactyl.yaml') if File.exist?('terradactyl.yaml')
203
250
  end
204
251
 
252
+ print_content(upgrade_notice)
253
+
205
254
  result
206
255
  end
207
256
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terradactyl
4
- VERSION = '0.15.0'
4
+ VERSION = '0.15.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terradactyl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Warsing