cloudformation-tool 1.3.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -17
- data/lib/cloud_formation_tool/cli/compile.rb +5 -0
- data/lib/cloud_formation_tool/cli/main.rb +3 -1
- data/lib/cloud_formation_tool/cli/services.rb +25 -0
- data/lib/cloud_formation_tool/cloud_formation/stack.rb +38 -0
- data/lib/cloud_formation_tool/cloud_formation.rb +2 -2
- data/lib/cloud_formation_tool/cloud_init.rb +2 -2
- data/lib/cloud_formation_tool/version.rb +1 -1
- data/lib/cloud_formation_tool.rb +5 -0
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3af98e9eacdd806d05045dca7f8bcf35f6d25c668f8abc2902a45fb07c0ae3
|
4
|
+
data.tar.gz: aedd1156bdd61e9b6085c9496bac440f7fe744b50f5f89319e1386e7043f905e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccb703d5a98b708ceb00ec8e0245b270eb28143066fe14ff86b2c8da03ec2745aac5d588a7b710144d55c5402cd3fe7edf38d9d979b98596ae83e126e38f6338
|
7
|
+
data.tar.gz: 9e063966aa631e161f686ab0af55269a0e8b50cfca6b65f1dc68af7d7e8f9442ce848c7d84106e41c64b33e87e16b8d85a7a65da9c6a3435016f5ef4d43a6a0d
|
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
|
107
|
-
resource, the user-data can be loaded from an external
|
108
|
-
is currently supported, sorry) by specifying the
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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).
|
123
|
-
does not exceed the user-data size limitation.
|
124
|
-
|
125
|
-
|
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
|
|
@@ -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
|
@@ -53,8 +54,9 @@ module CloudFormationTool
|
|
53
54
|
subcommand 'delete', "Delete an existing stack", Delete
|
54
55
|
subcommand 'servers', 'List stack resources', Servers
|
55
56
|
subcommand 'groups', 'List stack Autoscaling groups', Groups
|
57
|
+
subcommand 'services', 'List stack Fargate services', Services
|
56
58
|
subcommand 'recycle', 'Recycle servers in an auto scaling group', Recycle
|
57
|
-
subcommand 'scale', 'Set the number of desired
|
59
|
+
subcommand 'scale', 'Set the number of desired servers in an auto scaling group', Scale
|
58
60
|
subcommand 'invalidate', 'Invalidate CloudFront caches in the stack', Invalidate
|
59
61
|
subcommand 'output', 'Retrieve output values from the stack', Output
|
60
62
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CloudFormationTool
|
2
|
+
module CLI
|
3
|
+
|
4
|
+
class Services < Clamp::Command
|
5
|
+
include CloudFormationTool
|
6
|
+
|
7
|
+
parameter "STACK_NAME", "Name of the stack to list Fargate services from"
|
8
|
+
|
9
|
+
def execute
|
10
|
+
st = CloudFormation::Stack.new(stack_name)
|
11
|
+
output = st.fargate_services.collect do |res|
|
12
|
+
{
|
13
|
+
name: res.logical_resource_id,
|
14
|
+
res: res.physical_resource_id,
|
15
|
+
len: res.logical_resource_id.length
|
16
|
+
}
|
17
|
+
end
|
18
|
+
width = output.collect { |g| g[:name].length }.max
|
19
|
+
output.collect do |svc|
|
20
|
+
puts svc[:name].ljust(width, ' ') + "\t => " + svc[:res]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -126,6 +126,44 @@ module CloudFormationTool
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
def fargate_services
|
130
|
+
output = []
|
131
|
+
resources do |res|
|
132
|
+
output << res if res.resource_type == 'AWS::ECS::Service'
|
133
|
+
end
|
134
|
+
output.collect do |res|
|
135
|
+
res.extend(CloudFormationTool)
|
136
|
+
res.instance_eval do
|
137
|
+
def arn
|
138
|
+
physical_resource_id
|
139
|
+
end
|
140
|
+
def cluster_name
|
141
|
+
self.arn.split(/:/).last.split('/')[1]
|
142
|
+
end
|
143
|
+
def service_name
|
144
|
+
self.arn.split(/:/).last.split('/')[2]
|
145
|
+
end
|
146
|
+
def service
|
147
|
+
svc = awsecs.describe_services(cluster: cluster_name, services: [ service_name ], include: [ 'TAGS' ]).services.first
|
148
|
+
svc.instance_eval do
|
149
|
+
def client= ecsclient
|
150
|
+
@client = ecsclient
|
151
|
+
end
|
152
|
+
def client
|
153
|
+
@client
|
154
|
+
end
|
155
|
+
end
|
156
|
+
svc.client = awsecs
|
157
|
+
svc
|
158
|
+
end
|
159
|
+
def task_definition
|
160
|
+
awsecs.describe_task_definition(task_definition: service.task_definition).task_definition
|
161
|
+
end
|
162
|
+
end
|
163
|
+
res
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
129
167
|
def cdns
|
130
168
|
output = []
|
131
169
|
resources do |res|
|
@@ -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
|
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
|
@@ -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 >
|
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 >
|
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}"
|
data/lib/cloud_formation_tool.rb
CHANGED
@@ -95,6 +95,11 @@ module CloudFormationTool
|
|
95
95
|
$__aws_as ||= Aws::AutoScaling::Client.new aws_config
|
96
96
|
end
|
97
97
|
|
98
|
+
def awsecs
|
99
|
+
require 'aws-sdk-ecs'
|
100
|
+
$__aws_ecs ||= Aws::ECS::Client.new aws_config
|
101
|
+
end
|
102
|
+
|
98
103
|
def awscdn
|
99
104
|
require 'aws-sdk-cloudfront'
|
100
105
|
$__aws_cdn ||= Aws::CloudFront::Client.new aws_config
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Arbel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-22 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:
|
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:
|
26
|
+
version: 12.3.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: clamp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aws-sdk-ecs
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: aws-sdk-autoscaling
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +178,7 @@ files:
|
|
164
178
|
- lib/cloud_formation_tool/cli/recycle.rb
|
165
179
|
- lib/cloud_formation_tool/cli/scale.rb
|
166
180
|
- lib/cloud_formation_tool/cli/servers.rb
|
181
|
+
- lib/cloud_formation_tool/cli/services.rb
|
167
182
|
- lib/cloud_formation_tool/cli/status.rb
|
168
183
|
- lib/cloud_formation_tool/cloud_formation.rb
|
169
184
|
- lib/cloud_formation_tool/cloud_formation/cloud_front_distribution.rb
|
@@ -193,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
208
|
- !ruby/object:Gem::Version
|
194
209
|
version: '0'
|
195
210
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
211
|
+
rubygems_version: 3.2.5
|
197
212
|
signing_key:
|
198
213
|
specification_version: 4
|
199
214
|
summary: A pre-compiler tool for CloudFormation YAML templates
|