cloudspin-stack 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: c885e8c2a9014973458e691e79b350769043e562
4
- data.tar.gz: d008d0062896585c367f314110768f02ab6325b5
3
+ metadata.gz: '09f576357a24456f36f68485eb0cdfcc4236e953'
4
+ data.tar.gz: 4d014c6c8978d8e0465174fc313c4d301f614f0e
5
5
  SHA512:
6
- metadata.gz: 8f1cea03a705b02c92e805dcbb9de31a698e93f9f1865bd8fc9bdb60f84d8a6dd4e0e14ed9f8a4901d358c5a629f1ac6adb75cee03029e8f1313e83748557247
7
- data.tar.gz: 06c98e0cdaec56f173cdb2c90401cb10a05964c76ada6226c6ccf3d9835ecc13503827cde70abb1f09c67fa2a6181d6c629ea93dc18596d1ff6b9078f8090544
6
+ metadata.gz: 591b428a3e10c2d7e8c753120c7bb29c5bc3a53b336aeb1046359011e0d9ccee679db5a58aec5f6298d072d70c9ce7f4ae363f381fd8fd280279dc194a4cba51
7
+ data.tar.gz: c8e033b0cff15d03bf9d07086d7aaeb85082a234f5e31439d8ae31142316f837cfe83e62b94c76da6b3ef03f37c48357345629e992163008cd4f8e6ffdd020f6
@@ -10,43 +10,38 @@ module Cloudspin
10
10
  :banner => 'YAML-CONFIG-FILE',
11
11
  :type => :array,
12
12
  :default => [
13
- Util.full_path_to('spin-default.yaml'),
14
- Util.full_path_to('spin-local.yaml')
13
+ Util.full_path_from_local('spin-default.yaml'),
14
+ Util.full_path_from_local('spin-local.yaml')
15
15
  ],
16
16
  :desc => 'A list of configuration files to load for the stack instance. Values in files listed later override those from earlier files.'
17
17
 
18
18
  class_option :terraform_source,
19
19
  :aliases => '-t',
20
20
  :banner => 'PATH',
21
- :default => Util.full_path_to('./src'),
21
+ :default => Util.full_path_from_local('./src'),
22
22
  :desc => 'Folder with the terraform project source files'
23
23
 
24
24
  class_option :work,
25
25
  :aliases => '-w',
26
26
  :banner => 'PATH',
27
- :default => Util.full_path_to('./work'),
27
+ :default => Util.full_path_from_local('./work'),
28
28
  :desc => 'Folder to create and copy working files into'
29
29
 
30
30
  class_option :state,
31
31
  :aliases => '-s',
32
32
  :banner => 'PATH',
33
- :default => Util.full_path_to('./state'),
33
+ :default => Util.full_path_from_local('./state'),
34
34
  :desc => 'Folder to create and store local state'
35
35
 
36
- desc 'plan', 'Print the changes that will by applied when the \'up\' command is run'
37
- option :dry, :type => :boolean, :default => false
38
- def plan
39
- if options[:dry]
40
- puts instance.plan_dry
41
- else
42
- instance.plan
43
- end
44
- end
45
-
46
36
  desc 'up', 'Create or update the stack instance'
47
37
  option :dry, :type => :boolean, :default => false
38
+ option :plan, :type => :boolean, :default => false
48
39
  def up
49
- if options[:dry]
40
+ if options[:plan] && options[:dry]
41
+ puts instance.plan_dry
42
+ elsif options[:plan] && ! options[:dry]
43
+ puts instance.plan
44
+ elsif ! options[:plan] && options[:dry]
50
45
  puts instance.up_dry
51
46
  else
52
47
  instance.up
@@ -54,8 +49,18 @@ module Cloudspin
54
49
  end
55
50
 
56
51
  desc 'down', 'Destroy the stack instance'
52
+ option :dry, :type => :boolean, :default => false
53
+ option :plan, :type => :boolean, :default => false
57
54
  def down
58
- instance.down
55
+ if options[:plan] && options[:dry]
56
+ puts instance.plan_dry(plan_destroy: true)
57
+ elsif options[:plan] && ! options[:dry]
58
+ puts instance.plan(plan_destroy: true)
59
+ elsif ! options[:plan] && options[:dry]
60
+ puts instance.down_dry
61
+ else
62
+ instance.down
63
+ end
59
64
  end
60
65
 
61
66
  desc 'version', 'Print the version number'
@@ -40,23 +40,25 @@ module Cloudspin
40
40
  add_resource_values(config['resources']) if config['resources']
41
41
  end
42
42
 
43
- def plan
43
+ def plan(plan_destroy: false)
44
44
  RubyTerraform.clean(directory: working_folder)
45
45
  mkdir_p File.dirname(working_folder)
46
46
  cp_r @stack_definition.terraform_source_path, working_folder
47
47
  Dir.chdir(working_folder) do
48
48
  RubyTerraform.init(backend_config: backend_config)
49
49
  RubyTerraform.plan(
50
+ destroy: plan_destroy,
50
51
  state: terraform_statefile,
51
52
  vars: terraform_variables
52
53
  )
53
54
  end
54
55
  end
55
56
 
56
- def plan_dry
57
+ def plan_dry(plan_destroy: false)
57
58
  plan_command = RubyTerraform::Commands::Plan.new
58
59
  command_line_builder = plan_command.instantiate_builder
59
60
  configured_command = plan_command.configure_command(command_line_builder, {
61
+ :destroy => plan_destroy,
60
62
  :state => terraform_statefile,
61
63
  :vars => terraform_variables
62
64
  })
@@ -103,6 +105,17 @@ module Cloudspin
103
105
  end
104
106
  end
105
107
 
108
+ def down_dry
109
+ down_command = RubyTerraform::Commands::Destroy.new
110
+ command_line_builder = down_command.instantiate_builder
111
+ configured_command = down_command.configure_command(command_line_builder, {
112
+ :state => terraform_statefile,
113
+ :vars => terraform_variables
114
+ })
115
+ built_command = configured_command.build
116
+ built_command.to_s
117
+ end
118
+
106
119
  def terraform_variables
107
120
  @parameter_values.merge(@resource_values) { |key, oldval, newval|
108
121
  raise "Duplicate values for terraform variable '#{key}' ('#{oldval}' and '#{newval}')"
@@ -1,5 +1,5 @@
1
1
  module Cloudspin
2
2
  module Stack
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
@@ -1,7 +1,16 @@
1
1
  module Cloudspin
2
2
  class Util
3
- def self.full_path_to(relative_path)
4
- Pathname.new(Dir.pwd + '/' + relative_path).realpath.to_s
3
+ def self.full_path_from_local(relative_path)
4
+ raw_path = self.raw_path_from_local(relative_path)
5
+ if File.exists?(raw_path)
6
+ Pathname.new(raw_path).realpath.to_s
7
+ else
8
+ relative_path
9
+ end
10
+ end
11
+
12
+ def self.raw_path_from_local(relative_path)
13
+ Dir.pwd + '/' + relative_path
5
14
  end
6
15
  end
7
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudspin-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'kief '