sparkle_formation 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v0.2.0
2
+ * Add Registry helper into Utils
3
+ * Add script for collecting cfn and hot resources
4
+ * Provide builtin dynamics
5
+ * Add helpers for registry and dynamic insertions
6
+ * Let dynamics provide metadata about themselves
7
+ * Start translation implementation
8
+ * Include bang helper method aliases
9
+ * Add hash dumping and JSON dumping helpers to formation instance
10
+
1
11
  ## v0.1.4
2
12
  * Allow compile to return raw object instead of hash dump
3
13
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/heavywater/sparkle_formation/pulls
16
+
17
+ Please base all pull requests off the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/heavywater/sparkle_formation/issues
data/README.md CHANGED
@@ -20,61 +20,56 @@ we can just convert it into a single file (ec2_example.rb):
20
20
 
21
21
  ```ruby
22
22
  SparkleFormation.new('ec2_example') do
23
- description "AWS CloudFormation Sample Template EC2InstanceSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example uses the default security group, so to SSH to the new instance using the KeyPair you enter, you will need to have port 22 open in your default security group. **WARNING** This template an Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template."
23
+ description "AWS CloudFormation Sample Template ..."
24
24
 
25
- parameters do
26
- key_name do
27
- description 'Name of an existing EC2 KeyPair to enable SSH access to the instance'
28
- type 'String'
29
- end
25
+ parameters.keyname do
26
+ description 'Name of EC2 key pair'
27
+ type 'string'
30
28
  end
31
29
 
32
30
  mappings.region_map do
33
- _set('us-east-1', :ami => 'ami-7f418316')
34
- _set('us-east-1', :ami => 'ami-7f418316')
35
- _set('us-west-1', :ami => 'ami-951945d0')
36
- _set('us-west-2', :ami => 'ami-16fd7026')
37
- _set('eu-west-1', :ami => 'ami-24506250')
38
- _set('sa-east-1', :ami => 'ami-3e3be423')
39
- _set('ap-southeast-1', :ami => 'ami-74dda626')
40
- _set('ap-northeast-1', :ami => 'ami-dcfa4edd')
31
+ set!('us-east-1', :ami => 'ami-7f418316')
32
+ set!('us-east-1', :ami => 'ami-7f418316')
33
+ set!('us-west-1', :ami => 'ami-951945d0')
34
+ set!('us-west-2', :ami => 'ami-16fd7026')
35
+ set!('eu-west-1', :ami => 'ami-24506250')
36
+ set!('sa-east-1', :ami => 'ami-3e3be423')
37
+ set!('ap-southeast-1', :ami => 'ami-74dda626')
38
+ set!('ap-northeast-1', :ami => 'ami-dcfa4edd')
41
39
  end
42
40
 
43
- resources do
44
- my_instance do
45
- type 'AWS::EC2::Instance'
46
- properties do
47
- key_name _cf_ref(:key_name)
48
- image_id _cf_map(:region_map, 'AWS::Region', :ami)
49
- user_data _cf_base64('80')
50
- end
41
+ dynamic!(:ec2_instance, :foobar) do
42
+ properties do
43
+ key_name ref!(:key_name)
44
+ image_id map!(:region_map, 'AWS::Region', :ami)
45
+ user_data base64!('80')
51
46
  end
52
47
  end
53
48
 
54
49
  outputs do
55
50
  instance_id do
56
51
  description 'InstanceId of the newly created EC2 instance'
57
- value _cf_ref(:my_instance)
52
+ value ref!(:foobar_ec2_instance)
58
53
  end
59
54
  az do
60
55
  description 'Availability Zone of the newly created EC2 instance'
61
- value _cf_attr(:my_instance, :availability_zone)
56
+ value attr!(:foobar_ec2_instance, :availability_zone)
62
57
  end
63
58
  public_ip do
64
59
  description 'Public IP address of the newly created EC2 instance'
65
- value _cf_attr(:my_instance, :public_ip)
60
+ value attr!(:foobar_ec2_instance, :public_ip)
66
61
  end
67
62
  private_ip do
68
63
  description 'Private IP address of the newly created EC2 instance'
69
- value _cf_attr(:my_instance, :private_ip)
64
+ value attr!(:foobar_ec2_instance, :private_ip)
70
65
  end
71
66
  public_dns do
72
67
  description 'Public DNSName of the newly created EC2 instance'
73
- value _cf_attr(:my_instance, :public_dns_name)
68
+ value attr!(:foobar_ec2_instance, :public_dns_name)
74
69
  end
75
70
  private_dns do
76
71
  description 'Private DNSName of the newly created EC2 instance'
77
- value _cf_attr(:my_instance, :private_dns_name)
72
+ value attr!(:foobar_ec2_instance, :private_dns_name)
78
73
  end
79
74
  end
80
75
  end
@@ -110,70 +105,66 @@ templates.
110
105
  First, create the component (components/ami.rb):
111
106
 
112
107
  ```ruby
113
- SparkleFormation.build do
114
-
115
- parameters do
116
- key_name do
117
- description 'Name of an existing EC2 KeyPair to enable SSH access to the instance'
118
- type 'String'
119
- end
120
- end
108
+ SparkleFormation.build(:ami) do
121
109
 
122
110
  mappings.region_map do
123
- _set('us-east-1', :ami => 'ami-7f418316')
124
- _set('us-east-1', :ami => 'ami-7f418316')
125
- _set('us-west-1', :ami => 'ami-951945d0')
126
- _set('us-west-2', :ami => 'ami-16fd7026')
127
- _set('eu-west-1', :ami => 'ami-24506250')
128
- _set('sa-east-1', :ami => 'ami-3e3be423')
129
- _set('ap-southeast-1', :ami => 'ami-74dda626')
130
- _set('ap-northeast-1', :ami => 'ami-dcfa4edd')
111
+ set!('us-east-1', :ami => 'ami-7f418316')
112
+ set!('us-east-1', :ami => 'ami-7f418316')
113
+ set!('us-west-1', :ami => 'ami-951945d0')
114
+ set!('us-west-2', :ami => 'ami-16fd7026')
115
+ set!('eu-west-1', :ami => 'ami-24506250')
116
+ set!('sa-east-1', :ami => 'ami-3e3be423')
117
+ set!('ap-southeast-1', :ami => 'ami-74dda626')
118
+ set!('ap-northeast-1', :ami => 'ami-dcfa4edd')
131
119
  end
120
+
132
121
  end
133
122
  ```
134
123
 
135
124
  Now, we can modify our initial example to use this component (ec2_example.rb):
136
125
 
137
126
  ```ruby
138
- SparkleFormation.new('ec2_example').load(:ami).overrides do
127
+ SparkleFormation.new('ec2_example').load(:ami) do
139
128
 
140
- description "AWS CloudFormation Sample Template EC2InstanceSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example uses the default security group, so to SSH to the new instance using the KeyPair you enter, you will need to have port 22 open in your default security group. **WARNING** This template an Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template."
129
+ description "AWS CloudFormation Sample Template ..."
141
130
 
142
- resources do
143
- my_instance do
144
- type 'AWS::EC2::Instance'
145
- properties do
146
- key_name _cf_ref(:key_name)
147
- image_id _cf_map(:region_map, 'AWS::Region', :ami)
148
- user_data _cf_base64('80')
149
- end
131
+ parameters.keyname do
132
+ description 'Name of EC2 key pair'
133
+ type 'string'
134
+ end
135
+
136
+ dynamic!(:ec2_instance, :foobar) do
137
+ properties do
138
+ key_name ref!(:key_name)
139
+ image_id map!(:region_map, 'AWS::Region', :ami)
140
+ user_data base64!('80')
150
141
  end
151
142
  end
152
143
 
153
144
  outputs do
154
145
  instance_id do
155
146
  description 'InstanceId of the newly created EC2 instance'
156
- value _cf_ref(:my_instance)
147
+ value ref!(:foobar_ec2_instance)
157
148
  end
158
149
  az do
159
150
  description 'Availability Zone of the newly created EC2 instance'
160
- value _cf_attr(:my_instance, :availability_zone)
151
+ value attr!(:foobar_ec2_instance, :availability_zone)
161
152
  end
162
153
  public_ip do
163
154
  description 'Public IP address of the newly created EC2 instance'
164
- value _cf_attr(:my_instance, :public_ip)
155
+ value attr!(:foobar_ec2_instance, :public_ip)
165
156
  end
166
157
  private_ip do
167
158
  description 'Private IP address of the newly created EC2 instance'
168
- value _cf_attr(:my_instance, :private_ip)
159
+ value attr!(:foobar_ec2_instance, :private_ip)
169
160
  end
170
161
  public_dns do
171
162
  description 'Public DNSName of the newly created EC2 instance'
172
- value _cf_attr(:my_instance, :public_dns_name)
163
+ value attr!(:foobar_ec2_instance, :public_dns_name)
173
164
  end
174
165
  private_dns do
175
166
  description 'Private DNSName of the newly created EC2 instance'
176
- value _cf_attr(:my_instance, :private_dns_name)
167
+ value attr!(:foobar_ec2_instance, :private_dns_name)
177
168
  end
178
169
  end
179
170
  end
@@ -196,42 +187,56 @@ parts to multiple templates. So what do we use?
196
187
  Enter `dynamics`. These are much like components, except that instead of simply
197
188
  being merged, they allow passing of arguments which makes them reusable to create
198
189
  unique resources. So, from our last example, lets move the ec2 related items
199
- into a dynamic (dynamics/ec2.rb):
190
+ into a dynamic (dynamics/node.rb):
200
191
 
201
192
  ```ruby
202
- SparkleFormation.dynamic(:ec2) do |_name|
203
- resources("#{_name}_instance".to_sym)
204
- type 'AWS::EC2::Instance'
193
+ SparkleFormation.dynamic(:node,
194
+ :parameters => {
195
+ :key_name => {
196
+ :type => 'String',
197
+ :description => 'Optionally make keypair static'
198
+ }
199
+ }
200
+ ) do |_name, _config|
201
+
202
+ if(_config[:key_name])
203
+ parameters.keyname do
204
+ description 'Name of EC2 key pair'
205
+ type 'string'
206
+ end
207
+ end
208
+
209
+ dynamic!(:ec2_instance, _name) do
205
210
  properties do
206
- key_name _cf_ref(:key_name)
207
- image_id _cf_map(:region_map, 'AWS::Region', :ami)
208
- user_data _cf_base64('80')
211
+ key_name _config.fetch(:key_name, ref!(:key_name))
212
+ image_id map!(:region_map, 'AWS::Region', :ami)
213
+ user_data baes64!('80')
209
214
  end
210
215
  end
211
216
 
212
217
  outputs("#{_name}_instance_id".to_sym) do
213
218
  description 'InstanceId of the newly created EC2 instance'
214
- value _cf_ref("#{_name}_instance".to_sym)
219
+ value ref!("#{_name}_ec2_instance".to_sym)
215
220
  end
216
221
  outputs("#{_name}_az".to_sym) do
217
222
  description 'Availability Zone of the newly created EC2 instance'
218
- value _cf_attr("#{_name}_instance".to_sym, :availability_zone)
223
+ value attr!("#{_name}_ec2_instance".to_sym, :availability_zone)
219
224
  end
220
225
  outputs("#{_name}_public_ip".to_sym) do
221
226
  description 'Public IP address of the newly created EC2 instance'
222
- value _cf_attr("#{_name}_instance".to_sym, :public_ip)
227
+ value attr!("#{_name}_ec2_instance".to_sym, :public_ip)
223
228
  end
224
229
  outputs("#{_name}_private_ip".to_sym) do
225
230
  description 'Private IP address of the newly created EC2 instance'
226
- value _cf_attr("#{_name}_instance".to_sym, :private_ip)
231
+ value attr!("#{_name}_ec2_instance".to_sym, :private_ip)
227
232
  end
228
233
  outputs("#{_name}_public_dns".to_sym) do
229
234
  description 'Public DNSName of the newly created EC2 instance'
230
- value _cf_attr("#{_name}_instance".to_sym, :public_dns_name)
235
+ value attr!("#{_name}_ec2_instance".to_sym, :public_dns_name)
231
236
  end
232
237
  outputs("#{_name}_private_dns".to_sym) do
233
238
  description 'Private DNSName of the newly created EC2 instance'
234
- value _cf_attr("#{_name}_instance".to_sym, :private_dns_name)
239
+ value attr!("#{_name}_ec2_instance".to_sym, :private_dns_name)
235
240
  end
236
241
  end
237
242
  ```
@@ -242,12 +247,15 @@ resource easily:
242
247
  ```ruby
243
248
  SparkleFormation.new('ec2_example').load(:ami).overrides do
244
249
 
245
- description "AWS CloudFormation Sample Template EC2InstanceSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example uses the default security group, so to SSH to the new instance using the KeyPair you enter, you will need to have port 22 open in your default security group. **WARNING** This template an Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template."
250
+ description "AWS CloudFormation Sample Template ..."
246
251
 
247
- [:node1, :node2, :node3].each do |_node_name|
248
- SparkleFormation.insert(:ec2, self, _node_name)
252
+ %w(node1 node2 node3).each do |_node_name|
253
+ dynamic!(:node, _node_name)
249
254
  end
250
255
 
256
+ # and include one with predefined keypair
257
+
258
+ dynamic!(:node, 'snowflake', :key_pair => 'snowkeys')
251
259
  end
252
260
  ```
253
261
 
data/bin/aws_resources CHANGED
@@ -22,13 +22,47 @@ Dir.glob(File.join(STORE, '**/*.html')).each do |path|
22
22
  resource = nil
23
23
  begin
24
24
  file = Nokogiri::HTML(File.open(path, 'r'))
25
- type = file.css('h1.topictitle').text
25
+ type = file.css('h1.topictitle').text.strip
26
26
  if(type.include?(' '))
27
27
  next
28
28
  end
29
29
  resource = file.css('div.variablelist').first
30
30
  if(resource)
31
- aws_resources[type] = {:properties => resource.css('span.term').map(&:text).map(&:strip)}
31
+ names = resource.css('dt').css('span').map(&:text).map(&:strip)
32
+ types = resource.css('dd p').map(&:text).find_all do |x|
33
+ x.include?('Type')
34
+ end.map do |x|
35
+ if(x.downcase.match(/(\s|^)list(\s|$)/))
36
+ 'Array'
37
+ elsif(x.include?('Type: String'))
38
+ 'String'
39
+ elsif(x.include?('Type: Boolean'))
40
+ 'Boolean'
41
+ elsif(x.include?('Type: Integer'))
42
+ 'Number'
43
+ elsif(x.include?('Type:') && x.include?('JSON') && x.include?('document'))
44
+ 'JSON'
45
+ else
46
+ 'Unknown'
47
+ end
48
+ end
49
+ requires = resource.css('dd p').map(&:text).find_all do |x|
50
+ x.include?('Required:')
51
+ end.map do |x|
52
+ x.include?('No') ? false : true
53
+ end
54
+ descriptions = resource.css('dd').map do |dd|
55
+ dd.css('p').first.text.strip
56
+ end.map do |string|
57
+ string.split("\n").map(&:strip).join(' ')
58
+ end
59
+ property_hashes = names.size.times.map do |i|
60
+ [names[i], {:description => descriptions[i], :required => requires[i], :type => types[i]}]
61
+ end
62
+ aws_resources[type] = {
63
+ :properties => names,
64
+ :full_properties => Hash[property_hashes]
65
+ }
32
66
  else
33
67
  resource = file.css('div.informaltable')
34
68
  if(resource)
@@ -1,5 +1,5 @@
1
1
  SparkleFormation.new('ec2_example') do
2
- description "AWS CloudFormation Sample Template EC2InstanceSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example uses the default security group, so to SSH to the new instance using the KeyPair you enter, you will need to have port 22 open in your default security group. **WARNING** This template an Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template."
2
+ description "AWS CloudFormation Sample Template EC2InstanceSample..."
3
3
 
4
4
  parameters do
5
5
  key_name do
@@ -2,6 +2,8 @@ require 'sparkle_formation'
2
2
  require 'pp'
3
3
  require 'json'
4
4
 
5
+ SparkleFormation.sparkle_path = File.join(File.dirname(__FILE__), 'cloudformation')
6
+
5
7
  puts JSON.pretty_generate(
6
8
  SparkleFormation.compile(
7
9
  File.join(
@@ -1,41 +1,39 @@
1
1
  SparkleFormation.new('ec2_example').load(:ami).overrides do
2
- description "AWS CloudFormation Sample Template EC2InstanceSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example uses the default security group, so to SSH to the new instance using the KeyPair you enter, you will need to have port 22 open in your default security group. **WARNING** This template an Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template."
3
2
 
4
- resources do
5
- my_instance do
6
- type 'AWS::EC2::Instance'
7
- properties do
8
- key_name _cf_ref(:key_name)
9
- image_id _cf_map(:region_map, 'AWS::Region', :ami)
10
- user_data _cf_base64('80')
11
- end
3
+ description "AWS CloudFormation Sample Template EC2InstanceSample..."
4
+
5
+ dynamic!(:ec2_instance, :my) do
6
+ properties do
7
+ key_name ref!(:key_name)
8
+ image_id map!(:region_map, 'AWS::Region', :ami)
9
+ user_data base64!('80')
12
10
  end
13
11
  end
14
12
 
15
13
  outputs do
16
14
  instance_id do
17
15
  description 'InstanceId of the newly created EC2 instance'
18
- value _cf_ref(:my_instance)
16
+ value ref!(:my_ec2_instance)
19
17
  end
20
18
  az do
21
19
  description 'Availability Zone of the newly created EC2 instance'
22
- value _cf_attr(:my_instance, :availability_zone)
20
+ value attr!(:my_ec2_instance, :availability_zone)
23
21
  end
24
22
  public_ip do
25
23
  description 'Public IP address of the newly created EC2 instance'
26
- value _cf_attr(:my_instance, :public_ip)
24
+ value attr!(:my_ec2_instance, :public_ip)
27
25
  end
28
26
  private_ip do
29
27
  description 'Private IP address of the newly created EC2 instance'
30
- value _cf_attr(:my_instance, :private_ip)
28
+ value attr!(:my_ec2_instance, :private_ip)
31
29
  end
32
30
  public_dns do
33
31
  description 'Public DNSName of the newly created EC2 instance'
34
- value _cf_attr(:my_instance, :public_dns_name)
32
+ value attr!(:my_ec2_instance, :public_dns_name)
35
33
  end
36
34
  private_dns do
37
35
  description 'Private DNSName of the newly created EC2 instance'
38
- value _cf_attr(:my_instance, :private_dns_name)
36
+ value attr!(:my_ec2_instance, :private_dns_name)
39
37
  end
40
38
  end
41
39
  end
@@ -2,6 +2,8 @@ require 'sparkle_formation'
2
2
  require 'pp'
3
3
  require 'json'
4
4
 
5
+ SparkleFormation.sparkle_path = File.join(File.dirname(__FILE__), 'cloudformation')
6
+
5
7
  puts JSON.pretty_generate(
6
8
  SparkleFormation.compile(
7
9
  File.join(
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'multi_json'
19
20
  require 'attribute_struct'
20
21
 
21
22
  class SparkleFormation