aws_as_code 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +337 -15
- data/exe/aws-as-code +4 -4
- data/lib/aws_as_code/concerns/aws_task_helpers.rb +2 -0
- data/lib/aws_as_code/dsl/cache_instances.rb +2 -0
- data/lib/aws_as_code/dsl/ec2_instances.rb +2 -0
- data/lib/aws_as_code/dsl/rds_instances.rb +2 -0
- data/lib/aws_as_code/stack_state_semaphore.rb +2 -0
- data/lib/aws_as_code/task/compile.rb +2 -1
- data/lib/aws_as_code/task/update.rb +1 -0
- data/lib/aws_as_code/task/upload.rb +2 -1
- data/lib/aws_as_code/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2b846a3091b5d51d22c08d3fac3251bbe31e9e1
|
4
|
+
data.tar.gz: 162f56da70060281885207a6fde5c43880fc3d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3a4b25c816e7f7dac74f8c2f3c4684d19859992ad0836f75ac09e9366bae1a7f84f20ef6ced57ce5876205d51ba35f85e47dcfa8e62a565a5de4508b3e80b7
|
7
|
+
data.tar.gz: 35aefa249b8a751f2ae50e3dea7a160107d3dfb493fee74190e9645202d99f91e869d77d9da657a31ee2d22c2cb1ce2c8190a687cc87c440947754e31e56ace1
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# AwsAsCode
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
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
|
-
|
159
|
+
#### `--version`
|
37
160
|
|
38
|
-
|
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
|
-
|
164
|
+
*Required*
|
41
165
|
|
42
|
-
|
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
|
-
|
172
|
+
### `parameters.yml`
|
46
173
|
|
47
|
-
|
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
|
+
```
|
data/exe/aws-as-code
CHANGED
@@ -7,10 +7,10 @@ require "thor"
|
|
7
7
|
require "cfndsl"
|
8
8
|
require "ostruct"
|
9
9
|
|
10
|
-
DEFAULT_RUBY_DIR = "cfn"
|
11
|
-
DEFAULT_JSON_DIR = "cfn-compiled"
|
12
|
-
DEFAULT_STACK = "master"
|
13
|
-
DEFAULT_TEMPLATE = "environment"
|
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
|
data/lib/aws_as_code/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cfndsl
|