lono-cfn 0.0.3 → 0.0.4

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: 2bf84b20c1282ec13d59fd62885d1fba43bdbcde
4
- data.tar.gz: ffd102241da5df42ed250f7915f45a69868588d1
3
+ metadata.gz: 9c6dad389b3fefe174cc4e2b1e5e2f400e1cfe7a
4
+ data.tar.gz: 551b23221bb7208f57ace0517a7b4b1e01e02b4c
5
5
  SHA512:
6
- metadata.gz: 93e1da08ad74beac891b830aa50a4798b6c4cbbb5eb6d34c84fe62c12864467918609e283f3679c076e0403d5c935b9b202b626f4f9170f9bae64cef94f582d9
7
- data.tar.gz: f3ac0486f5da76f20468df99b59666f5096ceb21534a6d6549cc95751dd083dbcebf9dcebbefd0ceaec42a65ff62cd6ee56480bf1ce7fff82ac13c6bee244a62
6
+ metadata.gz: 62cc0595fac727b77bc1152aaab946899b5d057fad75d314d16d4440c9425193d172a47c12c3aaa325071a3796f27e009e00c53766ea5c29504ad8a24514c023
7
+ data.tar.gz: 6d776ab590dbc1aad9bc5ca6419726c434daffcf58ba53133a7d20ba51c2aa6d24eb960651c2e5974075268a4d6636ff388484336964f59c6687f9076c58c847
@@ -15,8 +15,6 @@ module LonoCfn
15
15
  @params_path = get_source_path(params_name, :params)
16
16
  puts "Using template: #{@template_path}"
17
17
  puts "Using parameters: #{@params_path}"
18
-
19
- @region = options[:region] || 'us-east-1'
20
18
  end
21
19
 
22
20
  def run
@@ -37,13 +35,13 @@ module LonoCfn
37
35
  generator = LonoParams::Generator.new(@stack_name,
38
36
  project_root: @project_root,
39
37
  path: @params_path,
40
- allow_no_file: true)
38
+ allow_no_file: false)
41
39
  generator.generate # Writes the json file in CamelCase keys format
42
40
  generator.params # Returns Array in underscore keys format
43
41
  end
44
42
 
45
43
  def cfn
46
- @cfn ||= Aws::CloudFormation::Client.new(region: @region)
44
+ @cfn ||= Aws::CloudFormation::Client.new
47
45
  end
48
46
 
49
47
  def check_for_errors
@@ -66,6 +64,23 @@ module LonoCfn
66
64
  errors
67
65
  end
68
66
 
67
+ def stack_exists?
68
+ return if @options[:noop]
69
+
70
+ exist = true
71
+ begin
72
+ # When the stack does not exist an exception is raised. Example:
73
+ # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
74
+ response = cfn.describe_stacks(stack_name: @stack_name)
75
+ rescue Aws::CloudFormation::Errors::ValidationError => e
76
+ e.message
77
+ if e.message =~ /Stack with/ || e.message =~ /does not exist/
78
+ exist = false
79
+ end
80
+ end
81
+ exist
82
+ end
83
+
69
84
  # if existing in params path then use that
70
85
  # if it doesnt assume it is a full path and check that
71
86
  # else fall back to convention, which also eventually gets checked in check_for_errors
@@ -7,6 +7,7 @@ module LonoCfn
7
7
  class_option :verbose, type: :boolean
8
8
  class_option :noop, type: :boolean
9
9
  class_option :project_root, desc: "Project folder. Defaults to current directory", default: '.'
10
+ class_option :region, desc: "AWS region"
10
11
 
11
12
  # common to create and update
12
13
  class_option :template, desc: 'override convention and specify the template file to use'
@@ -26,11 +26,5 @@ module LonoCfn
26
26
  end
27
27
  puts message unless @options[:mute]
28
28
  end
29
-
30
- def stack_exists?
31
- return if @options[:noop]
32
- stack = cfn.describe_stacks(stack_name: @stack_name).stacks.first
33
- !!stack
34
- end
35
29
  end
36
30
  end
@@ -7,6 +7,11 @@ module LonoCfn
7
7
 
8
8
  # aws cloudformation update-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
9
9
  def update_stack(params)
10
+ unless stack_exists?
11
+ puts "Cannot update a stack because the #{@stack_name} does not exists."
12
+ return
13
+ end
14
+
10
15
  template_body = IO.read(@template_path)
11
16
  message = "#{@stack_name} stack updating."
12
17
  if @options[:noop]
@@ -1,3 +1,3 @@
1
1
  module LonoCfn
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono-cfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.6.4
220
+ rubygems_version: 2.6.8
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: Wrapper cfn tool to quickly create CloudFormation stacks from lono templates