cloudformation-tool 1.3.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6667d6553e4525f298bb9b2fd517a7045d50f8ed88273fe7bf43ca1e5b588ed
4
- data.tar.gz: f8b8ebc3884b92222e8fe67e60f6fdea325cc60b0130eecb36b45edb83e7f209
3
+ metadata.gz: 5d47ec3cc3379ca6dfb0cc2f85ffade8b42e0422d4b761cf15da9ee1c97ca960
4
+ data.tar.gz: 4853ad5baa7f8b2322cf745f62e68603d098b53a1744562db5ec92ecd3200001
5
5
  SHA512:
6
- metadata.gz: 1db7a23fd37bb5ac7f5ab7437b5a62b8fe3d57e0c26a9ac48389641f08042c683f6ecf8eea482a88e08bf68e9ed7fc1c51415db6da54feb1f434a6ab41fb0d42
7
- data.tar.gz: ade2265d6bf3652212ecf11125028239494e4ce0318345a88366a2f53440e7b3efde861eb0cfdb946e262438931a5968d3a0e6354376fb17c6aded89a590dfc8
6
+ metadata.gz: e37177758d4c82350f8af6e842ecfbfc1e336230a50a11e946c87a325f8a27ec8cfe6b07a3b7ee7d8ba3c1682bb74a235c3cfceb7627394d27f173a1598ba368
7
+ data.tar.gz: af3e5b0a4dac828b3b846c0b5242b2661aec5d221b4fde8b3612756b9048009404ab1f2d64bd45c5fc7339c4b126eef0bfc07ecefa0afea834a171a6b62275e2
data/README.md CHANGED
@@ -103,27 +103,30 @@ multiple sub-templates, this is an error that would cause the tool to abort.
103
103
 
104
104
  ### Loading user data files
105
105
 
106
- When specifying a user-data block for a `LaunchConfiguration` resource or an `Instance`
107
- resource, the user-data can be loaded from an external YAML file (only YAML formatted user-data
108
- is currently supported, sorry) by specifying the `UserData` element as a map with the single
109
- field `File` that is set with the relative path to the user-data file. The user-data file is
110
- expected to be a cloud-init configuration file with the default extension `.init`.
111
-
112
- Alternatively, the field `FileTemplate` can be used under `UserData` to load an external cloud-init configuration file that includes variable place holders for the
113
- (CloudFormation intrinsic function Sub)[http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html]. The `FileTemplate` mode supports all
114
- the features described above as well as it performs the parsing detailed below, except
115
- compression and S3 offloading - as doing so prevents CloudFormation from performing the
116
- substitution operation. As a result, if the resulting cloud-init file is larger than 16KB
117
- you should expect that the template will fail to create the server.
106
+ When specifying a user-data block for a `LaunchConfiguration` resource, `Instance`
107
+ resource, or a `LaunchTemplate` resource, the user-data can be loaded from an external
108
+ YAML file (only YAML formatted user-data is currently supported, sorry) by specifying the
109
+ `UserData` element as a map with the single field `File` that is set with the relative
110
+ path to the user-data file. The user-data file is expected to be a cloud-init configuration
111
+ file with the default extension `.init` (but there really aren't any filename requirements).
112
+
113
+ Alternatively, the field `FileTemplate` can be used under `UserData` to load an external
114
+ cloud-init configuration file that includes variable place holders for the
115
+ (CloudFormation intrinsic function Sub)[http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html].
116
+ The `FileTemplate` mode supports all the features described above as well as it performs
117
+ the parsing detailed below, except compression and S3 offloading - as doing so prevents
118
+ CloudFormation from performing the substitution operation. As a result, if the resulting
119
+ cloud-init file is larger than 16KB you should expect that the template will fail to create
120
+ the stack.
118
121
 
119
122
  #### User data file parsing
120
123
 
121
124
  The reference file will be loaded and parsed as a ("Cloud Config data" file)[http://cloudinit.readthedocs.io/en/latest/topics/format.html#cloud-config-data]
122
- with the special `write_files` and `write_directories` enhancement (see below). The result is then checked that it
123
- does not exceed the user-data size limitation. If the file is bigger than can fit in the AWS
124
- user-data block, it will first be compressed using gzip and if it is still too large, it will
125
- be uploaded to S3 and the user-data block will be set with a cloud-init download reference to
126
- the S3 object.
125
+ with the special `write_files` and `write_directories` enhancement (see below).
126
+ The result is then checked that it does not exceed the user-data size limitation.
127
+ If the file is bigger than can fit in the AWS user-data block, it will first be compressed
128
+ using gzip and if it is still too large, it will be uploaded to S3 and the user-data block
129
+ will be set with a cloud-init download reference to the S3 object.
127
130
 
128
131
  ##### Enhanced `write_files`
129
132
 
@@ -344,7 +347,12 @@ The following commands are supported:
344
347
  - `status` - Check if the names stack exists or not
345
348
  - `delete` - Delete the specified stack. After issuing the delete command, the tool will
346
349
  immediately start `monitor` mode until the operation has completed.
347
- - `servers` - List EC2 instances created and managed by this stack.
350
+ - `servers` - List EC2 instances created and managed by this stack, per autoscaling group, including servers in nested stacks.
351
+ - `groups` - list autoscaling groups managed by the stack, including groups in nested stacks.
352
+ - `recycle` - recycle servers in an autoscaling group in a stack by scaling the group up and down.
353
+ - `scale` - set the scale of an autoscaling group managed by a stack to a specific desired value.
354
+ - `invalidate` - send an invalidation request to a CloudFront distribution managed by a stack.
355
+ - `output` - retrieve output values from a stack.
348
356
 
349
357
  Please see the specific help for each command by running `cftool <command> --help` for
350
358
  more details and specific options.
@@ -356,3 +364,100 @@ The AWS region to be used can be select by specifying top level option (i.e. bef
356
364
  ### Credentials Selection
357
365
 
358
366
  The tool will use the standard AWS credentials selection process, except when you want to use AWS CLI configured credential profiles, you may select to use a profile other than "default" by specifying the top level option (i.e. before the command name) `-p <profile>`, by providing the standard environment variable `AWS_DEFAULT_PROFILE` or by having a file called `.awsprofile` - whose content is the name of a valid AWS REGION - in a parent directory (at any level up to the root directory).
367
+
368
+ ## Library API
369
+
370
+ The cloudformatin tool can also be consumed as a library by other applications - for example an application that needs to perform high-level business-logic oriented
371
+ operations for a specific application deployed in a stack, using the cloudformation tool abstraction of CloudFormation templates and stacks.
372
+
373
+ ### Usage as a library
374
+
375
+ To use the cloudformatin tool as a library, require `cloud_formation_tool`.
376
+
377
+ ### CloudFormation templates
378
+
379
+ The cloudformation pre-compiler can be used to manipulate pre-compiled templates.
380
+
381
+ To access the pre-compiler, initialize a `CloudFormationTool::CloudFormation` with the path to the local template resource (either a file or a directory that can be
382
+ parsed by the pre-compiler).
383
+
384
+ The initial template resource will be loaded but will not be fully parsed - and included elements will not be read - until the `compile` method is called.
385
+
386
+ The following method calls are available on the `CloudFormation` instance:
387
+
388
+ #### `compile(parameters = nil)`
389
+
390
+ Pre-compiles the template, with the provided parameter `Hash`, if provided. Returns a `Hash` repsenting the compiled template.
391
+
392
+ #### `to_yaml`
393
+
394
+ Pre-compiles the template and returns a YAML rendering of the CloudFormation template, suitable for deploying to AWS CloudFormation.
395
+
396
+ #### `each`
397
+
398
+ Yields a tuple for each defined template parameter, that includes the parameter's name and its default value (if set, `nil` otherwise).
399
+
400
+ ### CloudFormation stacks
401
+
402
+ The cloudformation tool's abstraction of a CloudFormation stack can be used to manipulate stack resouces, such as autoscaling groups or instances in a stack context.
403
+
404
+ To access the stack API, initialize a `CloudFormationTool::CloudFormation::Stack` with the name of the stack. You can then access the following methods:
405
+
406
+ #### `exist?`
407
+
408
+ Check if a stack exists.
409
+
410
+ #### `create(template, params = {})`
411
+
412
+ Create or update a stack by deploying the specified template. The template can be any local file or directory resource that can be parsed by the cloudformation pre-compiler.
413
+
414
+ #### `delete`
415
+
416
+ Deletes the stack
417
+
418
+ #### `stack_id`
419
+
420
+ Return the AWS CloudFormation stack identifier for the stack, which is the ARN of the stack.
421
+
422
+ #### `output`
423
+
424
+ Returns the output values of the stack
425
+
426
+ #### `resources`
427
+
428
+ Return a list of resources in the stack and all of its nested stacks
429
+
430
+ #### `asgroups`
431
+
432
+ Return a list of autoscaling groups in the stack and all of its nested stacks. The returned values are AWS SDK CloudFormation resources, extended with a set of methods
433
+ to help manage autoscaling groups:
434
+
435
+ ##### `group`
436
+
437
+ Returns the AWS SDK `Aws::AutoScaling::AutoScalingGroup` object for the autoscaling group.
438
+
439
+ #### `cdns`
440
+
441
+ Return a list of CloudFront CDN distributions in the stack and all of its nested stacks. The returnd values are AWS SDK CloudFormation resources, extended with a set of
442
+ methods to help manage CloudFront distributions:
443
+
444
+ ##### `distribution`
445
+
446
+ Returns the AWS SDK `Aws::CloudFront::Types::Distribution` object for the CloudFront distribution.
447
+
448
+ ##### `domain_names`
449
+
450
+ Returns the comma delimited list of the distribution aliases domain names
451
+
452
+ ##### `invalidate(path)`
453
+
454
+ Creates a new invalidation in the CloudFront distribution with the specified path expression
455
+
456
+ #### `each`
457
+
458
+ Yields CloudFormation stack events, in the order they were created. Subsequent calls to `each` will not repeat events previously yielded and will only yield additional
459
+ events created since the last call to `each`.
460
+
461
+ #### `see_event`
462
+
463
+ Mark all events since the last call to `each` (or from stack creation, if `each` was not previously called) as "seen" so they will not be yielded in future calls to `each`.
@@ -4,11 +4,16 @@ module CloudFormationTool
4
4
  class Compile < Clamp::Command
5
5
  include ParamSupport
6
6
 
7
+ option "--user-data-size", "SIZE", "Maximum size of VM user data", default: $MAX_USER_DATA_SIZE do |s|
8
+ Integer(s)
9
+ end
10
+
7
11
  parameter 'FILE', 'Template main file'
8
12
 
9
13
  add_param_options
10
14
 
11
15
  def execute
16
+ $MAX_USER_DATA_SIZE = user_data_size
12
17
  if file.end_with? '.init'
13
18
  puts CloudInit.new(file).encode(false) # make sure cloud-init files obey AWS user-data restrictions, but are also printable
14
19
  else
@@ -1,6 +1,7 @@
1
1
  require 'clamp'
2
2
  require 'io/console'
3
3
 
4
+ $MAX_USER_DATA_SIZE = 16384
4
5
 
5
6
  module CloudFormationTool
6
7
  module CLI
@@ -23,7 +23,7 @@ module CloudFormationTool
23
23
  begin
24
24
  text = File.read(@path)
25
25
  # remove comments because white space seen between comments can seriously psych Psych
26
- text.gsub!(/^#.*\n/s,'')
26
+ text.gsub!(/^#.*\n/,'')
27
27
  text = fixShorthand(text)
28
28
  @data = YAML.load(text).to_h
29
29
  rescue Psych::SyntaxError => e
@@ -167,7 +167,7 @@ module CloudFormationTool
167
167
  restype = data['Type'] if restype.nil? and data.key?('Type')
168
168
  data.inject({}) do |dict, (key, val)|
169
169
  dict[key] = case restype
170
- when 'AWS::AutoScaling::LaunchConfiguration'
170
+ when 'AWS::AutoScaling::LaunchConfiguration', 'AWS::EC2::LaunchTemplate'
171
171
  if (key == "UserData") and (val["File"])
172
172
  # Support LaunchConfiguration UserData from file
173
173
  CloudInit.new("#{@basedir}/#{val["File"]}").to_base64
@@ -96,7 +96,14 @@ module CloudFormationTool
96
96
  def resources
97
97
  begin
98
98
  awscf.list_stack_resources(stack_name: @name).each do |resp|
99
- resp.stack_resource_summaries.each { |res| yield res }
99
+ resp.stack_resource_summaries.each do |res|
100
+ yield res
101
+ if res.resource_type == 'AWS::CloudFormation::Stack'
102
+ Stack.new(res.physical_resource_id).resources do |nested_res|
103
+ yield nested_res
104
+ end
105
+ end
106
+ end
100
107
  end
101
108
  rescue Aws::CloudFormation::Errors::ValidationError => e
102
109
  raise CloudFormationTool::Errors::AppError, "Failed to get resources: #{e.message}"
@@ -45,11 +45,11 @@ module CloudFormationTool
45
45
  def encode(allow_gzip = true)
46
46
  yamlout = compile
47
47
  usegzip = false
48
- if allow_gzip and yamlout.size > 16384 # max AWS EC2 user data size - try compressing it
48
+ if allow_gzip and yamlout.size > $MAX_USER_DATA_SIZE # max AWS EC2 user data size - try compressing it
49
49
  yamlout = Zlib::Deflate.new(nil, 31).deflate(yamlout, Zlib::FINISH) # 31 is the magic word to have deflate create a gzip compatible header
50
50
  usegzip = true
51
51
  end
52
- if yamlout.size > 16384 # still to big, we should upload to S3 and create an include file
52
+ if yamlout.size > $MAX_USER_DATA_SIZE # still to big, we should upload to S3 and create an include file
53
53
  url = upload make_filename('init'),
54
54
  yamlout, mime_type: 'text/cloud-config', gzip: usegzip
55
55
  log "Wrote cloud config to #{url}"
@@ -1,3 +1,3 @@
1
1
  module CloudFormationTool
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.1'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Arbel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-03 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '12'
19
+ version: 12.3.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '12'
26
+ version: 12.3.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: clamp
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.0.2
196
+ rubygems_version: 3.1.2
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: A pre-compiler tool for CloudFormation YAML templates