lono-cfn 1.0.4 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cce00749152f718ccb8edc814ae3fc05c65d94f5
4
- data.tar.gz: d69c3c08a4165e3f8b77def7a06bc15dcb1a72be
3
+ metadata.gz: fc7cbd896929c57d603558a99e4b856f33afd5dc
4
+ data.tar.gz: 3421211ad8ced2927393fa288fe53106fae7107d
5
5
  SHA512:
6
- metadata.gz: e11817facf60121389255b1fa1aab57ab3051042faa6281bf356c1d0ab91c17c93d5cf7600d45ca32150a7c0b8c8a9d55245a35b415c4d091ac34b62adb0ea27
7
- data.tar.gz: ec3826d45cc9264034f20e38a0bc9c1b0e914013548f53e5a890eaf5f14094a5cfc42d98f05826dede05abf038884f919416512bc2d9aad0f9568cab6e60d624
6
+ metadata.gz: 396a93fe146ae84070e20fb6b357f1ac43062d835b0511f2d286ed0223470f45e7dc610de52ba7cc0ff1c255917d418372e56cb172c9b27676fadcd4f597ed25
7
+ data.tar.gz: 20311ea9620a5015cf588feb59e9dc2b102c0eb66052b1b5c6051fd2318c61a5d11ebeae890b71cceacd5d753439da0255d8521c6f4d1165dda4c18c95c876fb
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.1.0]
7
+
8
+ - add lono-cfn diff
9
+ - rename lono-cfn preview
10
+
6
11
  ## [1.0.4]
7
12
 
8
13
  - rename lono_cfn -> lono-cfn
@@ -22,7 +27,7 @@ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), eve
22
27
 
23
28
  ## [1.0.0]
24
29
 
25
- - add lono-cfn plan
30
+ - add lono-cfn preview
26
31
  - fix edge cases and show helpful error messages when stacks are not in updatable statuses
27
32
 
28
33
  ## [0.0.8]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lono-cfn (1.0.3)
4
+ lono-cfn (1.0.4)
5
5
  aws-sdk
6
6
  colorize
7
7
  hashie
data/README.md CHANGED
@@ -8,7 +8,7 @@ Wrapper cfn tool to quickly create CloudFormation stacks from [lono templates](h
8
8
  $ lono-cfn create my-stack-$(date +%s) --template my-template --params my-params
9
9
  $ lono-cfn update my-stack-1493859659 --template my-template --params my-params
10
10
  $ lono-cfn delete my-stack-1493859659 --sure
11
- $ lono-cfn plan my-stack-1493859659 --template template-name --params params-name
11
+ $ lono-cfn preview my-stack-1493859659 --template template-name --params params-name
12
12
  ```
13
13
 
14
14
  The above command:
@@ -26,7 +26,7 @@ These blog posts cover both lono and lono-cfn:
26
26
  * [AutoScaling CloudFormation Template with Lono](https://medium.com/boltops/autoscaling-cloudformation-template-with-lono-3dc520480c5f)
27
27
  * [CloudFormation Tools: lono, lono-params and lono-cfn Together
28
28
  ](https://medium.com/boltops/cloudformation-tools-lono-lono-params-and-lono-cfn-play-together-620af51e616)
29
- * [AWS CloudFormation dry-run with lono-cfn plan](https://medium.com/boltops/aws-cloudformation-dry-run-with-lono-cfn-plan-2a1e0f80d13c)
29
+ * [AWS CloudFormation dry-run with lono-cfn preview](https://medium.com/boltops/aws-cloudformation-dry-run-with-lono-cfn-preview-2a1e0f80d13c)
30
30
 
31
31
  ## Installation
32
32
 
@@ -117,19 +117,19 @@ $ lono-cfn update my-stack --template template-name --params params-name --sure
117
117
  $ lono-cfn delete my-stack --sure
118
118
  ```
119
119
 
120
- ### lono-cfn plan
120
+ ### lono-cfn preview
121
121
 
122
- If you want to see the CloudFormation plan without updating the stack you can also use the `lono-cfn plan` command.
122
+ If you want to see the CloudFormation preview without updating the stack you can also use the `lono-cfn preview` command.
123
123
 
124
124
  ```
125
- $ lono-cfn plan example --template single_instance --params single_instance
125
+ $ lono-cfn preview example --template single_instance --params single_instance
126
126
  Using template: output/single_instance.yml
127
127
  Using parameters: params/single_instance.txt
128
128
  Generating CloudFormation templates:
129
129
  ./output/single_instance.yml
130
130
  Params file generated for example at ./output/params/example.json
131
- Generating CloudFormation Change Set for plan.....
132
- CloudFormation plan for 'example' stack update. Changes:
131
+ Generating CloudFormation Change Set for preview.....
132
+ CloudFormation preview for 'example' stack update. Changes:
133
133
  Remove AWS::Route53::RecordSet: DnsRecord testsubdomain.sub.tongueroo.com
134
134
  $
135
135
  ```
@@ -16,5 +16,6 @@ module LonoCfn
16
16
  autoload :Create, 'lono-cfn/create'
17
17
  autoload :Update, 'lono-cfn/update'
18
18
  autoload :Delete, 'lono-cfn/delete'
19
- autoload :Plan, 'lono-cfn/plan'
19
+ autoload :Preview, 'lono-cfn/preview'
20
+ autoload :Diff, 'lono-cfn/diff'
20
21
  end
@@ -15,15 +15,19 @@ module LonoCfn
15
15
  params_name = options[:params] || template_name
16
16
  @template_path = get_source_path(template_name, :template)
17
17
  @params_path = get_source_path(params_name, :params)
18
- puts "Using template: #{@template_path}"
19
- puts "Using parameters: #{@params_path}"
18
+ puts "Using template: #{@template_path}" unless @options[:mute_using]
19
+ puts "Using parameters: #{@params_path}" unless @options[:mute_using]
20
20
  end
21
21
 
22
22
  def run
23
+ params = generate_all
24
+ save_stack(params) # defined in the sub class
25
+ end
26
+
27
+ def generate_all
23
28
  generate_templates if @options[:lono]
24
29
  check_for_errors
25
- params = generate_params if @options[:lono]
26
- save_stack(params) # defined in the sub class
30
+ generate_params(mute: @options[:mute_params])
27
31
  end
28
32
 
29
33
  def generate_templates
@@ -23,7 +23,8 @@ module LonoCfn
23
23
  desc "update STACK", "update a CloudFormation stack"
24
24
  long_desc Help.update
25
25
  option :change_set, type: :boolean, default: true, desc: "Uses generated change set to update the stack. If false, will perform normal update-stack."
26
- option :preview, type: :boolean, default: true, desc: "Prints preview of the stack changes before continuing."
26
+ option :diff, type: :boolean, default: true, desc: "Show diff of the source code template changes before continuing."
27
+ option :preview, type: :boolean, default: true, desc: "Show preview of the stack changes before continuing."
27
28
  option :sure, type: :boolean, desc: "Skips are you sure prompt"
28
29
  def update(name)
29
30
  Update.new(name, options).run
@@ -36,11 +37,19 @@ module LonoCfn
36
37
  Delete.new(name, options).run
37
38
  end
38
39
 
39
- desc "plan STACK", "preview a CloudFormation stack update"
40
- long_desc Help.plan
40
+ desc "preview STACK", "preview a CloudFormation stack update"
41
+ long_desc Help.preview
41
42
  option :keep, type: :boolean, desc: "keep the changeset instead of deleting it afterwards"
42
- def plan(name)
43
- Plan.new(name, options).run
43
+ option :diff, type: :boolean, default: true, desc: "Show diff of the source code template changes also."
44
+ def preview(name)
45
+ Diff.new(name, options).run if options[:diff]
46
+ Preview.new(name, options).run
47
+ end
48
+
49
+ desc "diff STACK", "diff of newly generated template vs existing template in AWS"
50
+ long_desc Help.diff
51
+ def diff(name)
52
+ Diff.new(name, options).run
44
53
  end
45
54
  end
46
55
  end
@@ -66,19 +66,29 @@ The above command will delete my-stack.
66
66
  EOL
67
67
  end
68
68
 
69
- def plan
69
+ def preview
70
70
  <<-EOL
71
- Generates a CloudFormation plan. This is similar to a `terraform plan` or puppet's dry-run mode.
71
+ Generates a CloudFormation preview. This is similar to a `terraform plan` or puppet's dry-run mode.
72
72
 
73
73
  Example output:
74
74
 
75
- CloudFormation plan for 'example' stack update. Changes:
75
+ CloudFormation preview for 'example' stack update. Changes:
76
76
 
77
77
  Remove AWS::Route53::RecordSet: DnsRecord testsubdomain.sub.tongueroo.com
78
78
 
79
79
  Examples:
80
80
 
81
- $ lono-cfn plan my-stack
81
+ $ lono-cfn preview my-stack
82
+ EOL
83
+ end
84
+
85
+ def diff
86
+ <<-EOL
87
+ Displays code diff of the generated CloudFormation template locally vs the existing template on AWS. You can set a desired diff viewer by setting the LONO_CFN_DIFF environment variable.
88
+
89
+ Examples:
90
+
91
+ $ lono-cfn diff my-stack
82
92
  EOL
83
93
  end
84
94
  end
@@ -0,0 +1,45 @@
1
+ module LonoCfn
2
+ class Diff < Base
3
+ include AwsServices
4
+
5
+ def run
6
+ if @options[:noop]
7
+ puts "NOOP Generating CloudFormation source code diff..."
8
+ else
9
+ generate_all # from Base superclass. Generates the output lono teplates
10
+ puts "Generating CloudFormation source code diff..."
11
+ download_existing_cfn_template
12
+ show_changes
13
+ end
14
+ end
15
+
16
+ def download_existing_cfn_template
17
+ resp = cfn.get_template(
18
+ stack_name: @stack_name,
19
+ template_stage: "Original"
20
+ )
21
+ resp.template_body
22
+ IO.write(existing_template_path, resp.template_body)
23
+ end
24
+
25
+ def show_changes
26
+ command = "#{diff_viewer} #{existing_template_path} #{new_cfn_template}"
27
+ puts "Running: #{command}"
28
+ system(command)
29
+ end
30
+
31
+ # for clarity
32
+ def new_cfn_template
33
+ @template_path
34
+ end
35
+
36
+ def diff_viewer
37
+ return ENV['LONO_CFN_DIFF'] if ENV['LONO_CFN_DIFF']
38
+ system("type colordiff > /dev/null") ? "colordiff" : "diff"
39
+ end
40
+
41
+ def existing_template_path
42
+ "/tmp/existing_cfn_template.json"
43
+ end
44
+ end
45
+ end
@@ -1,32 +1,25 @@
1
1
  module LonoCfn
2
2
  # Inherit from Base because the initializer is the same
3
- class Plan < Base
3
+ class Preview < Base
4
4
  include AwsServices
5
5
 
6
- def setup
7
- generate_templates if @options[:lono]
8
- check_for_errors
9
- @params = generate_params(mute: @options[:mute_params])
10
- end
11
-
12
- # Override run from Base superclass, the run method is different enough with Plan
6
+ # Override run from Base superclass, the run method is different enough with Preview
13
7
  def run
14
- setup
15
-
16
8
  if @options[:noop]
17
- puts "NOOP CloudFormation plan for #{@stack_name} update"
9
+ puts "NOOP CloudFormation preview for #{@stack_name} update"
18
10
  else
19
- preview_change_set
11
+ params = generate_all
12
+ preview_change_set(params)
20
13
  delete_change_set unless @options[:keep] # Clean up and delete the change set
21
14
  end
22
15
  end
23
16
 
24
- def preview_change_set
25
- create_change_set
17
+ def preview_change_set(params)
18
+ create_change_set(params)
26
19
  display_change_set
27
20
  end
28
21
 
29
- def create_change_set
22
+ def create_change_set(params)
30
23
  unless stack_exists?(@stack_name)
31
24
  puts "Cannot create a change set for the stack because the #{@stack_name} does not exists."
32
25
  return
@@ -34,26 +27,26 @@ module LonoCfn
34
27
  exist_unless_updatable(stack_status(@stack_name))
35
28
 
36
29
  template_body = IO.read(@template_path)
37
- begin
30
+ # begin
38
31
  cfn.create_change_set(
39
32
  change_set_name: change_set_name,
40
33
  stack_name: @stack_name,
41
34
  template_body: template_body,
42
- parameters: @params
35
+ parameters: params
43
36
  )
44
- rescue Aws::CloudFormation::Errors::ValidationError => e
45
- if e.message =~ /^Parameters: /
46
- puts "Error creating CloudFormation plan because invalid CloudFormation parameters. Full error message:".colorize(:red)
47
- puts e.message
48
- quit(1)
49
- else
50
- raise
51
- end
52
- end
37
+ # rescue Aws::CloudFormation::Errors::ValidationError => e
38
+ # if e.message =~ /^Parameters: /
39
+ # puts "Error creating CloudFormation preview because invalid CloudFormation parameters. Full error message:".colorize(:red)
40
+ # puts e.message
41
+ # quit(1)
42
+ # else
43
+ # raise
44
+ # end
45
+ # end
53
46
  end
54
47
 
55
48
  def display_change_set
56
- print "Generating CloudFormation Change Set for plan.."
49
+ print "Generating CloudFormation Change Set for preview.."
57
50
  change_set = describe_change_set
58
51
  until change_set_finished?(change_set) do
59
52
  change_set = describe_change_set
@@ -64,12 +57,12 @@ module LonoCfn
64
57
 
65
58
  case change_set.status
66
59
  when "CREATE_COMPLETE"
67
- puts "CloudFormation plan for '#{@stack_name}' stack update. Changes:"
60
+ puts "CloudFormation preview for '#{@stack_name}' stack update. Changes:"
68
61
  change_set.changes.each do |change|
69
62
  display_change(change)
70
63
  end
71
64
  when "FAILED"
72
- puts "Fail to create a CloudFormation plan for '#{@stack_name}' stack update. Reason:".colorize(:red)
65
+ puts "Fail to create a CloudFormation preview for '#{@stack_name}' stack update. Reason:".colorize(:red)
73
66
  puts change_set.status_reason
74
67
  quit(1)
75
68
  else
@@ -18,11 +18,12 @@ module LonoCfn
18
18
  if @options[:noop]
19
19
  message = "NOOP #{message}"
20
20
  else
21
- preview_changes if @options[:preview]
21
+ diff.run if @options[:diff]
22
+ preview.run if @options[:preview]
22
23
  are_you_sure?(:update)
23
24
 
24
25
  if @options[:change_set] # defaults to this
25
- message << " via change set: #{plan.change_set_name}"
26
+ message << " via change set: #{preview.change_set_name}"
26
27
  change_set_update
27
28
  else
28
29
  standard_update(params)
@@ -46,19 +47,17 @@ module LonoCfn
46
47
  end
47
48
  end
48
49
 
49
- def plan
50
- return @plan if @plan
51
- @plan = Plan.new(@stack_name, @options.merge(lono: false, mute_params: true))
52
- @plan.setup
53
- @plan
50
+ def preview
51
+ options = @options.merge(lono: false, mute_params: true, mute_using: true, keep: true)
52
+ @preview ||= Preview.new(@stack_name, options)
54
53
  end
55
54
 
56
- def preview_changes
57
- plan.preview_change_set
55
+ def diff
56
+ @diff ||= Diff.new(@stack_name, @options.merge(lono: false, mute_params: true, mute_using: true))
58
57
  end
59
58
 
60
59
  def change_set_update
61
- plan.execute_change_set
60
+ preview.execute_change_set
62
61
  end
63
62
  end
64
63
  end
@@ -1,3 +1,3 @@
1
1
  module LonoCfn
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -11,24 +11,29 @@ describe LonoCfn::CLI do
11
11
  end
12
12
 
13
13
  describe "lono-cfn" do
14
- it "creates stack" do
14
+ it "create stack" do
15
15
  out = execute("bin/lono-cfn create my-stack #{@args}")
16
16
  expect(out).to include("Creating")
17
17
  end
18
18
 
19
- it "updates stack" do
19
+ it "update stack" do
20
20
  out = execute("bin/lono-cfn update my-stack #{@args}")
21
21
  expect(out).to include("Updating")
22
22
  end
23
23
 
24
- it "deletes stack" do
24
+ it "delete stack" do
25
25
  out = execute("bin/lono-cfn delete my-stack #{@args}")
26
26
  expect(out).to include("Deleted")
27
27
  end
28
28
 
29
- it "plans stack" do
30
- out = execute("bin/lono-cfn plan my-stack #{@args}")
31
- expect(out).to include("CloudFormation plan")
29
+ it "preview stack" do
30
+ out = execute("bin/lono-cfn preview my-stack #{@args}")
31
+ expect(out).to include("CloudFormation preview")
32
+ end
33
+
34
+ it "diff stack" do
35
+ out = execute("bin/lono-cfn diff my-stack #{@args}")
36
+ expect(out).to include("diff")
32
37
  end
33
38
  end
34
39
  end
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.0.1]
7
+ - expose mute option
8
+
6
9
  ## [1.0.0]
7
10
  - allow --help or -h at the end of the command
8
11
  - rename lono_params -> lono-params
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lono-params (1.0.0)
4
+ lono-params (1.0.1)
5
5
  colorize
6
6
  hashie
7
7
  json
@@ -7,6 +7,7 @@ module LonoParams
7
7
  class CLI < Command
8
8
  class_option :verbose, type: :boolean
9
9
  class_option :noop, type: :boolean
10
+ class_option :mute, type: :boolean
10
11
  class_option :project_root, desc: "project root to use", default: '.'
11
12
 
12
13
  desc "generate NAME", "generate parameter json file for NAME"
@@ -72,7 +72,6 @@ module LonoParams
72
72
  end
73
73
 
74
74
  def write_output(json)
75
- puts "output_path #{output_path.inspect}"
76
75
  dir = File.dirname(output_path)
77
76
  FileUtils.mkdir_p(dir) unless File.exist?(dir)
78
77
  IO.write(output_path, json)
@@ -1,3 +1,3 @@
1
1
  module LonoParams
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono-cfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -180,7 +180,8 @@ files:
180
180
  - lib/lono-cfn/command.rb
181
181
  - lib/lono-cfn/create.rb
182
182
  - lib/lono-cfn/delete.rb
183
- - lib/lono-cfn/plan.rb
183
+ - lib/lono-cfn/diff.rb
184
+ - lib/lono-cfn/preview.rb
184
185
  - lib/lono-cfn/update.rb
185
186
  - lib/lono-cfn/util.rb
186
187
  - lib/lono-cfn/version.rb
@@ -208,6 +209,7 @@ files:
208
209
  - vendor/lono-params/lono-params.gemspec
209
210
  - vendor/lono-params/pkg/lono-params-0.0.6.gem
210
211
  - vendor/lono-params/pkg/lono-params-1.0.0.gem
212
+ - vendor/lono-params/pkg/lono-params-1.0.1.gem
211
213
  - vendor/lono-params/spec/fixtures/my_project/output/params/my-stack.json
212
214
  - vendor/lono-params/spec/fixtures/my_project/params/my-stack.txt
213
215
  - vendor/lono-params/spec/lib/cli_spec.rb