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 +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +7 -7
- data/lib/lono-cfn.rb +2 -1
- data/lib/lono-cfn/base.rb +8 -4
- data/lib/lono-cfn/cli.rb +14 -5
- data/lib/lono-cfn/cli/help.rb +14 -4
- data/lib/lono-cfn/diff.rb +45 -0
- data/lib/lono-cfn/{plan.rb → preview.rb} +22 -29
- data/lib/lono-cfn/update.rb +9 -10
- data/lib/lono-cfn/version.rb +1 -1
- data/spec/lib/cli_spec.rb +11 -6
- data/vendor/lono-params/CHANGELOG.md +3 -0
- data/vendor/lono-params/Gemfile.lock +1 -1
- data/vendor/lono-params/lib/lono-params/cli.rb +1 -0
- data/vendor/lono-params/lib/lono-params/generator.rb +0 -1
- data/vendor/lono-params/lib/lono-params/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc7cbd896929c57d603558a99e4b856f33afd5dc
|
4
|
+
data.tar.gz: 3421211ad8ced2927393fa288fe53106fae7107d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396a93fe146ae84070e20fb6b357f1ac43062d835b0511f2d286ed0223470f45e7dc610de52ba7cc0ff1c255917d418372e56cb172c9b27676fadcd4f597ed25
|
7
|
+
data.tar.gz: 20311ea9620a5015cf588feb59e9dc2b102c0eb66052b1b5c6051fd2318c61a5d11ebeae890b71cceacd5d753439da0255d8521c6f4d1165dda4c18c95c876fb
|
data/CHANGELOG.md
CHANGED
@@ -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
|
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]
|
data/Gemfile.lock
CHANGED
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
|
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
|
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
|
120
|
+
### lono-cfn preview
|
121
121
|
|
122
|
-
If you want to see the CloudFormation
|
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
|
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
|
132
|
-
CloudFormation
|
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
|
```
|
data/lib/lono-cfn.rb
CHANGED
data/lib/lono-cfn/base.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/lono-cfn/cli.rb
CHANGED
@@ -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 :
|
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 "
|
40
|
-
long_desc Help.
|
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
|
-
|
43
|
-
|
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
|
data/lib/lono-cfn/cli/help.rb
CHANGED
@@ -66,19 +66,29 @@ The above command will delete my-stack.
|
|
66
66
|
EOL
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
69
|
+
def preview
|
70
70
|
<<-EOL
|
71
|
-
Generates a CloudFormation
|
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
|
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
|
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
|
3
|
+
class Preview < Base
|
4
4
|
include AwsServices
|
5
5
|
|
6
|
-
|
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
|
9
|
+
puts "NOOP CloudFormation preview for #{@stack_name} update"
|
18
10
|
else
|
19
|
-
|
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:
|
35
|
+
parameters: params
|
43
36
|
)
|
44
|
-
rescue Aws::CloudFormation::Errors::ValidationError => e
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
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
|
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
|
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
|
data/lib/lono-cfn/update.rb
CHANGED
@@ -18,11 +18,12 @@ module LonoCfn
|
|
18
18
|
if @options[:noop]
|
19
19
|
message = "NOOP #{message}"
|
20
20
|
else
|
21
|
-
|
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: #{
|
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
|
50
|
-
|
51
|
-
@
|
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
|
57
|
-
|
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
|
-
|
60
|
+
preview.execute_change_set
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
data/lib/lono-cfn/version.rb
CHANGED
data/spec/lib/cli_spec.rb
CHANGED
@@ -11,24 +11,29 @@ describe LonoCfn::CLI do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "lono-cfn" do
|
14
|
-
it "
|
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 "
|
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 "
|
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 "
|
30
|
-
out = execute("bin/lono-cfn
|
31
|
-
expect(out).to include("CloudFormation
|
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
|
@@ -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"
|
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
|
+
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/
|
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
|