nexoform 0.0.4 → 0.1.0
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 +5 -5
- data/bin/nexoform +95 -9
- data/lib/nexoform/version.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8210b96451615b27d39e2bbafd827b34bbfe262872ada1622df46ca9b70ed143
|
4
|
+
data.tar.gz: '08d53cde72e871f596c3ecff3da95fdfc8ae8e24ab6ec1a26e3c862a5d08f0bd'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b116bdcf03e8520c33b245ababa552a6fe97dd68d12d1513f76870f953ea46f76e6fb47397bb464a313d19c105a86bf12d6b2b7190c11605fb05418a4376271a
|
7
|
+
data.tar.gz: 3d382aad3235762e85fba2ba7a10cab028735ddad098d8fa8856cbc08c6b38bf1facc130991e9c236330d70e5a5d8de7a3e3d77d11909d56283e7be4f8208db8
|
data/bin/nexoform
CHANGED
@@ -8,6 +8,8 @@ require 'thor'
|
|
8
8
|
require 'yaml'
|
9
9
|
require 'json'
|
10
10
|
require 'shellwords'
|
11
|
+
require 'erb'
|
12
|
+
require 'fileutils'
|
11
13
|
|
12
14
|
require 'nexoform'
|
13
15
|
|
@@ -37,7 +39,8 @@ class NexoformBin < Thor
|
|
37
39
|
long_desc <<-LONGDESC
|
38
40
|
Prints out any changes that will be made the next time
|
39
41
|
a nexoform apply is run. Under the hood, this command
|
40
|
-
runs a terraform plan.
|
42
|
+
runs a terraform plan. If you have ERB files, they will be
|
43
|
+
run through ERB to generate the output before running plan.
|
41
44
|
|
42
45
|
If you pass an arg to 'out' the plan will be saved to that filename.
|
43
46
|
If you pass '--save' or '-s' the plan will be saved to '#{default_plan_filename}'
|
@@ -60,7 +63,8 @@ class NexoformBin < Thor
|
|
60
63
|
desc 'apply', 'Apply changes (Runs a terraform apply)'
|
61
64
|
long_desc <<-LONGDESC
|
62
65
|
Applies any applicable changes. Under the hood, this command runs a
|
63
|
-
terraform apply.
|
66
|
+
terraform apply. If you have ERB files, they will be
|
67
|
+
run through ERB to generate the output before running plan.
|
64
68
|
|
65
69
|
If you pass --plan, the specified file will be used for the plan
|
66
70
|
If you pass --noplan, no plan file will be used
|
@@ -80,7 +84,8 @@ class NexoformBin < Thor
|
|
80
84
|
|
81
85
|
desc 'destroy', 'Destroy all provisioned resources (runs a terraform destroy)'
|
82
86
|
long_desc <<-LONGDESC
|
83
|
-
Destroys any resources that have been provisioned
|
87
|
+
Destroys any resources that have been provisioned. If you have ERB files,
|
88
|
+
they will be run through ERB to generate the output before running destroy.
|
84
89
|
|
85
90
|
> $ nexoform destroy
|
86
91
|
> $ nexoform destroy --environment 'dev'
|
@@ -92,11 +97,13 @@ class NexoformBin < Thor
|
|
92
97
|
desc 'output', 'Print any output from terraform'
|
93
98
|
long_desc <<-LONGDESC
|
94
99
|
Prints any output from last terraform state. Runs a 'terraform output'
|
100
|
+
If you have ERB files, they will be run through ERB to generate the output
|
101
|
+
before running plan.
|
95
102
|
|
96
103
|
> $ nexoform output
|
97
104
|
LONGDESC
|
98
105
|
def output
|
99
|
-
|
106
|
+
exec_output(options)
|
100
107
|
end
|
101
108
|
|
102
109
|
desc 'version', 'Check current installed version of nexoform'
|
@@ -130,6 +137,17 @@ class NexoformBin < Thor
|
|
130
137
|
exec_list_envs(options)
|
131
138
|
end
|
132
139
|
|
140
|
+
desc 'generate', 'Generate the raw terraform files for the environment but don\'t run terraform on them'
|
141
|
+
long_desc <<-LONGDESC
|
142
|
+
Generates the raw terraform files for the specified (or default) environment
|
143
|
+
but does not actually run terraform on them. This is useful for debugging/inspecting
|
144
|
+
|
145
|
+
> $ nexoform generate -e [environment]
|
146
|
+
LONGDESC
|
147
|
+
def generate
|
148
|
+
exec_generate(options)
|
149
|
+
end
|
150
|
+
|
133
151
|
private
|
134
152
|
|
135
153
|
def print_next_color(str)
|
@@ -177,6 +195,7 @@ class NexoformBin < Thor
|
|
177
195
|
config_file_present?
|
178
196
|
terraform_installed?
|
179
197
|
terraform_files_present?
|
198
|
+
# TODO: once plan_file_recent? is implemented, skip it for `nexoform generate`
|
180
199
|
plan_file_recent?(options)
|
181
200
|
end
|
182
201
|
|
@@ -312,8 +331,15 @@ class NexoformBin < Thor
|
|
312
331
|
"terraform apply #{varfile} #{planfile}"
|
313
332
|
end
|
314
333
|
|
334
|
+
def exec_output(options)
|
335
|
+
sanity_check(options)
|
336
|
+
generate_files(options, chdir: true) if has_erb_files?
|
337
|
+
execute('terraform output')
|
338
|
+
end
|
339
|
+
|
315
340
|
def exec_apply(options)
|
316
341
|
sanity_check(options)
|
342
|
+
generate_files(options, chdir: true) if has_erb_files? && !options[:plan]
|
317
343
|
options = prompt_for_plan_file(options)
|
318
344
|
exit_if_plan_file_should_but_does_not_exist(options)
|
319
345
|
unless options[:plan]
|
@@ -406,6 +432,7 @@ class NexoformBin < Thor
|
|
406
432
|
|
407
433
|
def exec_plan(options)
|
408
434
|
sanity_check(options)
|
435
|
+
generate_files(options, chdir: true) if has_erb_files?
|
409
436
|
options = prompt_for_save_file(options)
|
410
437
|
prompt_if_plan_file_exists(options)
|
411
438
|
run_init(options)
|
@@ -421,6 +448,7 @@ class NexoformBin < Thor
|
|
421
448
|
|
422
449
|
def exec_destroy(options)
|
423
450
|
sanity_check(options)
|
451
|
+
generate_files(options, chdir: true) if has_erb_files?
|
424
452
|
run_init(options)
|
425
453
|
run_refresh(options)
|
426
454
|
print_next_color '* Destroying any infrastructure resources ' \
|
@@ -480,15 +508,73 @@ class NexoformBin < Thor
|
|
480
508
|
end
|
481
509
|
puts
|
482
510
|
end
|
511
|
+
|
512
|
+
def exec_generate(options)
|
513
|
+
sanity_check(options)
|
514
|
+
generate_files(options, chdir: false)
|
515
|
+
end
|
516
|
+
|
517
|
+
def generate_files(options, chdir:)
|
518
|
+
print_next_color 'Generating terraform files ' \
|
519
|
+
'for environment: '
|
520
|
+
puts_next_color env(options)
|
521
|
+
|
522
|
+
clean_output_dir(options)
|
523
|
+
# find all .*.erb files, run them through erb and output the result
|
524
|
+
process_copy_erb_files(options)
|
525
|
+
# find all .* files (that don't end in erb) and copy them straight through
|
526
|
+
copy_other_files(options)
|
527
|
+
|
528
|
+
set_working_dir(options) if chdir
|
529
|
+
end
|
530
|
+
|
531
|
+
def copy_other_files(options)
|
532
|
+
Dir.glob('*')
|
533
|
+
.select { |f| !File.directory?(f) }
|
534
|
+
.select { |f| !(f =~ /\.erb$/i) }
|
535
|
+
.each { |f| FileUtils.cp(File.basename(f), output_dir(options)) }
|
536
|
+
end
|
537
|
+
|
538
|
+
def erb_file_to_out_file(f, options)
|
539
|
+
"#{output_dir(options)}/#{f.gsub(/\.erb$/i, '')}"
|
540
|
+
end
|
541
|
+
|
542
|
+
def process_copy_erb_files(options)
|
543
|
+
Dir.glob('*.erb').each do |f|
|
544
|
+
header = "# This file was generated by nexoform. Changes will be lost\n"
|
545
|
+
content = ERB.new(File.read(f), 0, "%<>").result(binding)
|
546
|
+
File.write(erb_file_to_out_file(f, options), "#{header}#{content}")
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
def clean_output_dir(options)
|
551
|
+
od = output_dir(options)
|
552
|
+
if Dir.exist?(od)
|
553
|
+
FileUtils.remove_dir(od)
|
554
|
+
end
|
555
|
+
FileUtils.mkdir_p(od)
|
556
|
+
end
|
557
|
+
|
558
|
+
def output_dir(options)
|
559
|
+
"#{Dir.pwd}/#{env(options)}"
|
560
|
+
end
|
561
|
+
|
562
|
+
def has_erb_files?
|
563
|
+
Dir.glob('*.erb').count > 0
|
564
|
+
end
|
565
|
+
|
566
|
+
def set_working_dir(optioons)
|
567
|
+
Dir.chdir(output_dir(options)) if has_erb_files?
|
568
|
+
end
|
483
569
|
end
|
484
570
|
|
485
571
|
if !ARGV.empty? && %w[-v --version].include?(ARGV.first)
|
486
572
|
puts "Nexoform - Version: #{Nexoform.version}"
|
487
573
|
else
|
488
|
-
begin
|
574
|
+
#begin
|
489
575
|
NexoformBin.start(ARGV)
|
490
|
-
rescue StandardError => e
|
491
|
-
|
492
|
-
|
493
|
-
end
|
576
|
+
#rescue StandardError => e
|
577
|
+
# puts "* Encountered an error. Make sure your config-file isn't messed up".red
|
578
|
+
# puts "\n* Exception message: #{e.message}".yellow
|
579
|
+
#end
|
494
580
|
end
|
data/lib/nexoform/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexoform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.20.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.20.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.6
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Environment aware wrapping for Terraform
|