lono-cfn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 265bf28e4a45544babe2118667de0af5915340d5
4
+ data.tar.gz: b0cdecb36faa043904edb48b33f56544d40bbb1c
5
+ SHA512:
6
+ metadata.gz: 8c70f4ddd7d26a3328412605aa890802ccbe24e019a1f5e1f27eaf075b8fd704ed8b286b58053aa8433d5dd8e9e42ed33653f9e9237a1f022a10a100c53c75ea
7
+ data.tar.gz: 4ca23f77a2d84fa824705b43239f4662b239319e6d63d58c8462182c842628d2b9c7454175eb18acec8eb0e8910d7e1cb59f9ac93da101db4bdce3184aa30370
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+
18
+ /params/output
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.0.1] Initial Release
7
+
8
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lono_cfn.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock ADDED
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lono-cfn (0.0.1)
5
+ aws-sdk
6
+ colorize
7
+ hashie
8
+ lono
9
+ lono-params
10
+ thor
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activemodel (4.0.13)
16
+ activesupport (= 4.0.13)
17
+ builder (~> 3.1.0)
18
+ activesupport (4.0.13)
19
+ i18n (~> 0.6, >= 0.6.9)
20
+ minitest (~> 4.2)
21
+ multi_json (~> 1.3)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 0.3.37)
24
+ aws-sdk (2.6.4)
25
+ aws-sdk-resources (= 2.6.4)
26
+ aws-sdk-core (2.6.4)
27
+ jmespath (~> 1.0)
28
+ aws-sdk-resources (2.6.4)
29
+ aws-sdk-core (= 2.6.4)
30
+ builder (3.1.4)
31
+ codeclimate-test-reporter (0.6.0)
32
+ simplecov (>= 0.7.1, < 1.0.0)
33
+ coderay (1.1.1)
34
+ colorize (0.8.1)
35
+ diff-lcs (1.2.5)
36
+ docile (1.1.5)
37
+ ffi (1.9.14)
38
+ formatador (0.2.5)
39
+ guard (2.14.0)
40
+ formatador (>= 0.2.4)
41
+ listen (>= 2.7, < 4.0)
42
+ lumberjack (~> 1.0)
43
+ nenv (~> 0.1)
44
+ notiffany (~> 0.0)
45
+ pry (>= 0.9.12)
46
+ shellany (~> 0.0)
47
+ thor (>= 0.18.1)
48
+ guard-bundler (2.1.0)
49
+ bundler (~> 1.0)
50
+ guard (~> 2.2)
51
+ guard-compat (~> 1.1)
52
+ guard-cloudformation (0.0.3)
53
+ colorize
54
+ guard
55
+ guard-compat (1.2.1)
56
+ guard-lono (0.0.2)
57
+ colorize
58
+ guard
59
+ guard-rspec (4.7.3)
60
+ guard (~> 2.1)
61
+ guard-compat (~> 1.1)
62
+ rspec (>= 2.99.0, < 4.0)
63
+ hashie (3.4.6)
64
+ i18n (0.7.0)
65
+ jmespath (1.3.1)
66
+ json (2.0.2)
67
+ listen (3.1.5)
68
+ rb-fsevent (~> 0.9, >= 0.9.4)
69
+ rb-inotify (~> 0.9, >= 0.9.7)
70
+ ruby_dep (~> 1.2)
71
+ lono (0.5.0)
72
+ colorize
73
+ guard
74
+ guard-cloudformation
75
+ guard-lono
76
+ json
77
+ rake
78
+ rb-fsevent
79
+ thor
80
+ lono-params (0.0.2)
81
+ colorize
82
+ hashie
83
+ plissken
84
+ thor
85
+ lumberjack (1.0.10)
86
+ method_source (0.8.2)
87
+ minitest (4.7.5)
88
+ multi_json (1.12.1)
89
+ nenv (0.3.0)
90
+ notiffany (0.1.1)
91
+ nenv (~> 0.1)
92
+ shellany (~> 0.0)
93
+ plissken (0.2.0)
94
+ symbolize (~> 4.2)
95
+ pry (0.10.4)
96
+ coderay (~> 1.1.0)
97
+ method_source (~> 0.8.1)
98
+ slop (~> 3.4)
99
+ rake (11.3.0)
100
+ rb-fsevent (0.9.7)
101
+ rb-inotify (0.9.7)
102
+ ffi (>= 0.5.0)
103
+ rspec (3.5.0)
104
+ rspec-core (~> 3.5.0)
105
+ rspec-expectations (~> 3.5.0)
106
+ rspec-mocks (~> 3.5.0)
107
+ rspec-core (3.5.3)
108
+ rspec-support (~> 3.5.0)
109
+ rspec-expectations (3.5.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.5.0)
112
+ rspec-mocks (3.5.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.5.0)
115
+ rspec-support (3.5.0)
116
+ ruby_dep (1.4.0)
117
+ shellany (0.0.1)
118
+ simplecov (0.12.0)
119
+ docile (~> 1.1.0)
120
+ json (>= 1.8, < 3)
121
+ simplecov-html (~> 0.10.0)
122
+ simplecov-html (0.10.0)
123
+ slop (3.6.0)
124
+ symbolize (4.5.2)
125
+ activemodel (>= 3.2, < 5)
126
+ activesupport (>= 3.2, < 5)
127
+ i18n
128
+ thor (0.19.1)
129
+ thread_safe (0.3.5)
130
+ tzinfo (0.3.51)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ bundler (~> 1.3)
137
+ codeclimate-test-reporter
138
+ guard
139
+ guard-bundler
140
+ guard-rspec
141
+ lono-cfn!
142
+ rake
143
+
144
+ BUNDLED WITH
145
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { "spec/lono_cfn_spec.rb" }
4
+ watch(%r{^lib/lono_cfn/(.+)\.rb$}) { "spec/lono_cfn_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec/lono_cfn_spec.rb" }
6
+ watch(%r{^lib/lono_cfn/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ end
8
+
9
+ guard 'bundler' do
10
+ watch('Gemfile')
11
+ watch(/^.+\.gemspec/)
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tung Nguyen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Lono Cfn
2
+
3
+ Wrapper cfn tool to quickly create CloudFormation stacks from lono templates and params files.
4
+
5
+ ```bash
6
+ $ bundle exec lono-cfn create my-stack-$(date +%s) --template my-template --params my-params
7
+ ```
8
+
9
+ The above command:
10
+
11
+ 1. Generates the lono templates defined in the lono config files.
12
+ 2. Generate a parameters file from the params/my-params.txt.
13
+ 3. Launch the CloudFormation stack with those parameters.
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` call.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'lono-cfn'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install lono-cfn
30
+
31
+ ## Usage
32
+
33
+ Provided that you are in a lono project and have a `my-stack` lono template definition. To create a stack you can simply run:
34
+
35
+ ```
36
+ $ lono-cfn create my-stack
37
+ ```
38
+
39
+ 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 conventions allows the command to be a very nice short command that can be easily remembered. Both conventions can be overridden.
40
+
41
+ ## More About Conventions
42
+
43
+ * stack - This is a required parameter and is the passed in from the CLI as the first parameter.
44
+ * template - By convention matches the stack name but can be overriden with `--template`.
45
+ * params = By convention matches the template name but can be overriden with `--params`.
46
+
47
+ Here are examples of overriding the template and params name conventions.
48
+
49
+ ```
50
+ $ lono-cfn create my-stack --template different-name1
51
+ ```
52
+
53
+ The template that will be use is output/different-name1.json and the parameters will use params/different-name1.json.
54
+
55
+ ```
56
+ $ lono-cfn create my-stack --params different-name2
57
+ ```
58
+
59
+ The template that will be use is output/different-name2.json and the parameters will use params/different-name2.json.
60
+
61
+ ```
62
+ $ lono-cfn create my-stack --template different-name3 --params different-name4
63
+ ```
64
+
65
+ The template that will be use is output/different-name3.json and the parameters will use params/different-name4.json.
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new
data/bin/lono-cfn ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path('../../lib', __FILE__))
4
+ require 'lono-cfn'
5
+ require 'lono_cfn/cli'
6
+
7
+ LonoCfn::CLI.start(ARGV)
data/lib/lono-cfn.rb ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.expand_path("../", __FILE__))
2
+ require "lono_cfn/version"
3
+ require "pp"
4
+
5
+ module LonoCfn
6
+ autoload :CLI, 'lono_cfn/cli'
7
+ autoload :Create, 'lono_cfn/create'
8
+ end
@@ -0,0 +1,20 @@
1
+ require 'thor'
2
+ require 'lono_cfn/cli/help'
3
+
4
+ module LonoCfn
5
+
6
+ class CLI < Thor
7
+ class_option :verbose, type: :boolean
8
+ class_option :noop, type: :boolean
9
+ class_option :project_root, desc: "Project folder. Defaults to current directory", default: '.'
10
+
11
+ desc "create STACK", "create a CloudFormation stack"
12
+ 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
+ def create(name)
17
+ Create.new(name, options).run
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module LonoCfn
2
+ class CLI < Thor
3
+ class Help
4
+ class << self
5
+ def create
6
+ <<-EOL
7
+ Examples:
8
+
9
+ Provided that you are in a lono project and have a `my-stack` lono template definition. To create a stack you can simply run:
10
+
11
+ $ lono-cfn create my-stack
12
+
13
+ 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.
14
+
15
+ Here are examples of overriding the template and params name conventions.
16
+
17
+ $ lono-cfn create my-stack --template different-name1
18
+
19
+ The template that will be use is output/different-name1.json and the parameters will use params/different-name1.json.
20
+
21
+ $ lono-cfn create my-stack --params different-name2
22
+
23
+ The template that will be use is output/different-name2.json and the parameters will use params/different-name2.json.
24
+
25
+ $ lono-cfn create my-stack --template different-name3 --params different-name4
26
+
27
+ The template that will be use is output/different-name3.json and the parameters will use params/different-name4.json.
28
+
29
+ EOL
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,112 @@
1
+ require "lono"
2
+ require "lono-params"
3
+ require "aws-sdk"
4
+
5
+ module LonoCfn
6
+ class Create
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
+ create_stack(params)
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_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
48
+ def create_stack(params)
49
+ template_body = IO.read(@template_path)
50
+ message = "#{@stack_name} stack created."
51
+ if @options[:noop]
52
+ message = "NOOP #{message}"
53
+ else
54
+ cfn.create_stack(
55
+ stack_name: @stack_name,
56
+ template_body: template_body,
57
+ parameters: params#,
58
+ # capabilities: ["CAPABILITY_IAM"]
59
+ )
60
+ end
61
+ puts message unless @options[:mute]
62
+ end
63
+
64
+ def cfn
65
+ @cfn ||= Aws::CloudFormation::Client.new(region: @region)
66
+ end
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
110
+ end
111
+ end
112
+ end