aws_as_code 1.0.4 → 1.0.5

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: 34986215f72ee84f1599cc865e45c8b4c636ec13
4
- data.tar.gz: 28cb66d30979987662eb0600c35916d24b9ab5ef
3
+ metadata.gz: c2b846a3091b5d51d22c08d3fac3251bbe31e9e1
4
+ data.tar.gz: 162f56da70060281885207a6fde5c43880fc3d05
5
5
  SHA512:
6
- metadata.gz: 7bed8edaea455f663b21a2e4d8e323000b8f0f1d8d5d6145b9bbc957fb0d8f015724fec6e6c185d6c90a51576749d67355e1208f897ebd2805dbc07206768709
7
- data.tar.gz: d39f89b30c383220530e0fceb9b4383f01c344e705463b8ab05d1852f9edf9e7f4fd6feaa4e2a1c3b3b358ea6465f1e0877167bfa3cd8c04ee1d45b46bc0a332
6
+ metadata.gz: bc3a4b25c816e7f7dac74f8c2f3c4684d19859992ad0836f75ac09e9366bae1a7f84f20ef6ced57ce5876205d51ba35f85e47dcfa8e62a565a5de4508b3e80b7
7
+ data.tar.gz: 35aefa249b8a751f2ae50e3dea7a160107d3dfb493fee74190e9645202d99f91e869d77d9da657a31ee2d22c2cb1ce2c8190a687cc87c440947754e31e56ace1
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.3
3
3
  Include:
4
4
  - "**/*.gemspec"
5
5
  - "**/Gemfile"
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
- # Aws::As::Code
1
+ # AwsAsCode
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aws/as/code`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem is built upon a
4
+ great [cfndsl](https://github.com/stevenjack/cfndsl) CloudFormation
5
+ DSL language in order to automate routine tasks related to CF stack
6
+ updates:
7
+ - compilation of multiple associated templates;
8
+ - a sensible convention around the way compiled templates are uploaded
9
+ and stored on S3;
10
+ - a simple wrapper around AWS SDK allowing you to apply stack changes
11
+ immediately after they have been compiled and uploaded to S3.
4
12
 
5
- TODO: Delete this and the text above, and describe your gem
13
+ This gem provides a command-line utility; normally you don't need to
14
+ use it as a library.
6
15
 
7
16
  ## Installation
8
17
 
@@ -22,26 +31,339 @@ Or install it yourself as:
22
31
 
23
32
  ## Usage
24
33
 
34
+ `bundle exec aws-as-code [command] [option...]`
35
+
36
+ ### Commands
37
+
38
+ #### `create`
39
+ Processes (compiles and uploads) CF templates and attempts to create a
40
+ new stack using them.
41
+
25
42
  ```
26
43
  bundle exec aws-as-code create \
27
- --ruby-dir=cfn \
28
- --json-dir=cfn-compiled \
29
- --bucket=my-cfn-bucket \
30
- --template=environment \
31
- --stack=master
44
+ --bucket=projectname-prod-cloudformation \
45
+ --version="$VERSION" \
46
+ --stack-params=ApiKey:KEY ApiSecret:SECRET
47
+ ```
48
+
49
+ #### `update`
50
+ Processes (compiles and uploads) CF templates and applies changes to an
51
+ existing stack (keeping all existing stack parameters which are not explicitly
52
+ overridden in the command line)
53
+
54
+ ```
55
+ bundle exec aws-as-code update \
56
+ --bucket=projectname-prod-cloudformation \
57
+ --version="$VERSION" \
58
+ --stack-params=ApiSecret:NEWSECRET
59
+ ```
60
+
61
+ #### `compile`
62
+ Compiles CF templates from `ruby-dir` using configuration from
63
+ `config-dir` and stores them locally in `json-dir`
64
+
65
+ ```
66
+ bundle exec aws-as-code compile \
67
+ --bucket=projectname-prod-cloudformation \
68
+ --version="$VERSION"
69
+ ```
70
+
71
+ Mainly used for debugging purposes.
72
+
73
+ #### `upload`
74
+ Uploads CF templates from `json-dir` to `bucket` on S3.
75
+
76
+ ```
77
+ bundle exec aws-as-code upload \
78
+ --bucket=projectname-prod-cloudformation \
79
+ --version="$VERSION"
80
+ ```
81
+
82
+ Mainly used for debugging purposes
83
+
84
+ #### `do-update`
85
+ Applies changes to the existing stack using currently uploaded templates.
86
+
87
+ ```
88
+ bundle exec aws-as-code do-update \
89
+ --bucket=projectname-prod-cloudformation \
90
+ --version="$VERSION"
91
+ ```
92
+
93
+ Mainly used for debugging purposes
94
+
95
+ #### `do-create`
96
+ Creates a new stack using templates already uploaded to S3
97
+
98
+ ```
99
+ bundle exec aws-as-code do-create \
100
+ --bucket=projectname-prod-cloudformation \
101
+ --version="$VERSION"
102
+ ```
103
+
104
+ Mainly used for debugging purposes
105
+
106
+ ### Options
107
+
108
+ #### `--config-dir`
109
+
110
+ Directory with configuration files.
111
+
112
+ Default value: `cfn`
113
+
114
+ #### `--ruby-dir`
115
+
116
+ Directory with CloudFormation templates written in Ruby DSL
117
+
118
+ Default value: `cfn`
119
+
120
+ #### `--json-dir`
121
+
122
+ Directory to put compiled JSON CF templates to
123
+
124
+ Default value: `cfn-compiled`
125
+
126
+ #### `--bucket`
127
+
128
+ S3 bucket used to store compiled templates.
129
+
130
+ *Required*
131
+
132
+ #### `--template`
133
+
134
+ Filename of the stack root template.
135
+
136
+ Default value: `environment`
137
+
138
+ #### `--stack`
139
+
140
+ Name of the stack to create or update (also used as a part of the
141
+ uploaded template name to help distinguish stack templates compiled
142
+ from the same source but using different configurations)
143
+
144
+ Default value: `master`
145
+
146
+ #### `--stack-params`
147
+
148
+ A list of stack parameters in the key-value form.
149
+
150
+ ```
151
+ --stack-params=ApiKey:KEY ApiSecret:SECRET
32
152
  ```
33
153
 
34
- ## Development
154
+ Optional. If not provided for `update` task, all parameters will be
155
+ kept as-is. If not provided for `create` task, no parameters will be
156
+ passed to the stack (if stack requires any parameters, then stack
157
+ creation will fail).
35
158
 
36
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
159
+ #### `--version`
37
160
 
38
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
161
+ Stack definition version. If you're using a version system, it's
162
+ highly recommended to use the latest commit hash as a version.
39
163
 
40
- ## Contributing
164
+ *Required*
41
165
 
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_as_code. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
166
+ ## Configuration files
43
167
 
168
+ `aws-as-code` expects to find two configuration files in `config-dir`:
169
+ - parameters.yml
170
+ - settings.yml
44
171
 
45
- ## License
172
+ ### `parameters.yml`
46
173
 
47
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
174
+ Contains the list of stack parameters configurable through the
175
+ CloudFormation AWS console.
176
+
177
+ Format:
178
+
179
+ ```
180
+ <PARAMETER NAME>:
181
+ Type: "String" | "Number" | "CommaDelimitedList"
182
+ Default: <DEFAULT VALUE>
183
+ _ext:
184
+ env: <ENVIRONMENT VARIABLE NAME>
185
+ services: <LIST OF SERVICE NAMES THIS PARAMETER IS PASSED TO>
186
+ ```
187
+
188
+ Example:
189
+
190
+ ```
191
+ GoogleAnalyticsId:
192
+ Type: String
193
+ Default: UA-66947010-2
194
+ _ext:
195
+ env: GOOGLE_ANALYTICS_ID
196
+ services:
197
+ - web
198
+
199
+ MailerUrl:
200
+ Type: String
201
+ Default: test://localhost
202
+ _ext:
203
+ secure: true
204
+ env: MAILER_URL
205
+ services:
206
+ - web
207
+ - queue
208
+ ```
209
+
210
+ Keep in mind that AWS has a
211
+ [hard cap of 60 parameters](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)
212
+ available to your stack. If a value is not sensitive and doesn't need to be
213
+ reconfigured on the fly, consider using `settings.yml` instead!
214
+
215
+ From the example above, `GoogleAnalyticsId` *can* be moved to
216
+ `settings.yml`, while `MailerUrl` *cannot*, as it contains some
217
+ sensitive information such as SMTP username and password.
218
+
219
+ ### `settings.yml`
220
+
221
+ Contains the list of non-sensitive environment-specific settings
222
+
223
+ Settings can be referenced from the tempalte definition using the
224
+ `setting('<SETTING NAME>')` DSL extension
225
+
226
+ Format:
227
+ ```
228
+ <SETTING NAME>:
229
+ <STACK NAME>: <VALUE>
230
+ <STACK NAME>: <VALUE>
231
+ _default: <DEFAULT VALUE>
232
+ ```
233
+
234
+ Example:
235
+ ```
236
+ es_instance_type:
237
+ master: t2.small.elasticsearch
238
+ _default: t2.small.elasticsearch
239
+ es_instance_count:
240
+ master: 2
241
+ _default: 1
242
+ web_tasks_count:
243
+ master: 4
244
+ _default: 1
245
+ ```
246
+
247
+ ## DSL extensions
248
+
249
+ ### `env_ebs_options(env = nil)`
250
+ Generates a list of ElasticBeanstalk confugration options passing the
251
+ list of stack parameters to the ElasticBeanstalk environment.
252
+
253
+ Example:
254
+
255
+ ```
256
+ ElasticBeanstalk_Environment "Service" do
257
+ Description "Sample app"
258
+ ApplicationName Ref "Application"
259
+ VersionLabel Ref "CurrentVersion"
260
+ OptionSettings [
261
+ {
262
+ Namespace: "aws:elasticbeanstalk:environment",
263
+ OptionName: "EnvironmentType",
264
+ Value: "SingleInstance"
265
+ }
266
+ ] + env_ebs_options("web")
267
+ SolutionStackName "SOLUTION"
268
+ end
269
+ ```
270
+
271
+ ### `env_passthrough(env = nil)`
272
+ Generates a list of stack parameters passing the list input parameters specific
273
+ to a selected environment `env` to a nested stack.
274
+
275
+ Example:
276
+
277
+ ```
278
+ CloudFormation_Stack "Services" do
279
+ Parameters Hash[
280
+ VPC: FnGetAtt("Network", "Outputs.VPC"),
281
+ ].merge(env_passthrough)
282
+ TemplateURL template_url "services"
283
+ TimeoutInMinutes 20
284
+ end
285
+ ```
286
+
287
+ ### `inputs(env = nil)`
288
+ Generates a list of stack input declarations for the environment `env`.
289
+
290
+ Example:
291
+
292
+ ```
293
+ CloudFormation do
294
+ inputs("web")
295
+
296
+ Parameter "SubnetA" do
297
+ String()
298
+ end
299
+ ...
300
+ ```
301
+
302
+ ### `params(env = nil)`
303
+ Returns a list of parameters for environment `env`
304
+
305
+ ### `setting(key)`
306
+ Returns the value of the setting `key` from `settings.yml`
307
+
308
+ Example:
309
+
310
+ ```
311
+ Resource "Lambda" do
312
+ Type "AWS::Lambda::Function"
313
+ Property "Description", "Sample lambda"
314
+ Property "Handler", "main.handler"
315
+ Property "Code",
316
+ S3Bucket: setting("lambda_source"),
317
+ S3Key: FnJoin(
318
+ "",
319
+ [
320
+ "lambda/", ENV["VERSION"], ".zip"
321
+ ]
322
+ )
323
+ Property "Runtime", "nodejs6.10"
324
+ Property "Timeout", "3"
325
+ Property "Role", setting("role")
326
+ end
327
+ ```
328
+
329
+ ### `template_url`
330
+
331
+ Returns a full S3 URL (including dynamically generated version) of another template.
332
+
333
+ Example:
334
+
335
+ ```
336
+ CloudFormation do
337
+ inputs
338
+
339
+ CloudFormation_Stack "Network" do
340
+ TemplateURL template_url "network"
341
+ TimeoutInMinutes 10
342
+ end
343
+ end
344
+ ```
345
+
346
+ ## Examples
347
+
348
+ ### Deploying stack changes from CircleCI
349
+
350
+ Assuming that AWS credentials (secret, key and default region) are
351
+ available in the build environment and this user has all the required
352
+ permissions to perform the required stack updates.
353
+
354
+ #### `circle.yml`
355
+ ```
356
+ deployment:
357
+ production:
358
+ branch: master
359
+ commands:
360
+ - >
361
+ bundle exec aws-as-code update \
362
+ --template=environment \
363
+ --config-dir=core \
364
+ --ruby-dir=core/cfn \
365
+ --json-dir=tmp/cfn \
366
+ --bucket=projectname-prod-cloudformation \
367
+ --stack="$CIRCLE_BRANCH" \
368
+ --version="$CIRCLE_SHA1"
369
+ ```
@@ -7,10 +7,10 @@ require "thor"
7
7
  require "cfndsl"
8
8
  require "ostruct"
9
9
 
10
- DEFAULT_RUBY_DIR = "cfn".freeze
11
- DEFAULT_JSON_DIR = "cfn-compiled".freeze
12
- DEFAULT_STACK = "master".freeze
13
- DEFAULT_TEMPLATE = "environment".freeze
10
+ DEFAULT_RUBY_DIR = "cfn"
11
+ DEFAULT_JSON_DIR = "cfn-compiled"
12
+ DEFAULT_STACK = "master"
13
+ DEFAULT_TEMPLATE = "environment"
14
14
 
15
15
  # Main CLI application for aws-as-code gem
16
16
  class AwsAsCodeCli < Thor
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AwsAsCode
2
4
  module Concerns
3
5
  module AwsTaskHelpers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  CACHE_INSTANCE_CLASSES = %w(
2
4
  cache.t2.micro
3
5
  cache.t2.small
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  EC2_INSTANCE_CLASSES = %w(
2
4
  c3.2xlarge
3
5
  c3.4xlarge
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RDS_INSTANCE_CLASSES = %w(
2
4
  db.m3.medium
3
5
  db.m3.large
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "term/ansicolor"
2
4
 
3
5
  module AwsAsCode
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cfndsl"
2
4
  require "yaml"
3
5
  require "fileutils"
4
6
 
5
- # frozen_string_literal: true
6
7
  module AwsAsCode
7
8
  module Task
8
9
  # Compiles all input templates and puts
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module AwsAsCode
3
4
  module Task
4
5
  class Update < Base
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "aws-sdk"
2
4
  require "pathname"
3
5
 
4
- # frozen_string_literal: true
5
6
  module AwsAsCode
6
7
  module Task
7
8
  class Upload < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module AwsAsCode
3
- VERSION = "1.0.4".freeze
4
+ VERSION = "1.0.5"
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_as_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Burnaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cfndsl