lono-cfn 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +8 -8
- data/README.md +24 -7
- data/lib/lono-cfn.rb +2 -0
- data/lib/lono_cfn/base.rb +93 -0
- data/lib/lono_cfn/cli/help.rb +27 -0
- data/lib/lono_cfn/cli.rb +11 -3
- data/lib/lono_cfn/create.rb +14 -90
- data/lib/lono_cfn/update.rb +25 -0
- data/lib/lono_cfn/version.rb +2 -2
- data/spec/lib/cli_spec.rb +7 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ffa1032d935ae7276a2500f96b1194582d0d53
|
4
|
+
data.tar.gz: 12ad9b4d32e1093bc1a52fa6ae05651f5a633866
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19148e7e7e85bc34bc2024e3beac7e25a8e5a12aa34c3733267fd8075b40f9b14bcb411d4b04f52636c2711358559e4817f38e0fdfc41d9b3b87019e8fe09c1d
|
7
|
+
data.tar.gz: 0c3a39eb67e4bb16acf08256545916eae5593765c5557a38f614469ded37866f1bce1a3eafe15033a914a43ab66cc52a7d0ad460b23ce4d6aea19518936a9441
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
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
|
+
## [0.0.2] lono-cfn update
|
7
|
+
|
8
|
+
- `lono-cfn update` implemented.
|
9
|
+
|
6
10
|
## [0.0.1] Initial Release
|
7
11
|
|
8
|
-
- Initial release
|
12
|
+
- Initial release: `lono-cfn create`.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lono-cfn (0.0.
|
4
|
+
lono-cfn (0.0.2)
|
5
5
|
aws-sdk
|
6
6
|
colorize
|
7
7
|
hashie
|
@@ -21,12 +21,12 @@ GEM
|
|
21
21
|
multi_json (~> 1.3)
|
22
22
|
thread_safe (~> 0.1)
|
23
23
|
tzinfo (~> 0.3.37)
|
24
|
-
aws-sdk (2.6.
|
25
|
-
aws-sdk-resources (= 2.6.
|
26
|
-
aws-sdk-core (2.6.
|
24
|
+
aws-sdk (2.6.5)
|
25
|
+
aws-sdk-resources (= 2.6.5)
|
26
|
+
aws-sdk-core (2.6.5)
|
27
27
|
jmespath (~> 1.0)
|
28
|
-
aws-sdk-resources (2.6.
|
29
|
-
aws-sdk-core (= 2.6.
|
28
|
+
aws-sdk-resources (2.6.5)
|
29
|
+
aws-sdk-core (= 2.6.5)
|
30
30
|
builder (3.1.4)
|
31
31
|
codeclimate-test-reporter (0.6.0)
|
32
32
|
simplecov (>= 0.7.1, < 1.0.0)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
69
69
|
rb-inotify (~> 0.9, >= 0.9.7)
|
70
70
|
ruby_dep (~> 1.2)
|
71
|
-
lono (0.5.
|
71
|
+
lono (0.5.2)
|
72
72
|
colorize
|
73
73
|
guard
|
74
74
|
guard-cloudformation
|
@@ -77,7 +77,7 @@ GEM
|
|
77
77
|
rake
|
78
78
|
rb-fsevent
|
79
79
|
thor
|
80
|
-
lono-params (0.0.
|
80
|
+
lono-params (0.0.4)
|
81
81
|
colorize
|
82
82
|
hashie
|
83
83
|
plissken
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Lono Cfn
|
2
2
|
|
3
|
-
Wrapper cfn tool to quickly create CloudFormation stacks from lono templates and params files.
|
3
|
+
Wrapper cfn tool to quickly create CloudFormation stacks from [lono templates](https://github.com/tongueroo/lono) and [lono-params](https://github.com/tongueroo/lono-params) files. Example:
|
4
4
|
|
5
5
|
```bash
|
6
6
|
$ bundle exec lono-cfn create my-stack-$(date +%s) --template my-template --params my-params
|
@@ -12,7 +12,7 @@ The above command:
|
|
12
12
|
2. Generate a parameters file from the params/my-params.txt.
|
13
13
|
3. Launch the CloudFormation stack with those parameters.
|
14
14
|
|
15
|
-
This tool is meant to be used in conjuction with [lono](https://github.com/tongueroo/lono) but can also be used separately with the `--no-lono` flag, which skips the `lono generate`
|
15
|
+
This tool is meant to be used in conjuction with [lono](https://github.com/tongueroo/lono) but can also be used separately with the `--no-lono` flag, which skips the `lono generate` step.
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
@@ -36,15 +36,32 @@ Provided that you are in a lono project and have a `my-stack` lono template defi
|
|
36
36
|
$ lono-cfn create my-stack
|
37
37
|
```
|
38
38
|
|
39
|
-
The above command will generate and use the template in output/my-stack.json and parameters in params/my-stack.txt.
|
39
|
+
The above command will generate and use the template in output/my-stack.json and parameters in params/my-stack.txt.
|
40
40
|
|
41
|
-
|
41
|
+
### Conventions
|
42
42
|
|
43
|
-
|
43
|
+
The template by convention defaults to the name of the stack. In turn, the params by convention defaults to the name of the template in turn.
|
44
|
+
|
45
|
+
* stack - This is a required parameter and is the CLI first parameter.
|
44
46
|
* template - By convention matches the stack name but can be overriden with `--template`.
|
45
|
-
* params
|
47
|
+
* params - By convention matches the template name but can be overriden with `--params`.
|
48
|
+
|
49
|
+
The conventions allows the command to be a very nice short command that can be easily remembered. For example, these 2 commands are the same:
|
50
|
+
|
51
|
+
Long form:
|
52
|
+
|
53
|
+
```
|
54
|
+
$ lono-cfn create my-stack --template my-stack --params --my-stack
|
55
|
+
```
|
56
|
+
|
57
|
+
Short form:
|
58
|
+
|
59
|
+
```
|
60
|
+
$ lono-cfn create my-stack
|
61
|
+
```
|
62
|
+
|
46
63
|
|
47
|
-
Here are examples of overriding the template and params name conventions.
|
64
|
+
Both template and params conventions can be overridden. Here are examples of overriding the template and params name conventions.
|
48
65
|
|
49
66
|
```
|
50
67
|
$ lono-cfn create my-stack --template different-name1
|
data/lib/lono-cfn.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "lono"
|
2
|
+
require "lono-params"
|
3
|
+
require "aws-sdk"
|
4
|
+
|
5
|
+
module LonoCfn
|
6
|
+
class Base
|
7
|
+
def initialize(stack_name, options={})
|
8
|
+
@stack_name = stack_name
|
9
|
+
@options = options
|
10
|
+
@project_root = options[:project_root] || '.'
|
11
|
+
|
12
|
+
template_name = options[:template] || @stack_name
|
13
|
+
params_name = options[:params] || template_name
|
14
|
+
@template_path = get_source_path(template_name, :template)
|
15
|
+
@params_path = get_source_path(params_name, :params)
|
16
|
+
puts "Using template: #{@template_path}"
|
17
|
+
puts "Using parameters: #{@params_path}"
|
18
|
+
|
19
|
+
@region = options[:region] || 'us-east-1'
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
generate_templates if @options[:lono]
|
24
|
+
check_for_errors
|
25
|
+
params = generate_params
|
26
|
+
save_stack(params) # defined in the sub class
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_templates
|
30
|
+
Lono::DSL.new(
|
31
|
+
project_root: @project_root,
|
32
|
+
pretty: true
|
33
|
+
).run
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_params
|
37
|
+
generator = LonoParams::Generator.new(@stack_name,
|
38
|
+
project_root: @project_root,
|
39
|
+
path: @params_path,
|
40
|
+
allow_no_file: true)
|
41
|
+
generator.generate # Writes the json file in CamelCase keys format
|
42
|
+
generator.params # Returns Array in underscore keys format
|
43
|
+
end
|
44
|
+
|
45
|
+
def cfn
|
46
|
+
@cfn ||= Aws::CloudFormation::Client.new(region: @region)
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_for_errors
|
50
|
+
errors = check_files
|
51
|
+
unless errors.empty?
|
52
|
+
puts "Please double check the command you ran. There were some errors."
|
53
|
+
puts "#{errors.join("\n")}"
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_files
|
59
|
+
errors = []
|
60
|
+
unless File.exist?(@template_path)
|
61
|
+
errors << "Template file missing: could not find #{@template_path}"
|
62
|
+
end
|
63
|
+
if @options[:params] && !File.exist?(@params_path)
|
64
|
+
errors << "Parameters file missing: could not find #{@params_path}"
|
65
|
+
end
|
66
|
+
errors
|
67
|
+
end
|
68
|
+
|
69
|
+
# if existing in params path then use that
|
70
|
+
# if it doesnt assume it is a full path and check that
|
71
|
+
# else fall back to convention, which also eventually gets checked in check_for_errors
|
72
|
+
#
|
73
|
+
# Type - :params or :template
|
74
|
+
def get_source_path(path, type)
|
75
|
+
default_convention_path = convention_path(@stack_name, type)
|
76
|
+
|
77
|
+
return default_convention_path if path.nil?
|
78
|
+
# convention path based on the input from the user
|
79
|
+
convention_path(path, type)
|
80
|
+
end
|
81
|
+
|
82
|
+
def convention_path(name, type)
|
83
|
+
case type
|
84
|
+
when :template
|
85
|
+
"#{@project_root}/output/#{name}.json"
|
86
|
+
when :params
|
87
|
+
"#{@project_root}/params/#{name}.txt"
|
88
|
+
else
|
89
|
+
raise "hell: dont come here"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/lono_cfn/cli/help.rb
CHANGED
@@ -26,6 +26,33 @@ $ lono-cfn create my-stack --template different-name3 --params different-name4
|
|
26
26
|
|
27
27
|
The template that will be use is output/different-name3.json and the parameters will use params/different-name4.json.
|
28
28
|
|
29
|
+
EOL
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
<<-EOL
|
34
|
+
Examples:
|
35
|
+
|
36
|
+
Provided that you are in a lono project and have a `my-stack` lono template definition. To update a stack you can simply run:
|
37
|
+
|
38
|
+
$ lono-cfn update my-stack
|
39
|
+
|
40
|
+
The above command will generate and use the template in output/my-stack.json and parameters in params/my-stack.txt. The template defaults by convention to the name of the stack. The params defaults by convention to the name of the template in turn. The convention allows the command to be a very nice short command that can be easily remembered. Both conventions can be overridden.
|
41
|
+
|
42
|
+
Here are examples of overriding the template and params name conventions.
|
43
|
+
|
44
|
+
$ lono-cfn update my-stack --template different-name1
|
45
|
+
|
46
|
+
The template that will be use is output/different-name1.json and the parameters will use params/different-name1.json.
|
47
|
+
|
48
|
+
$ lono-cfn update my-stack --params different-name2
|
49
|
+
|
50
|
+
The template that will be use is output/different-name2.json and the parameters will use params/different-name2.json.
|
51
|
+
|
52
|
+
$ lono-cfn update my-stack --template different-name3 --params different-name4
|
53
|
+
|
54
|
+
The template that will be use is output/different-name3.json and the parameters will use params/different-name4.json.
|
55
|
+
|
29
56
|
EOL
|
30
57
|
end
|
31
58
|
end
|
data/lib/lono_cfn/cli.rb
CHANGED
@@ -8,13 +8,21 @@ module LonoCfn
|
|
8
8
|
class_option :noop, type: :boolean
|
9
9
|
class_option :project_root, desc: "Project folder. Defaults to current directory", default: '.'
|
10
10
|
|
11
|
+
# common to create and update
|
12
|
+
class_option :template, desc: 'override convention and specify the template file to use'
|
13
|
+
class_option :params, desc: 'override convention and specify the params file to use'
|
14
|
+
class_option :lono, type: :boolean, desc: 'invoke lono to generate CloudFormation templates', default: true
|
15
|
+
|
11
16
|
desc "create STACK", "create a CloudFormation stack"
|
12
17
|
long_desc Help.create
|
13
|
-
option :template, desc: 'override convention and specify the template file to use'
|
14
|
-
option :params, desc: 'override convention and specify the params file to use'
|
15
|
-
option :lono, type: :boolean, desc: 'invoke lono to generate CloudFormation templates', default: true
|
16
18
|
def create(name)
|
17
19
|
Create.new(name, options).run
|
18
20
|
end
|
21
|
+
|
22
|
+
desc "update STACK", "update a CloudFormation stack"
|
23
|
+
long_desc Help.update
|
24
|
+
def update(name)
|
25
|
+
Update.new(name, options).run
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
data/lib/lono_cfn/create.rb
CHANGED
@@ -1,53 +1,19 @@
|
|
1
|
-
require "lono"
|
2
|
-
require "lono-params"
|
3
|
-
require "aws-sdk"
|
4
|
-
|
5
1
|
module LonoCfn
|
6
|
-
class Create
|
7
|
-
|
8
|
-
|
9
|
-
@options = options
|
10
|
-
@project_root = options[:project_root] || '.'
|
11
|
-
|
12
|
-
template_name = options[:template] || @stack_name
|
13
|
-
params_name = options[:params] || template_name
|
14
|
-
@template_path = get_source_path(template_name, :template)
|
15
|
-
@params_path = get_source_path(params_name, :params)
|
16
|
-
puts "Using template: #{@template_path}"
|
17
|
-
puts "Using parameters: #{@params_path}"
|
18
|
-
|
19
|
-
@region = options[:region] || 'us-east-1'
|
20
|
-
end
|
21
|
-
|
22
|
-
def run
|
23
|
-
generate_templates if @options[:lono]
|
24
|
-
check_for_errors
|
25
|
-
params = generate_params
|
2
|
+
class Create < Base
|
3
|
+
# save_stack is the interface method
|
4
|
+
def save_stack(params)
|
26
5
|
create_stack(params)
|
27
6
|
end
|
28
7
|
|
29
|
-
|
30
|
-
Lono::DSL.new(
|
31
|
-
project_root: @project_root,
|
32
|
-
pretty: true
|
33
|
-
).run
|
34
|
-
end
|
35
|
-
|
36
|
-
def generate_params
|
37
|
-
generator = LonoParams::Generator.new(@stack_name,
|
38
|
-
project_root: @project_root,
|
39
|
-
path: @params_path,
|
40
|
-
allow_blank: true)
|
41
|
-
generator.generate # Writes the json file in CamelCase keys format
|
42
|
-
generator.params # Returns Array in underscore keys format
|
43
|
-
end
|
44
|
-
|
45
|
-
# aws cloudformation create-stack --stack-name cluster-hi \
|
46
|
-
# --template-body file://output/cluster-hi.json \
|
47
|
-
# --parameters file://parameters/output/cluster-hi.json
|
8
|
+
# aws cloudformation create-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
|
48
9
|
def create_stack(params)
|
10
|
+
if stack_exists?
|
11
|
+
puts "Cannot create a stack because the #{@stack_name} already exists."
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
49
15
|
template_body = IO.read(@template_path)
|
50
|
-
message = "#{@stack_name} stack
|
16
|
+
message = "#{@stack_name} stack creating."
|
51
17
|
if @options[:noop]
|
52
18
|
message = "NOOP #{message}"
|
53
19
|
else
|
@@ -61,52 +27,10 @@ module LonoCfn
|
|
61
27
|
puts message unless @options[:mute]
|
62
28
|
end
|
63
29
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
def check_for_errors
|
69
|
-
errors = check_files
|
70
|
-
unless errors.empty?
|
71
|
-
puts "Please double check the command you ran. There were some errors."
|
72
|
-
puts "#{errors.join("\n")}"
|
73
|
-
exit
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def check_files
|
78
|
-
errors = []
|
79
|
-
unless File.exist?(@template_path)
|
80
|
-
errors << "Template file missing: could not find #{@template_path}"
|
81
|
-
end
|
82
|
-
if @options[:params] && !File.exist?(@params_path)
|
83
|
-
errors << "Parameters file missing: could not find #{@params_path}"
|
84
|
-
end
|
85
|
-
errors
|
86
|
-
end
|
87
|
-
|
88
|
-
# if existing in params path then use that
|
89
|
-
# if it doesnt assume it is a full path and check that
|
90
|
-
# else fall back to convention, which also eventually gets checked in check_for_errors
|
91
|
-
#
|
92
|
-
# Type - :params or :template
|
93
|
-
def get_source_path(path, type)
|
94
|
-
default_convention_path = convention_path(@stack_name, type)
|
95
|
-
|
96
|
-
return default_convention_path if path.nil?
|
97
|
-
# convention path based on the input from the user
|
98
|
-
convention_path(path, type)
|
99
|
-
end
|
100
|
-
|
101
|
-
def convention_path(name, type)
|
102
|
-
case type
|
103
|
-
when :template
|
104
|
-
"#{@project_root}/output/#{name}.json"
|
105
|
-
when :params
|
106
|
-
"#{@project_root}/params/#{name}.txt"
|
107
|
-
else
|
108
|
-
raise "hell: dont come here"
|
109
|
-
end
|
30
|
+
def stack_exists?
|
31
|
+
return if @options[:noop]
|
32
|
+
stack = cfn.describe_stacks(stack_name: @stack_name).stacks.first
|
33
|
+
!!stack
|
110
34
|
end
|
111
35
|
end
|
112
36
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LonoCfn
|
2
|
+
class Update < Base
|
3
|
+
# save_stack is the interface method
|
4
|
+
def save_stack(params)
|
5
|
+
update_stack(params)
|
6
|
+
end
|
7
|
+
|
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
|
+
def update_stack(params)
|
10
|
+
template_body = IO.read(@template_path)
|
11
|
+
message = "#{@stack_name} stack updating."
|
12
|
+
if @options[:noop]
|
13
|
+
message = "NOOP #{message}"
|
14
|
+
else
|
15
|
+
cfn.update_stack(
|
16
|
+
stack_name: @stack_name,
|
17
|
+
template_body: template_body,
|
18
|
+
parameters: params#,
|
19
|
+
# capabilities: ["CAPABILITY_IAM"]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
puts message unless @options[:mute]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/lono_cfn/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module LonoCfn
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/spec/lib/cli_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# to run specs with what's remembered from vcr
|
4
4
|
# $ rake
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# to run specs with new fresh data from aws api calls
|
7
7
|
# $ rake clean:vcr ; time rake
|
8
8
|
describe LonoCfn::CLI do
|
@@ -13,7 +13,12 @@ describe LonoCfn::CLI do
|
|
13
13
|
describe "lono-cfn" do
|
14
14
|
it "creates stack" do
|
15
15
|
out = execute("bin/lono-cfn create my-stack #{@args}")
|
16
|
-
expect(out).to include("stack
|
16
|
+
expect(out).to include("stack creating.")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "updates stack" do
|
20
|
+
out = execute("bin/lono-cfn update my-stack #{@args}")
|
21
|
+
expect(out).to include("stack updating.")
|
17
22
|
end
|
18
23
|
end
|
19
24
|
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.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2016-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -184,9 +184,11 @@ files:
|
|
184
184
|
- Rakefile
|
185
185
|
- bin/lono-cfn
|
186
186
|
- lib/lono-cfn.rb
|
187
|
+
- lib/lono_cfn/base.rb
|
187
188
|
- lib/lono_cfn/cli.rb
|
188
189
|
- lib/lono_cfn/cli/help.rb
|
189
190
|
- lib/lono_cfn/create.rb
|
191
|
+
- lib/lono_cfn/update.rb
|
190
192
|
- lib/lono_cfn/version.rb
|
191
193
|
- lono_cfn.gemspec
|
192
194
|
- spec/fixtures/my_project/config/lono.rb
|
@@ -227,4 +229,3 @@ test_files:
|
|
227
229
|
- spec/fixtures/my_project/params/my-stack.txt
|
228
230
|
- spec/lib/cli_spec.rb
|
229
231
|
- spec/spec_helper.rb
|
230
|
-
has_rdoc:
|