cfndsl 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ require 'cfndsl/JSONable'
2
+
3
+ module CfnDsl
4
+ class PropertyDefinition < JSONable
5
+ ##
6
+ # Handles property objects for Resources
7
+ #
8
+ # Usage
9
+ # Resource("aaa") {
10
+ # Property("propName", "propValue" )
11
+ # }
12
+ #
13
+ def initialize(value)
14
+ @value = value;
15
+ end
16
+
17
+ def value
18
+ return @value
19
+ end
20
+
21
+ def to_json(*a)
22
+ @value.to_json(*a)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+
2
+ module RefCheck
3
+ ##
4
+ # This module defines some methods for walking the reference tree
5
+ # of various objects.
6
+ #
7
+ def references(refs)
8
+ ##
9
+ # Build up a set of references.
10
+ #
11
+ raise "Circular reference" if @_visited
12
+
13
+ @_visited = true
14
+
15
+ if( self.respond_to?(:get_references ) ) then
16
+ self.get_references.each do |ref|
17
+ refs[ref.to_s] = 1
18
+ end
19
+ end
20
+
21
+ self.ref_children.each do |elem|
22
+ elem.references(refs) if elem.respond_to?(:references)
23
+ end
24
+
25
+ @_visited = nil
26
+
27
+ return refs
28
+ end
29
+
30
+ def ref_children
31
+ return []
32
+ end
33
+
34
+ end
35
+
36
+ class Array
37
+ include RefCheck
38
+ def ref_children
39
+ return self
40
+ end
41
+ end
42
+
43
+ class Hash
44
+ include RefCheck
45
+ def ref_children
46
+ return self.values
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ require 'cfndsl/JSONable'
2
+ require 'cfndsl/Metadata'
3
+ require 'cfndsl/Properties'
4
+
5
+ module CfnDsl
6
+ class ResourceDefinition < JSONable
7
+ ##
8
+ # Handles Resource objects
9
+ dsl_attr_setter :Type, :DependsOn, :DeletionPolicy
10
+ dsl_content_object :Property, :Metadata
11
+
12
+ def get_references()
13
+ refs = []
14
+ if @DependsOn then
15
+ if( @DependsOn.respond_to?(:each) ) then
16
+ @DependsOn.each do |dep|
17
+ refs.push dep
18
+ end
19
+ end
20
+
21
+ if( @DependsOn.instance_of?(String) ) then
22
+ refs.push @DependsOn
23
+ end
24
+ end
25
+ refs
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,116 @@
1
+ require 'yaml'
2
+ require 'cfndsl/JSONable'
3
+ require 'cfndsl/Plurals'
4
+
5
+ module CfnDsl
6
+ module Types
7
+
8
+ aws_types = YAML::load( File.open( "#{File.dirname(__FILE__)}/aws_types.yaml") );
9
+ Types.const_set( "AWS_Types", aws_types);
10
+
11
+ # Do a little sanity checking - all of the types referenced in Resources
12
+ # should be represented in Types
13
+ aws_types["Resources"].keys.each do |resource_name|
14
+ #puts resource_name
15
+ resource = aws_types["Resources"][resource_name]
16
+ resource.values.each do |thing|
17
+ thing.values.each do |type|
18
+ if( type.kind_of? Array ) then
19
+ type.each do | type |
20
+ puts "unknown type #{type}" unless aws_types["Types"].has_key? type
21
+ end
22
+ else
23
+ puts "unknown type #{type}" unless aws_types["Types"].has_key? type
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ # All of the type values should also be references
30
+
31
+ aws_types["Types"].values do |type|
32
+ if( type.respond_to? :values) then
33
+ type.values.each do |tv|
34
+ puts "unknown type #{tv}" unless aws_types["Types"].has_key? tv
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+
41
+ # declare classes for all of the types with named methods for setting the values
42
+ class AWSType < JSONable
43
+ end
44
+
45
+ classes = {}
46
+
47
+ # Go through and declare all of the types first
48
+ aws_types["Types"].each_key do |typename|
49
+ if( ! Types.const_defined? typename ) then
50
+ klass = Types.const_set( typename, Class.new(AWSType ) )
51
+ classes[typename] = klass
52
+ else
53
+ classes[typename] = Types.const_get(typename)
54
+ end
55
+ end
56
+
57
+ # Now go through them again and define attribute setter methods
58
+ classes.each_pair do |typename,type|
59
+ #puts typename
60
+ typeval = aws_types["Types"][typename]
61
+ if( typeval.respond_to? :each_pair ) then
62
+ typeval.each_pair do |attr_name, attr_type|
63
+ if( attr_type.kind_of? Array ) then
64
+ klass = CfnDsl::Types.const_get( attr_type[0] )
65
+ variable = "@#{attr_name}".to_sym
66
+ method = CfnDsl::Plurals::singularize(attr_name)
67
+ methods = attr_name
68
+
69
+ type.class_eval do
70
+ define_method(method) do | value=nil, *rest, &block|
71
+ value ||= klass.new
72
+ x = instance_variable_get( variable )
73
+ if( !x ) then
74
+ x = instance_variable_set( variable, [] )
75
+ end
76
+ x.push value
77
+ value.instance_eval &block if block
78
+ value
79
+ end
80
+
81
+ type.class_eval do
82
+ define_method(methods) do | value, &block |
83
+ x = instance_variable_get( variable )
84
+ if( !x ) then
85
+ x = instance_variable_set( variable, [] )
86
+ end
87
+
88
+ if( ! value.type_of? Array) then
89
+ value = [value]
90
+ end
91
+ value.each do |v|
92
+ x.push v
93
+ v.instance_eval &block if block
94
+ end
95
+ end
96
+ end
97
+ end
98
+ else
99
+ klass = CfnDsl::Types.const_get( attr_type );
100
+ variable = "@#{attr_name}".to_sym
101
+
102
+ type.class_eval do
103
+ define_method(attr_name) do | value=nil, *rest, &block |
104
+ value ||= klass.new
105
+ instance_variable_set( variable, value )
106
+ value.instance_eval &block if block
107
+ value
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+
@@ -0,0 +1,442 @@
1
+ Resources:
2
+ "AWS::AutoScaling::AutoScalingGroup" :
3
+ Properties:
4
+ AvailabilityZones: [ String ]
5
+ Cooldown: String
6
+ DesiredCapacity: String
7
+ HealthCheckGracePeriod: Integer
8
+ HealthCheckType: String
9
+ LaunchConfigurationName: String
10
+ LoadBalancers: [ String ]
11
+ MaxSize: Integer
12
+ MinSize: Integer
13
+ NotificationConfiguration: String
14
+ Tags: [ AutoScalingTags ]
15
+ VPCZoneIdentifier: [ String ]
16
+ "AWS::AutoScaling::LaunchConfiguration" :
17
+ Properties:
18
+ BlockDeviceMappings: [ BlockDeviceMapping ]
19
+ ImageId: String
20
+ InstanceType: String
21
+ KernelId: String
22
+ KeyName: String
23
+ RamDiskId: String
24
+ SecurityGroups: [ String ]
25
+ UserData: String
26
+ "AWS::Autoscaling::ScalingPolicy" :
27
+ Properties:
28
+ AdjustmentType: String
29
+ AutoScalingGroupName: String
30
+ Cooldown: String
31
+ ScalingAdjustment: String
32
+ "AWS::Autoscaling::Trigger" :
33
+ Properties:
34
+ Dimensions: [ MetricDimension ]
35
+ MetricName: String
36
+ Namespace: String
37
+ Period: String
38
+ Statistic: String
39
+ Unit: String
40
+ UpperBreachScaleIncrement: String
41
+ LowerBreachScaleIncrement: String
42
+ AutoScalingGroupName: String
43
+ BreachDuration: String
44
+ UpperThreshold: String
45
+ LowerThreshold: String
46
+ "AWS::CloudFormation::Stack" :
47
+ Properties:
48
+ TemplateUrl: String
49
+ TimeoutInMinutes: String
50
+ Parameters: CloudFormationStackParameters
51
+ "AWS::CloudFormation::WaitCondition" :
52
+ Properties:
53
+ Handle: String
54
+ Timeout: String
55
+ Count: String
56
+ Attributes:
57
+ Data: String
58
+ "AWS::CloudFormation::WaitConditionHandle" :
59
+ Properties: {}
60
+ "AWS::CloudFront::Distribution" :
61
+ Properties:
62
+ DistributionConfig: String
63
+ Attributes:
64
+ DomainName: String
65
+ "AWS::CloudWatch::Alarm" :
66
+ Properties:
67
+ ActionsEnabled: String
68
+ AlarmActions: [ String ]
69
+ AlarmDescription: String
70
+ ComparisonOperator: String
71
+ Dimensions: [ MetricDimension ]
72
+ EvaluationPeriods: String
73
+ InsufficientDataActions: [ String ]
74
+ MetricName: String
75
+ Namespace: String
76
+ OKActions: [ String ]
77
+ Period: String
78
+ Statistic: String
79
+ Threshold: String
80
+ Unit: String
81
+ "AWS::EC2::EIP" :
82
+ Properties:
83
+ InstanceId: String
84
+ Domain: String
85
+ Attributes:
86
+ AllocationId: String
87
+ "AWS::EC2::EIPAssociation" :
88
+ Properties:
89
+ InstanceId: String
90
+ EIP: String
91
+ AllocationId: String
92
+ "AWS::EC2::Instance" :
93
+ Properties:
94
+ AvailabilityZone: String
95
+ DisableApiTermination: String
96
+ ImageId: String
97
+ InstanceType: String
98
+ KernelId: String
99
+ KeyName: String
100
+ Monitoring: String
101
+ PlacementGroupName: String
102
+ PrivateIpAddress: String
103
+ RamDiskId: String
104
+ SecurityGroups: [String]
105
+ SecurityGroupIds: [String]
106
+ SourceDestCheck: Boolean
107
+ SubnetId: String
108
+ Tags: [ EC2Tag ]
109
+ Tenancey: String
110
+ UserData: String
111
+ Volumes: [ EC2MountPoint ]
112
+ Attributes:
113
+ AvailabilityZone: String
114
+ PrivateDnsName: String
115
+ PublicDnsName: String
116
+ PrivateIp: String
117
+ PublicIp: String
118
+ "AWS::EC2::SecurityGroup" :
119
+ Properties:
120
+ GroupDescription: String
121
+ SecurityGroupIngress: EC2SecurityGroupRule
122
+ SecurityGroupEgress: EC2SecurityGroupRule
123
+ VpcId: String
124
+ "AWS::EC2::SecurityGroupEgress" :
125
+ Properties:
126
+ GroupId: String
127
+ IpProtocol: String
128
+ CidrIp: String
129
+ DestinationSecurityGroupId: String
130
+ FromPort: Number
131
+ ToPort: Number
132
+ "AWS::EC2::SecurityGroupIngress":
133
+ Properties:
134
+ GroupName: String
135
+ GroupId: String
136
+ IpProtocol: String
137
+ CidrIp: String
138
+ SourceSecurtityGroupName: String
139
+ SourceSecurtityGroupId: String
140
+ SourceSecurityGroupOwnerId: String
141
+ FromPort: Number
142
+ ToPort: Number
143
+ "AWS::EC2::Volume" :
144
+ Properties:
145
+ AvailabilityZone: String
146
+ Size: String
147
+ SnapshotId: String
148
+ Tags: [ EC2Tag ]
149
+ "AWS::EC2::VolumeAttachment" :
150
+ Properties:
151
+ InstanceId: String
152
+ VolumeId: String
153
+ Device: String
154
+ "AWS::ElastiCache::CacheCluster" :
155
+ Properties:
156
+ AutoMinorVersionUpgrade: Boolean
157
+ CacheNodeType: String
158
+ CacheParameterGroupName: String
159
+ CacheSecurityGroupNames: [String]
160
+ Engine: String
161
+ EngineVersion: String
162
+ NotificationTopicArn: String
163
+ NumCacheNodes: String
164
+ Port: Integer
165
+ PreferrredAvailabilityZone: String
166
+ PreferredMaintenanceWindow: String
167
+ "AWS::ElastiCache::ParameterGroup" :
168
+ Properties:
169
+ CacheParameterGroupFamily: String
170
+ Description: String
171
+ Properties: [ String ]
172
+ "AWS::ElastiCache::SecurityGroup" :
173
+ Properties:
174
+ Decription: String
175
+ "AWS::ElastiCache::SecurityGrouIngress" :
176
+ Properties:
177
+ CacheSecurityGroupName: String
178
+ EC2SecurityGroupName: String
179
+ EC2SecurityGroupOwnerId: String
180
+ "AWS::ElasticBeanstalk::Application" :
181
+ Properties:
182
+ ApplicationVersions: [ ApplicationVersion ]
183
+ ConfigurationTemplates: [ ConfigurationTemplate ]
184
+ "AWS::ElasticBeanstalk::Environment" :
185
+ Properties:
186
+ ApplicationName: String
187
+ CNAMEPrefix: String
188
+ OptionSettings: OptionSetting
189
+ OptionsToRemove: OptionSetting
190
+ SolutionStackName: String
191
+ TemplateName: String
192
+ VersionLabel: String
193
+ "AWS::ElasticLoadBalancing::LoadBalancer" :
194
+ Properties:
195
+ AvailabilityZones: [String]
196
+ HealthCheck: HealthCheck
197
+ Instances: [String]
198
+ Listeners: [ Listener ]
199
+ AppCookieStickinessPolicy: AppCookieStickinessPolicy
200
+ LBCookieStickinessPolicy: LBCookieStickinessPolicy
201
+ SecurityGroups: [ String ]
202
+ Subnets: [ String ]
203
+ Attributes:
204
+ CanonicalHostedZoneName: String
205
+ CanonicalGostedZoneNameID: String
206
+ DNSName: String
207
+ SourceSecurityGroup.GroupName: String
208
+ SourceSecurityGroup.OwnerAlias: String
209
+ "AWS::IAM::AccessKey" :
210
+ Properties:
211
+ Serial: Integer
212
+ Status: String
213
+ UserName: String
214
+ Attributes:
215
+ SecretAccessKey: String
216
+ "AWS::IAM::Group" :
217
+ Properties:
218
+ Path: String
219
+ Policies: [ IAMEmbeddedPolicy ]
220
+ Attributes:
221
+ Arn : String
222
+ "AWS::IAM::Policy" :
223
+ Properties:
224
+ PolicyName: String
225
+ PolocyDocument: JSON
226
+ Groups: [ String ]
227
+ Users: [ String ]
228
+ "AWS::IAM::UserToGroupAddition" :
229
+ Properties:
230
+ Group: String
231
+ Users: [String]
232
+ "AWS::IAM::User" :
233
+ Properties:
234
+ Path: String
235
+ Groups: [String]
236
+ LoginProfile: String
237
+ Policies: [ IAMEmbeddedPolicy ]
238
+ Attributes:
239
+ Arn: String
240
+ "AWS::RDS::DBInstance" :
241
+ Properties:
242
+ DBSnapshotIdentifier: String
243
+ AllocatedStorage: String
244
+ AvailabilityZone: String
245
+ BackupRetentionPeriod: String
246
+ DBInstanceClass: String
247
+ DBName: String
248
+ DBParameterGroupName: String
249
+ DBSecurityGroups: [ String ]
250
+ DBSubnetGroupName: String
251
+ Engine: String
252
+ EngineVersion: String
253
+ LicenseModel: String
254
+ MasterUsername: String
255
+ MasterUserPassword: String
256
+ Port: String
257
+ PreferredBackupWindow: String
258
+ PreferredMaintenanceWindow: String
259
+ MultiAZ: Boolean
260
+ Attributes:
261
+ DBInstanceIdentifier: String
262
+ Endpoint.Address: String
263
+ Endpoint.Port: String
264
+ "AWS::RDS::DBSecurityGroup" :
265
+ Properties:
266
+ DBSubnetGroupDescription: String
267
+ SubnetIds: [ String ]
268
+ "AWS::RDS::SecurityGroup" :
269
+ Properties:
270
+ DBSecurityGroupIngress: RDSSecurityGroupRule
271
+ EC2VpcId: String
272
+ GroupDescription: String
273
+ "AWS::RDS::SecurityGroupIngress" :
274
+ Properties:
275
+ CIDRIR: String
276
+ EC2SecurityGroupId: String
277
+ EC2SecurityGroupOwnerId: String
278
+ "AWS::Route53::RecordSet" :
279
+ Properties:
280
+ HostedZoneId: String
281
+ HostedZoneName: String
282
+ Name: String
283
+ Type: String
284
+ TTL: String
285
+ ResoureRecords: [ String ]
286
+ Weight: Integer
287
+ SetIdentifier: String
288
+ AliasTarget: String
289
+ Comment: String
290
+ "AWS::Route53::RecordSetGroup" :
291
+ Properties:
292
+ HostedZoneId: String
293
+ HostedZoneName: String
294
+ RecordSets: [ JSON ]
295
+ "AWS::S3::Bucket" :
296
+ Properties:
297
+ AccessControl: String
298
+ WebsiteConfiguration: JSON
299
+ Attributes:
300
+ DomainName: String
301
+ WebsiteUrl: String
302
+ "AWS::S3::BucketPolicy" :
303
+ Properties:
304
+ PolicyDocument: JSON
305
+ Bucket: String
306
+ "AWS::SDB::Domain" :
307
+ Properties: {}
308
+ "AWS::SNS::TopicPolicy" :
309
+ Properties:
310
+ PolicyDocument: JSON
311
+ Topics: [ String ]
312
+ # "AWS::SNS::Subscription" :
313
+ "AWS::SNS::Topic" :
314
+ Properties: {}
315
+ "AWS::SQS::QueuePolicy" :
316
+ Properties:
317
+ PolicyDocument: JSON
318
+ Queues: [ String ]
319
+ "AWS::SQS::Queue" :
320
+ Properties:
321
+ VisibilityTimeout: String
322
+ Attributes:
323
+ Arn: String
324
+ QueueName: String
325
+
326
+
327
+ Types:
328
+ String: String
329
+ Boolean: Boolean
330
+ JSON: JSON
331
+ Integer: Integer
332
+ Number: Number
333
+ BlockDeviceMapping:
334
+ DeviceName: String
335
+ VirtualName: String
336
+ Ebs: BlockDeviceTemplate
337
+ BlockDeviceTemplate:
338
+ SnapshotId: String
339
+ VolumeSize: String
340
+ NotificationConfiguration:
341
+ TopicARN: String
342
+ NotificationType: [ String ]
343
+ AutoScalingTags:
344
+ Key: String
345
+ Value: String
346
+ PropagateAtLaunch: Boolean
347
+ CloudFormationStackParameters: JSON
348
+ CloudFrontDistributionConfig:
349
+ S3Origin: CloudFrontS3Origin
350
+ CustomOrigin: CloudFrontCustomOrigin
351
+ Enabled: Boolean
352
+ DefaultRootObject: String
353
+ CNAMEs: [ String ]
354
+ Logging: CloudFrontLogging
355
+ TrustedSigners: [ String ]
356
+ RequiredProtocols: [ String ]
357
+ Comment: String
358
+ CloudFrontS3Origin:
359
+ DNSName: String
360
+ OriginAccessIdentity: String
361
+ CloudFrontCustomOrigin:
362
+ DNSName: String
363
+ OriginProtocolPolicy: String
364
+ HTTPPort: String
365
+ HTTPSPort: String
366
+ CloudFrontLogging:
367
+ Bucket: String
368
+ Prefix: String
369
+ MetricDimension:
370
+ Name: String
371
+ Value: String
372
+ EC2MountPoint:
373
+ Device: String
374
+ VolumeId: String
375
+ EC2SecurityGroupRule:
376
+ IpProtocol: String
377
+ CidrIp: String
378
+ SourceSecurityGroupName: String
379
+ SourceSecurityGroupId: String
380
+ SourceSecurityGroupOwnerId: String
381
+ FromPort: String
382
+ ToPort: String
383
+ EC2Tag:
384
+ Key: String
385
+ Value: String
386
+ ApplicationVersion:
387
+ VersionLabel: String
388
+ SourceBundle: SourceBundle
389
+ ConfigurationTemplate:
390
+ TemplateName: String
391
+ OptionSettings: OptionSetting
392
+ SolutionStackName: String
393
+ OptionSetting:
394
+ NameSpace: String
395
+ OptionName: String
396
+ Value: String
397
+ SourceBundle:
398
+ S3Bucket: String
399
+ S3Key: String
400
+ AppCookieStickinessPolicy:
401
+ CookieName: String
402
+ PolicyName: String
403
+ HealthCheck:
404
+ HealthyThreshold: String
405
+ Interval: String
406
+ Target: String
407
+ Timeout: String
408
+ UnhealthyThreshold: String
409
+ LBCookieStickinessPolicy:
410
+ CookieExpirationPeriod: String
411
+ PolicyName: String
412
+ LBOrAppCookieStickinessPolicy:
413
+ CookieName: String
414
+ PolicyName: String
415
+ CookieExpirationPeriod: String
416
+ Listener:
417
+ InstancePort: String
418
+ LoadBalancerPort: String
419
+ Protocol: String
420
+ SSLCertificate: String
421
+ PolicyNames: [ LBOrAppCookieStickinessPolicy ]
422
+ RDSSecurityGroupRule:
423
+ CIDRIP: String
424
+ EC2SecurityGroupName: String
425
+ EC2SecurityGroupOwnerId: String
426
+ AliasTarget:
427
+ HostedZoneId: String
428
+ DNSName: String
429
+ WebsiteConfiguration:
430
+ IndexDocument: String
431
+ ErrorDocument: String
432
+ SubscriptionProperty:
433
+ Endpoint: String
434
+ Protocol: String
435
+ IAMEmbeddedPolicy:
436
+ PolicyDocument: JSON
437
+ PolicyName: String
438
+
439
+
440
+
441
+
442
+