cf_factory 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/examples/base_vpc.rb +40 -0
  2. data/examples/cloudinit_script_for_one_instance.rb +77 -0
  3. data/examples/cloudinit_script_with_autoscaling.rb +85 -0
  4. data/examples/elb_with_cloudfront.rb +101 -0
  5. data/examples/instance_with_eip.rb +38 -0
  6. data/examples/instance_with_yum.rb +38 -0
  7. data/examples/just_an_instance.rb +29 -0
  8. data/examples/play_with_region_and_zones.rb +26 -0
  9. data/examples/ra_web_hosting.rb +146 -0
  10. data/examples/s3_with_cloudfront.rb +36 -0
  11. data/examples/test_vpc.rb +53 -0
  12. data/lib/cf_factory/as/cf_as_group.rb +75 -0
  13. data/lib/cf_factory/as/cf_as_launch_config.rb +53 -0
  14. data/lib/cf_factory/as/cf_as_scaling_policy.rb +33 -0
  15. data/lib/cf_factory/base/cf_base.rb +97 -0
  16. data/lib/cf_factory/base/cf_ec2_tag.rb +32 -0
  17. data/lib/cf_factory/base/cf_generator.rb +18 -0
  18. data/lib/cf_factory/base/cf_helper.rb +91 -0
  19. data/lib/cf_factory/base/cf_inner.rb +55 -0
  20. data/lib/cf_factory/base/cf_main.rb +101 -0
  21. data/lib/cf_factory/base/cf_mapping.rb +26 -0
  22. data/lib/cf_factory/base/cf_named_inner.rb +0 -0
  23. data/lib/cf_factory/base/cf_output.rb +24 -0
  24. data/lib/cf_factory/base/cf_parameter.rb +25 -0
  25. data/lib/cf_factory/base/cf_script_reader.rb +32 -0
  26. data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +25 -0
  27. data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +37 -0
  28. data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +25 -0
  29. data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +33 -0
  30. data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +38 -0
  31. data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +25 -0
  32. data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +28 -0
  33. data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +34 -0
  34. data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +42 -0
  35. data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +30 -0
  36. data/lib/cf_factory/cloudformation/cf_init_script.rb +73 -0
  37. data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +37 -0
  38. data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +28 -0
  39. data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +64 -0
  40. data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +37 -0
  41. data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +32 -0
  42. data/lib/cf_factory/cloudfront/cf_distribution_config.rb +31 -0
  43. data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +25 -0
  44. data/lib/cf_factory/cloudfront/cf_logging.rb +24 -0
  45. data/lib/cf_factory/cloudfront/cf_origin.rb +40 -0
  46. data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +25 -0
  47. data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +58 -0
  48. data/lib/cf_factory/ec2/cf_ebs_volume.rb +54 -0
  49. data/lib/cf_factory/ec2/cf_ec2_instance.rb +62 -0
  50. data/lib/cf_factory/ec2/cf_ec2_security_group.rb +40 -0
  51. data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +28 -0
  52. data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +39 -0
  53. data/lib/cf_factory/ec2/cf_eip.rb +26 -0
  54. data/lib/cf_factory/ec2/cf_eip_association.rb +29 -0
  55. data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +15 -0
  56. data/lib/cf_factory/elb/cf_elb.rb +49 -0
  57. data/lib/cf_factory/elb/cf_health_check.rb +23 -0
  58. data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +15 -0
  59. data/lib/cf_factory/elb/cf_listener.rb +26 -0
  60. data/lib/cf_factory/help/fixes.rb +14 -0
  61. data/lib/cf_factory/help/ip_mask.rb +165 -0
  62. data/lib/cf_factory/help/template_validation.rb +28 -0
  63. data/lib/cf_factory/iam/cf_iam_access_key.rb +32 -0
  64. data/lib/cf_factory/iam/cf_iam_group.rb +30 -0
  65. data/lib/cf_factory/iam/cf_iam_instance_profile.rb +30 -0
  66. data/lib/cf_factory/iam/cf_iam_policy.rb +18 -0
  67. data/lib/cf_factory/iam/cf_iam_role.rb +56 -0
  68. data/lib/cf_factory/iam/cf_iam_statement.rb +23 -0
  69. data/lib/cf_factory/iam/cf_iam_user.rb +34 -0
  70. data/lib/cf_factory/iam/cf_policy_document.rb +19 -0
  71. data/lib/cf_factory/modules/base_vpc.rb +61 -0
  72. data/lib/cf_factory/rds/cf_rds_instance.rb +53 -0
  73. data/lib/cf_factory/rds/cf_rds_security_group.rb +33 -0
  74. data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +29 -0
  75. data/lib/cf_factory/rds/cf_rds_subnet_group.rb +29 -0
  76. data/lib/cf_factory/route53/cf_elb_alias_target.rb +21 -0
  77. data/lib/cf_factory/route53/cf_record_set.rb +61 -0
  78. data/lib/cf_factory/route53/cf_route53_record_set.rb +61 -0
  79. data/lib/cf_factory/route53/cf_route53_record_set_group.rb +42 -0
  80. data/lib/cf_factory/s3/cf_s3_bucket.rb +32 -0
  81. data/lib/cf_factory/s3/cf_web_site_config.rb +24 -0
  82. data/lib/cf_factory/sqs/cf_sqs_queue.rb +26 -0
  83. data/lib/cf_factory/vpc/cf_attach_gateway.rb +28 -0
  84. data/lib/cf_factory/vpc/cf_internet_gateway.rb +30 -0
  85. data/lib/cf_factory/vpc/cf_network_acl.rb +39 -0
  86. data/lib/cf_factory/vpc/cf_network_acl_association.rb +24 -0
  87. data/lib/cf_factory/vpc/cf_network_acl_entry.rb +37 -0
  88. data/lib/cf_factory/vpc/cf_route.rb +43 -0
  89. data/lib/cf_factory/vpc/cf_route_table.rb +41 -0
  90. data/lib/cf_factory/vpc/cf_route_table_association.rb +24 -0
  91. data/lib/cf_factory/vpc/cf_subnet.rb +48 -0
  92. data/lib/cf_factory/vpc/cf_vpc.rb +64 -0
  93. data/lib/cf_factory.rb +103 -0
  94. metadata +140 -0
@@ -0,0 +1,61 @@
1
+ require 'cf_factory/base/cf_base'
2
+ class CfRecordSet
3
+ include CfInner
4
+
5
+ def initialize(name, record_name, record_type, options)
6
+ @name = name
7
+ @record_name = record_name
8
+ @record_type = record_type
9
+
10
+ @comment = options[:comment]
11
+ @region = options[:region]
12
+ @hosted_zone_id = options[:hosted_zone_id]
13
+ @hosted_zone_name = options[:hosted_zone_name]
14
+ @region = options[:region]
15
+ @ttl = options[:ttl]
16
+ @resource_records = options[:resource_records]
17
+ @weight = options[:weight]
18
+ @set_identifier = options[:set_identifier]
19
+ @alias_target = options[:alias_target]
20
+ validate()
21
+ end
22
+
23
+ def get_cf_type
24
+ "AWS::Route53::RecordSet"
25
+ end
26
+
27
+ def get_cf_attributes
28
+ {}
29
+ end
30
+
31
+ def get_cf_properties
32
+ result = {}
33
+ result["Name"] = @record_name
34
+ result["Type"] = @record_type
35
+ result["Comment"] = @comment unless @comment.nil?
36
+ result["HostedZoneId"] = @hosted_zone_id unless @hosted_zone_id.nil?
37
+ result["HostedZoneName"] = @hosted_zone_name unless @hosted_zone_name.nil?
38
+ result["Region"] = @region unless @region.nil?
39
+ result["TTL"] = @ttl unless @ttl.nil?
40
+ result["Weight"] = @weight unless @weight.nil?
41
+ result["SetIdentifier"] = @set_identifier unless @set_identifier.nil?
42
+ result["ResourceRecords"] = @resource_records.inspect unless @resource_records.nil?
43
+ result["AliasTarget"] = @alias_target.generate unless @alias_target.nil?
44
+ result
45
+ end
46
+
47
+ private
48
+
49
+ def validate
50
+ if @hosted_zone_id.nil? && @hosted_zone_name.nil?
51
+ raise Exception.new("either :hosted_zone_id or :hosted_zone_name must be specified")
52
+ end
53
+ if !@ttl.nil? && @resource_records.nil?
54
+ raise Exception.new("when :ttl specified, :resource_records must also be specified (and vice versa)")
55
+ end
56
+ if !@weight.nil? && @set_identifier.nil?
57
+ raise Exception.new("when :weight specified, :set_identifier must also be specified (and vice versa)")
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,61 @@
1
+ require 'cf_factory/base/cf_base'
2
+ class CfRoute53RecordSet
3
+ include CfBase
4
+
5
+ def initialize(name, record_name, record_type, options)
6
+ @name = name
7
+ @record_name = record_name
8
+ @record_type = record_type
9
+
10
+ @comment = options[:comment]
11
+ @region = options[:region]
12
+ @hosted_zone_id = options[:hosted_zone_id]
13
+ @hosted_zone_name = options[:hosted_zone_name]
14
+ @region = options[:region]
15
+ @ttl = options[:ttl]
16
+ @resource_records = options[:resource_records]
17
+ @weight = options[:weight]
18
+ @set_identifier = options[:set_identifier]
19
+ @alias_target = options[:alias_target]
20
+ validate()
21
+ end
22
+
23
+ def get_cf_type
24
+ "AWS::Route53::RecordSet"
25
+ end
26
+
27
+ def get_cf_attributes
28
+ {}
29
+ end
30
+
31
+ def get_cf_properties
32
+ result = {}
33
+ result["Name"] = @record_name
34
+ result["Type"] = @record_type
35
+ result["Comment"] = @comment unless @comment.nil?
36
+ result["HostedZoneId"] = @hosted_zone_id unless @hosted_zone_id.nil?
37
+ result["HostedZoneName"] = @hosted_zone_name unless @hosted_zone_name.nil?
38
+ result["Region"] = @region unless @region.nil?
39
+ result["TTL"] = @ttl unless @ttl.nil?
40
+ result["Weight"] = @weight unless @weight.nil?
41
+ result["SetIdentifier"] = @set_identifier unless @set_identifier.nil?
42
+ result["ResourceRecords"] = CfHelper.print_array(@resource_records) unless @resource_records.nil?
43
+ result["AliasTarget"] = @alias_target.generate unless @alias_target.nil?
44
+ result
45
+ end
46
+
47
+ private
48
+
49
+ def validate
50
+ if @hosted_zone_id.nil? && @hosted_zone_name.nil?
51
+ raise Exception.new("either :hosted_zone_id or :hosted_zone_name must be specified")
52
+ end
53
+ if !@ttl.nil? && @resource_records.nil?
54
+ raise Exception.new("when :ttl specified, :resource_records must also be specified (and vice versa)")
55
+ end
56
+ if !@weight.nil? && @set_identifier.nil?
57
+ raise Exception.new("when :weight specified, :set_identifier must also be specified (and vice versa)")
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,42 @@
1
+ #not yet working
2
+
3
+ require 'cf_factory/base/cf_base'
4
+ class CfRoute53RecordSetGroup
5
+ include CfBase
6
+
7
+ def initialize(name, record_sets, options)
8
+ raise Exception.new("don't use for now")
9
+ @name = name
10
+ @record_sets = record_sets
11
+ @hosted_zone_id = options[:hosted_zone_id]
12
+ @hosted_zone_name = options[:hosted_zone_name]
13
+ @comment = options[:comment]
14
+ validate()
15
+ end
16
+
17
+ def get_cf_type
18
+ "AWS::Route53::RecordSetGroup"
19
+ end
20
+
21
+ def get_cf_attributes
22
+ {}
23
+ end
24
+
25
+ def get_cf_properties
26
+ result = {}
27
+ result["RecordSets"] = CfHelper.generate_inner_array(@record_sets)
28
+ result["Comment"] = @comment unless @comment.nil?
29
+ result["HostedZoneId"] = @hosted_zone_id unless @hosted_zone_id.nil?
30
+ result["HostedZoneName"] = @hosted_zone_name unless @hosted_zone_name.nil?
31
+ result
32
+ end
33
+
34
+ private
35
+
36
+ def validate
37
+ if @hosted_zone_id.nil? && @hosted_zone_name.nil?
38
+ raise Exception.new("either :hosted_zone_id or :hosted_zone_name must be specified")
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,32 @@
1
+ require 'cf_factory/base/cf_base'
2
+ class CfS3Bucket
3
+ include CfBase
4
+
5
+ def initialize(name, options = {})
6
+ @name = name
7
+ @access_control = options[:access_control]
8
+ end
9
+
10
+ def set_deletion_policy(deletion_policy)
11
+ @deletion_policy = deletion_policy
12
+ end
13
+
14
+ def get_cf_type
15
+ "AWS::S3::Bucket"
16
+ end
17
+
18
+ def get_cf_attributes
19
+ result = super
20
+ end
21
+
22
+ def get_cf_properties
23
+ result = {}
24
+ result["AccessControl"] = @access_control unless @access_control.nil?
25
+ result
26
+ end
27
+
28
+ def short_domain_name
29
+ CfHelper.join([self.generate_ref, ".s3.amazonaws.com"])
30
+ end
31
+
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfWebSiteConfig
4
+ include CfInner
5
+
6
+ attr_reader(:id)
7
+
8
+ def additional_indent
9
+ 2
10
+ end
11
+
12
+ def initialize(index_doc, error_doc)
13
+ @index_doc = index_doc
14
+ @error_doc = error_doc
15
+ end
16
+
17
+ def get_cf_attributes
18
+ result = {}
19
+ result["IndexDocument"] = @index_doc
20
+ result["ErrorDocument"] = @error_doc
21
+ result
22
+ end
23
+
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_helper'
3
+
4
+ class CfSqsQueue
5
+ include CfBase
6
+
7
+ def initialize(name, options = {})
8
+ @name = name
9
+ @visibility_timeout = options[:visibility_timeout]
10
+ end
11
+
12
+ def get_cf_type
13
+ "AWS::SQS::Queue"
14
+ end
15
+
16
+ def get_cf_attributes
17
+ {}
18
+ end
19
+
20
+ def get_cf_properties
21
+ result = {}
22
+ result["VisibilityTimeout"] = @visibility_timeout unless @visibility_timeout.nil?
23
+ result
24
+ end
25
+
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'cf_factory/base/cf_base'
2
+ class CfAttachGateway
3
+ include CfBase
4
+
5
+ def initialize(name, vpc = nil, internet_gateway = nil, vpn_gateway = nil)
6
+ @name = name
7
+ @vpc = vpc
8
+ @internet_gateway = internet_gateway
9
+ @vpn_gateway = vpn_gateway
10
+ end
11
+
12
+ def get_cf_type
13
+ "AWS::EC2::VPCGatewayAttachment"
14
+ end
15
+
16
+ def get_cf_attributes
17
+ {}
18
+ end
19
+
20
+ def get_cf_properties
21
+ result = {}
22
+ result["VpcId"] = @vpc.generate_ref
23
+ result["InternetGatewayId"] = @internet_gateway.generate_ref unless @internet_gateway.nil?
24
+ result["VpnGatewayId"] = @vpn_gateway.generate_ref unless @vpn_gateway.nil?
25
+ result
26
+ end
27
+
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/vpc/cf_attach_gateway'
3
+
4
+ class CfInternetGateway
5
+ include CfBase
6
+
7
+ def initialize(name, vpn)
8
+ @name = name
9
+ @vpn = vpn
10
+ end
11
+
12
+ def get_cf_type
13
+ "AWS::EC2::InternetGateway"
14
+ end
15
+
16
+ def get_cf_attributes
17
+ {}
18
+ end
19
+
20
+ def get_cf_properties
21
+ {}
22
+ end
23
+
24
+ def generate
25
+ result = super
26
+ result += CfAttachGateway.new("Attach#{@name}", @vpn, self).generate
27
+ result
28
+ end
29
+
30
+ end
@@ -0,0 +1,39 @@
1
+ require 'cf_factory/base/cf_base'
2
+ class CfNetworkAcl
3
+ include CfBase
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @entries = []
8
+ end
9
+
10
+ def add_network_acl_entry(network_acl_entry)
11
+ network_acl_entry.set_network_acl(self)
12
+ @entries << network_acl_entry
13
+ end
14
+
15
+ def set_vpc(vpc)
16
+ @vpc = vpc
17
+ end
18
+
19
+ def get_cf_type
20
+ "AWS::EC2::NetworkAcl"
21
+ end
22
+
23
+ def get_cf_attributes
24
+ {}
25
+ end
26
+
27
+ def get_cf_properties
28
+ {"VpcId" => @vpc.generate_ref}
29
+ end
30
+
31
+ def generate
32
+ super
33
+ @entries.each() {|entry|
34
+ @result += entry.generate
35
+ }
36
+ @result
37
+ end
38
+
39
+ end
@@ -0,0 +1,24 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfNetworkAclAssociation
4
+ include CfBase
5
+
6
+ def initialize(name, subnet, network_acl)
7
+ @name = name
8
+ @subnet = subnet
9
+ @network_acl = network_acl
10
+ end
11
+
12
+ def get_cf_type
13
+ "AWS::EC2::SubnetNetworkAclAssociation"
14
+ end
15
+
16
+ def get_cf_attributes
17
+ {}
18
+ end
19
+
20
+ def get_cf_properties
21
+ {"SubnetId" => @subnet.generate_ref, "NetworkAclId" => @network_acl.generate_ref}
22
+ end
23
+
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfNetworkAclEntry
4
+ include CfBase
5
+
6
+ def initialize(name, rule_number, protocol, rule_action, egress, cidr_block, from_port, to_port)
7
+ @name = name
8
+ @rule_number = rule_number
9
+ @protocol = protocol
10
+ @rule_action = rule_action
11
+ @egress = egress
12
+ @cidr_block = cidr_block
13
+ @from_port = from_port
14
+ @to_port = to_port
15
+ end
16
+
17
+ def set_network_acl(network_acl)
18
+ @network_acl = network_acl
19
+ end
20
+
21
+ def get_cf_type
22
+ "AWS::EC2::NetworkAclEntry"
23
+ end
24
+
25
+ def get_cf_attributes
26
+ {}
27
+ end
28
+
29
+ def get_cf_properties
30
+ {"NetworkAclId" => @network_acl.generate_ref, "CidrBlock" => @cidr_block,
31
+ "Protocol" => @protocol.to_i, "RuleNumber" => @rule_number.to_i, "RuleAction" => @rule_action, "Egress" => @egress,
32
+ "PortRange" => {"From" => @from_port.to_i, "To" => @to_port.to_i }
33
+ }
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,43 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfRoute
4
+ include CfBase
5
+
6
+ def initialize(name, dest_cidr, gateway = nil, instance = nil, eni = nil)
7
+ @name = name
8
+ @dest_cidr = dest_cidr
9
+ @gateway = gateway
10
+ @instance = instance
11
+ @eni = eni
12
+ end
13
+
14
+ def set_route_table(route_table)
15
+ @route_table = route_table
16
+ end
17
+
18
+ def add_association()
19
+ end
20
+
21
+ def get_cf_type
22
+ "AWS::EC2::Route"
23
+ end
24
+
25
+ def get_cf_attributes
26
+ {}
27
+ end
28
+
29
+ def get_cf_properties
30
+ options = {}
31
+ unless @gateway.nil?
32
+ options["GatewayId"] = @gateway.generate_ref
33
+ end
34
+ unless @instance.nil?
35
+ options["InstanceId"] = @instance.generate_ref
36
+ end
37
+ unless @eni.nil?
38
+ options["NetworkInterfaceId"] = @eni.generate_ref
39
+ end
40
+ {"RouteTableId" => @route_table.generate_ref, "DestinationCidrBlock" => @dest_cidr}.merge(options)
41
+ end
42
+
43
+ end
@@ -0,0 +1,41 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfRouteTable
4
+ include CfBase
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @vpc = ":::::"
9
+ @routes = []
10
+ end
11
+
12
+ def add_route(route)
13
+ route.set_route_table(self)
14
+ @routes << route
15
+ end
16
+
17
+ def set_vpc(vpc)
18
+ @vpc = vpc
19
+ end
20
+
21
+ def get_cf_type
22
+ "AWS::EC2::RouteTable"
23
+ end
24
+
25
+ def get_cf_attributes
26
+ {}
27
+ end
28
+
29
+ def get_cf_properties
30
+ {"VpcId" => @vpc.generate_ref}
31
+ end
32
+
33
+ def generate
34
+ super
35
+ @routes.each() {|route|
36
+ @result += route.generate
37
+ }
38
+ @result
39
+ end
40
+
41
+ end
@@ -0,0 +1,24 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfRouteTableAssociation
4
+ include CfBase
5
+
6
+ def initialize(name, subnet, route_table)
7
+ @name = name
8
+ @subnet = subnet
9
+ @route_table = route_table
10
+ end
11
+
12
+ def get_cf_type
13
+ "AWS::EC2::SubnetRouteTableAssociation"
14
+ end
15
+
16
+ def get_cf_attributes
17
+ {}
18
+ end
19
+
20
+ def get_cf_properties
21
+ {"SubnetId" => @subnet.generate_ref, "RouteTableId" => @route_table.generate_ref}
22
+ end
23
+
24
+ end
@@ -0,0 +1,48 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/vpc/cf_route_table_association'
3
+ require 'cf_factory/vpc/cf_network_acl_association'
4
+
5
+ class CfSubnet
6
+ include CfBase
7
+
8
+ def initialize(name, cidr_block, availability_zone, route_table = nil, network_acl = nil)
9
+ @name = name
10
+ @vpc = ":::::"
11
+ @cidr_block = cidr_block
12
+ @route_table = route_table
13
+ @network_acl = network_acl
14
+ @availability_zone = availability_zone
15
+ end
16
+
17
+ def set_vpc(vpc)
18
+ @vpc = vpc
19
+ end
20
+
21
+ def get_cf_type
22
+ "AWS::EC2::Subnet"
23
+ end
24
+
25
+ def get_cf_attributes
26
+ {}
27
+ end
28
+
29
+ def get_cf_properties
30
+ {"VpcId" => @vpc.generate_ref, "CidrBlock" => @cidr_block, "AvailabilityZone" => @availability_zone}
31
+ end
32
+
33
+ def generate
34
+ super
35
+ unless @route_table.nil?
36
+ name = "#{@name}RouteTableAssociation"
37
+ rta = CfRouteTableAssociation.new(name, self, @route_table)
38
+ @result += rta.generate
39
+ end
40
+ unless @network_acl.nil?
41
+ name = "#{@name}NetworkAclAssociation"
42
+ acl = CfNetworkAclAssociation.new(name, self, @network_acl)
43
+ @result += acl.generate
44
+ end
45
+ @result
46
+ end
47
+
48
+ end
@@ -0,0 +1,64 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfVpc
4
+ include CfBase
5
+
6
+ def initialize(cidr, name = "MyVpc")
7
+ @cidr = cidr
8
+ @name = name
9
+ @subnets = []
10
+ @igws = []
11
+ @route_tables = []
12
+ @network_acls = []
13
+ end
14
+
15
+ def get_cf_type
16
+ "AWS::EC2::VPC"
17
+ end
18
+
19
+ def get_cf_attributes
20
+ {}
21
+ end
22
+
23
+ def get_cf_properties
24
+ {"CidrBlock" => @cidr}
25
+ end
26
+
27
+ def add_subnet(subnet)
28
+ subnet.set_vpc(self)
29
+ @subnets << subnet
30
+ end
31
+
32
+ def add_route_table(route_table)
33
+ route_table.set_vpc(self)
34
+ @route_tables << route_table
35
+ end
36
+
37
+ def add_internet_gateway(igw)
38
+ @igws << igw
39
+ end
40
+
41
+ def add_network_acl(network_acl)
42
+ network_acl.set_vpc(self)
43
+ @network_acls << network_acl
44
+ end
45
+
46
+ def generate
47
+ super
48
+ @igws.each() {|ig|
49
+ @result += ig.generate
50
+ }
51
+ @route_tables.each() {|rt|
52
+ @result += rt.generate
53
+ }
54
+ @network_acls.each() {|acl|
55
+ @result += acl.generate
56
+ }
57
+ @subnets.each() {|sn|
58
+ @result += sn.generate
59
+ }
60
+ #
61
+ @result
62
+ end
63
+
64
+ end