cloud_former 0.7.12 → 0.8.0

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
  SHA1:
3
- metadata.gz: ca4e0066415458e1b308b34881e13df101730477
4
- data.tar.gz: 70dc364ad688eb1d51ecb86736c353886930accb
3
+ metadata.gz: 7572dd274fed161720cc0bf56518b9fdb0d4cfe2
4
+ data.tar.gz: 608558f4dd6f2fd242130b6a22dbda0cadf29a9e
5
5
  SHA512:
6
- metadata.gz: 3e447a2b1ba44a4df5b9895ad595e5c39fad7cbdb3e786df3635bffea03420d76e72e927ccd41f5cab354e8fa747cfda9d3e6e3b732083945f8d60bb1ea5c988
7
- data.tar.gz: 8ea81d86feca1a79f97fa2bfcd45716057c343ece50646a4e752b8ae302a8f54b173ee7c7662f0bc73d5a7247733fb54442b9f386c1b6041eca8eb98fb7dade3
6
+ metadata.gz: ee3881b6dea3cd6bfee8ec8ebc22fea001e19fdd5e2589a0e11c78b981f29550daa5ead304a6a8e5401afa6065ad49dfdecdb26506b0633e0bb6f20b21c00c0b
7
+ data.tar.gz: 336f51df5f003b6ca5e9fc7038f6975503e4afc5fba8795f6dc609ca1d0f452a743988dc15659b1f0797375b3808294f64b78b1b172d8671ac6d82f22735d7a2
data/lib/cloud_former.rb CHANGED
@@ -3,6 +3,28 @@ require 'cloud_former/has_properties_and_attributes'
3
3
  require 'cloud_former/makes_json'
4
4
 
5
5
  module CloudFormer
6
+ def self.types
7
+ @types ||= {}
8
+ end
9
+
10
+ def self.type_to_class(type)
11
+ mod, name = types[type]
12
+ return nil if mod.nil?
13
+ value = mod.const_get(name)
14
+ value.is_a?(Class) && value < Resource ? value : nil
15
+ end
16
+
17
+ refine Module do
18
+ def autoload(constant_name, path)
19
+ super
20
+ namespace = self.name.to_s.sub(/\ACloudFormer::/, '').gsub(/([a-z])([A-Z])/, '\\1_\\2').gsub('::', '.').downcase
21
+ base_name = constant_name.to_s.gsub(/([a-z])([A-Z])/, '\\1_\\2').downcase
22
+ ::CloudFormer.types["#{namespace}.#{base_name}"] = [self, constant_name]
23
+ end
24
+ end
25
+
26
+ using self
27
+
6
28
  autoload :Boolean, 'cloud_former/boolean'
7
29
  autoload :Parameter, 'cloud_former/parameters/parameter'
8
30
  autoload :CommaDelimitedListParameter, 'cloud_former/parameters/comma_delimited_list_parameter'
@@ -132,6 +154,12 @@ module CloudFormer
132
154
  autoload :VPNGatewayRoutePropagation, 'cloud_former/resources/ec2/vpn_gateway_route_propagation'
133
155
  end
134
156
 
157
+ module EFS
158
+ autoload :FileSystem, 'cloud_former/resources/efs/file_system'
159
+ autoload :FileSystemTag, 'cloud_former/resource_properties/efs/file_system_tag'
160
+ autoload :MountTarget, 'cloud_former/resources/efs/mount_target'
161
+ end
162
+
135
163
  module ElastiCache
136
164
  autoload :CacheCluster, 'cloud_former/resources/elasti_cache/cache_cluster'
137
165
  autoload :ParameterGroup, 'cloud_former/resources/elasti_cache/parameter_group'
@@ -0,0 +1,9 @@
1
+ # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-efs-filesystem-filesystemtags.html
2
+ module CloudFormer
3
+ module EFS
4
+ class FileSystemTag < ResourceProperty
5
+ aws_attribute :key, type: String
6
+ aws_attribute :value, type: String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html
2
+ module CloudFormer
3
+ module EFS
4
+ class FileSystem < Resource
5
+ aws_property :file_system_tags, list: true, embed: true, type: FileSystemTag
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-mounttarget.html
2
+ module CloudFormer
3
+ module EFS
4
+ class MountTarget < Resource
5
+ aws_property :file_system_id, type: String
6
+ aws_property :ip_address, type: String
7
+ aws_property :security_groups, list: true, type: String
8
+ aws_property :subnet_id, type: String
9
+ end
10
+ end
11
+ end
@@ -25,9 +25,19 @@ module CloudFormer
25
25
  param
26
26
  end
27
27
 
28
- def add_resource(resource)
28
+ def add_resource(*args, &block)
29
+ if args.size == 1
30
+ resource = args.first
31
+ elsif args.size == 2
32
+ type, name = *args
33
+ klass = CloudFormer.type_to_class(type)
34
+ resource = klass.new(name, &block)
35
+ else
36
+ raise ArgumentErrror, "wrong number of args (#{args.size} for 1..2)"
37
+ end
29
38
  raise "Overwriting resource with name #{resource.get_name}" if @resources.any? { |r| r.get_name == resource.get_name }
30
39
  @resources << resource
40
+ resource
31
41
  end
32
42
 
33
43
  def resource(name)
@@ -1,3 +1,3 @@
1
1
  module CloudFormer
2
- VERSION = '0.7.12'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudFormer do
4
+ describe ".type_to_class" do
5
+ it "returns the class for the given resource type" do
6
+ klass = CloudFormer.type_to_class('ec2.security_group')
7
+ expect(klass).to be(CloudFormer::EC2::SecurityGroup)
8
+ end
9
+
10
+ it "is nil for non-Resource constants" do
11
+ expect(CloudFormer.type_to_class('ec2.mount_point')).to be_nil
12
+ end
13
+
14
+ it "is nil for rubbish" do
15
+ expect(CloudFormer.type_to_class('rubbish')).to be_nil
16
+ end
17
+ end
18
+ end
@@ -24,45 +24,6 @@ describe CloudFormer::HasPropertiesAndAttributes do
24
24
  )
25
25
  end
26
26
 
27
- it "supports builds nested resource lists via blocks" do
28
- auto_scaling_group = CloudFormer::AutoScaling::LaunchConfiguration.new('myconfig') do
29
- image_id 'ami-123456'
30
- security_groups(2) do |i|
31
- name "name #{i}"
32
- group_description "security group #{i}"
33
- end
34
- end
35
- template.add_resource(auto_scaling_group)
36
-
37
- expect(template.dump_json).to eq(
38
- "AWSTemplateFormatVersion" => "2010-09-09",
39
- "Resources" => {
40
- "myconfig" => {
41
- "Type" => "AWS::AutoScaling::LaunchConfiguration",
42
- "Properties" => {
43
- "ImageId" => "ami-123456",
44
- "SecurityGroups" => [
45
- {"Ref" => "name 0"},
46
- {"Ref" => "name 1"},
47
- ],
48
- },
49
- },
50
- "name 0" => {
51
- "Type" => "AWS::EC2::SecurityGroup",
52
- "Properties" => {
53
- "GroupDescription" => "security group 0",
54
- },
55
- },
56
- "name 1" => {
57
- "Type" => "AWS::EC2::SecurityGroup",
58
- "Properties" => {
59
- "GroupDescription" => "security group 1",
60
- },
61
- },
62
- },
63
- )
64
- end
65
-
66
27
  it "supports builds nested resource properties via blocks" do
67
28
  instance = CloudFormer::EC2::Instance.new('myinstance') do
68
29
  # list
@@ -55,7 +55,7 @@ describe 'stupid metadata' do
55
55
  },
56
56
  'Metadata' => {
57
57
  'AWS::CloudFormation::Authentication' => {
58
- authentication_item.name => {
58
+ authentication_item.get_name => {
59
59
  'accessKeyId' => 12,
60
60
  'password' => 'ack',
61
61
  'secretKey' => 'boom'
@@ -148,5 +148,3 @@ describe 'stupid metadata' do
148
148
  end
149
149
 
150
150
  end
151
-
152
-
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudFormer::EFS::FileSystem do
4
+ it "should generate correct json" do
5
+ fs = CloudFormer::EFS::FileSystem.new('file_system') do
6
+ file_system_tags :list do
7
+ entry do
8
+ key 'Name'
9
+ value 'TestFileSystem'
10
+ end
11
+ end
12
+ end
13
+
14
+ expect(fs.dump_json).to eq({
15
+ "Type" => "AWS::EFS::FileSystem",
16
+ "Properties" => {
17
+ "FileSystemTags" => [
18
+ {
19
+ "Key" => "Name",
20
+ "Value" => "TestFileSystem",
21
+ },
22
+ ]
23
+ }
24
+ })
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudFormer::EFS::MountTarget do
4
+ it "should generate correct json" do
5
+ fs = CloudFormer::EFS::MountTarget.new('mount_target') do
6
+ file_system_id 'fs-123'
7
+ subnet_id 'subnet-123'
8
+ security_groups ['sg-123', 'sg-456']
9
+ end
10
+
11
+ expect(fs.dump_json).to eq({
12
+ "Type" => "AWS::EFS::MountTarget",
13
+ "Properties" => {
14
+ "FileSystemId"=> "fs-123",
15
+ "SubnetId" => "subnet-123",
16
+ "SecurityGroups" => ["sg-123", "sg-456"],
17
+ }
18
+ })
19
+ end
20
+ end
@@ -37,7 +37,7 @@ describe CloudFormer::Template do
37
37
  expect(template.dump_json).to eq(
38
38
  'AWSTemplateFormatVersion' => '2010-09-09',
39
39
  'Resources' => {
40
- resource.name => {
40
+ resource.get_name => {
41
41
  'Type' => resource.aws_type,
42
42
  'Properties' => {
43
43
  'Status' => 'Active',
@@ -47,4 +47,22 @@ describe CloudFormer::Template do
47
47
  },
48
48
  )
49
49
  end
50
+
51
+ it "can add resources inline" do
52
+ resource = template.add_resource 'ec2.instance', 'MyInstance' do
53
+ availability_zone 'us-east-1a'
54
+ end
55
+ expect(template.dump_json).to eq(
56
+ 'AWSTemplateFormatVersion' => '2010-09-09',
57
+ 'Resources' => {
58
+ 'MyInstance' => {
59
+ 'Type' => 'AWS::EC2::Instance',
60
+ 'Properties' => {
61
+ 'AvailabilityZone' => 'us-east-1a',
62
+ },
63
+ },
64
+ },
65
+ )
66
+ expect(resource).to be_a(CloudFormer::EC2::Instance)
67
+ end
50
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_former
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aubrey Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -167,6 +167,7 @@ files:
167
167
  - lib/cloud_former/resource_properties/ec2/private_ip_address_specification.rb
168
168
  - lib/cloud_former/resource_properties/ec2/security_group_rule.rb
169
169
  - lib/cloud_former/resource_properties/ec2/tag.rb
170
+ - lib/cloud_former/resource_properties/efs/file_system_tag.rb
170
171
  - lib/cloud_former/resource_properties/elastic_beanstalk/environment_tier.rb
171
172
  - lib/cloud_former/resource_properties/elastic_beanstalk/option_setting.rb
172
173
  - lib/cloud_former/resource_properties/elastic_beanstalk/source_bundle.rb
@@ -249,6 +250,8 @@ files:
249
250
  - lib/cloud_former/resources/ec2/vpn_connection_route.rb
250
251
  - lib/cloud_former/resources/ec2/vpn_gateway.rb
251
252
  - lib/cloud_former/resources/ec2/vpn_gateway_route_propagation.rb
253
+ - lib/cloud_former/resources/efs/file_system.rb
254
+ - lib/cloud_former/resources/efs/mount_target.rb
252
255
  - lib/cloud_former/resources/elasti_cache/cache_cluster.rb
253
256
  - lib/cloud_former/resources/elasti_cache/parameter_group.rb
254
257
  - lib/cloud_former/resources/elasti_cache/security_group.rb
@@ -290,6 +293,7 @@ files:
290
293
  - lib/cloud_former/resources/sqs/queue_policy.rb
291
294
  - lib/cloud_former/template.rb
292
295
  - lib/cloud_former/version.rb
296
+ - spec/cloud_former_spec.rb
293
297
  - spec/conditions_spec.rb
294
298
  - spec/has_properties_and_attributes_spec.rb
295
299
  - spec/metadata_spec.rb
@@ -298,6 +302,8 @@ files:
298
302
  - spec/resources/auto_scaling/auto_scaling_group_spec.rb
299
303
  - spec/resources/auto_scaling/launch_configuration_spec.rb
300
304
  - spec/resources/auto_scaling/notification_configuration_spec.rb
305
+ - spec/resources/efs/file_system_spec.rb
306
+ - spec/resources/efs/mount_target_spec.rb
301
307
  - spec/resources/iam/access_key_spec.rb
302
308
  - spec/resources/iam/user_spec.rb
303
309
  - spec/resources/list_spec.rb
@@ -326,11 +332,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
332
  version: '0'
327
333
  requirements: []
328
334
  rubyforge_project:
329
- rubygems_version: 2.5.1
335
+ rubygems_version: 2.6.6
330
336
  signing_key:
331
337
  specification_version: 4
332
338
  summary: A Ruby DSL for creating CloudFormation templates
333
339
  test_files:
340
+ - spec/cloud_former_spec.rb
334
341
  - spec/conditions_spec.rb
335
342
  - spec/has_properties_and_attributes_spec.rb
336
343
  - spec/metadata_spec.rb
@@ -339,6 +346,8 @@ test_files:
339
346
  - spec/resources/auto_scaling/auto_scaling_group_spec.rb
340
347
  - spec/resources/auto_scaling/launch_configuration_spec.rb
341
348
  - spec/resources/auto_scaling/notification_configuration_spec.rb
349
+ - spec/resources/efs/file_system_spec.rb
350
+ - spec/resources/efs/mount_target_spec.rb
342
351
  - spec/resources/iam/access_key_spec.rb
343
352
  - spec/resources/iam/user_spec.rb
344
353
  - spec/resources/list_spec.rb