draw_cloud 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/README.md +22 -0
  2. data/lib/draw_cloud.rb +75 -0
  3. data/lib/draw_cloud/as_group.rb +104 -0
  4. data/lib/draw_cloud/as_group.rb~ +54 -0
  5. data/lib/draw_cloud/as_launch_configuration.rb +71 -0
  6. data/lib/draw_cloud/as_launch_configuration.rb~ +50 -0
  7. data/lib/draw_cloud/base.rb +264 -0
  8. data/lib/draw_cloud/base64_func.rb +30 -0
  9. data/lib/draw_cloud/configuration.rb +61 -0
  10. data/lib/draw_cloud/configuration.rb~ +64 -0
  11. data/lib/draw_cloud/ec2_instance.rb +141 -0
  12. data/lib/draw_cloud/ec2_instance.rb~ +78 -0
  13. data/lib/draw_cloud/ec2_instance_template.rb +29 -0
  14. data/lib/draw_cloud/ec2_instance_template.rb~ +36 -0
  15. data/lib/draw_cloud/elastic_ip.rb +97 -0
  16. data/lib/draw_cloud/elastic_ip.rb~ +19 -0
  17. data/lib/draw_cloud/get_att_func.rb +31 -0
  18. data/lib/draw_cloud/get_att_func.rb~ +19 -0
  19. data/lib/draw_cloud/iam_access_key.rb +53 -0
  20. data/lib/draw_cloud/iam_access_key.rb~ +43 -0
  21. data/lib/draw_cloud/iam_policy.rb +71 -0
  22. data/lib/draw_cloud/iam_policy.rb~ +41 -0
  23. data/lib/draw_cloud/iam_user.rb +53 -0
  24. data/lib/draw_cloud/iam_user.rb~ +44 -0
  25. data/lib/draw_cloud/internet_gateway.rb +66 -0
  26. data/lib/draw_cloud/join_func.rb +31 -0
  27. data/lib/draw_cloud/join_func.rb~ +24 -0
  28. data/lib/draw_cloud/locations.rb +25 -0
  29. data/lib/draw_cloud/locations.rb~ +53 -0
  30. data/lib/draw_cloud/map.rb +65 -0
  31. data/lib/draw_cloud/network_acl.rb +91 -0
  32. data/lib/draw_cloud/network_acl.rb~ +36 -0
  33. data/lib/draw_cloud/network_acl_entry.rb +110 -0
  34. data/lib/draw_cloud/network_acl_entry.rb~ +36 -0
  35. data/lib/draw_cloud/network_interface.rb +71 -0
  36. data/lib/draw_cloud/network_interface.rb~ +46 -0
  37. data/lib/draw_cloud/output.rb +38 -0
  38. data/lib/draw_cloud/output.rb~ +39 -0
  39. data/lib/draw_cloud/parameter.rb +58 -0
  40. data/lib/draw_cloud/parameter.rb~ +30 -0
  41. data/lib/draw_cloud/rds_instance.rb +117 -0
  42. data/lib/draw_cloud/rds_security_group.rb +57 -0
  43. data/lib/draw_cloud/route_table.rb +56 -0
  44. data/lib/draw_cloud/route_table_entry.rb +59 -0
  45. data/lib/draw_cloud/route_table_entry.rb~ +33 -0
  46. data/lib/draw_cloud/s3_bucket.rb~ +41 -0
  47. data/lib/draw_cloud/security_group.rb +85 -0
  48. data/lib/draw_cloud/security_group.rb~ +71 -0
  49. data/lib/draw_cloud/service.rb~ +75 -0
  50. data/lib/draw_cloud/simple_ref.rb +30 -0
  51. data/lib/draw_cloud/simple_ref.rb~ +17 -0
  52. data/lib/draw_cloud/sns_topic.rb +58 -0
  53. data/lib/draw_cloud/sns_topic.rb~ +39 -0
  54. data/lib/draw_cloud/subnet.rb +104 -0
  55. data/lib/draw_cloud/subnet.rb~ +56 -0
  56. data/lib/draw_cloud/utilities.rb +65 -0
  57. data/lib/draw_cloud/version.rb +3 -0
  58. data/lib/draw_cloud/vpc.rb +57 -0
  59. data/lib/draw_cloud/vpc.rb~ +55 -0
  60. data/lib/draw_cloud/wait_handle.rb +78 -0
  61. data/lib/draw_cloud/wait_handle.rb~ +10 -0
  62. metadata +195 -0
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ # may not use this work except in compliance with the License. You may
7
+ # obtain a copy of the License in the LICENSE file, or at:
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ # implied. See the License for the specific language governing
15
+ # permissions and limitations under the License.
16
+
17
+ #
18
+
19
+ module DrawCloud
20
+ class JoinFunc
21
+ attr_accessor :delimiter, :args
22
+ def initialize(delimiter, args=nil)
23
+ @delimiter = delimiter
24
+ @args = args
25
+ end
26
+
27
+ def ref
28
+ {"Fn::Join" => [delimiter, args.collect {|a| DrawCloud.ref(a)} ]}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ # License:: All rights reserved
5
+ #
6
+
7
+ module DrawCloud
8
+ class JoinFunc
9
+ attr_accessor :fnname, :args
10
+ def initialize(fnname, args=nil)
11
+ @fnname = fnname
12
+ @args = args
13
+ end
14
+
15
+ def ref
16
+ case args
17
+ when Array
18
+ {fnname => args.collect {|a| DrawCloud.ref(a) }}
19
+ else
20
+ {fnname => DrawCloud.ref(args)}
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ # may not use this work except in compliance with the License. You may
7
+ # obtain a copy of the License in the LICENSE file, or at:
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ # implied. See the License for the specific language governing
15
+ # permissions and limitations under the License.
16
+
17
+ #
18
+
19
+ module DrawCloud
20
+ module Locations
21
+ def arn_s3(bucket_name, path)
22
+ fnjoin("", "arn:aws:s3:::", bucket_name, path)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ # License:: All rights reserved
5
+ #
6
+
7
+ module DrawCloud
8
+ module Utilities
9
+ def region
10
+ SimpleRef.new("AWS::Region")
11
+ end
12
+
13
+ def stack_name
14
+ SimpleRef.new("AWS::StackName")
15
+ end
16
+
17
+ def fngetatt(resource, attribute_name)
18
+ GetAttFunc.new(resource, attribute_name)
19
+ end
20
+
21
+ def fnbase64(arg)
22
+ Base64Func.new(arg)
23
+ end
24
+
25
+ def fnjoin(delimiter, *args)
26
+ JoinFunc.new(delimiter, args)
27
+ end
28
+
29
+ def resource_style(str)
30
+ DrawCloud.resource_style(str)
31
+ end
32
+
33
+ def desplice(string)
34
+ fnjoin("", *string.split('|CHOPHERE|').collect {|s| if s.start_with? 'YYYY' then YAML::load(s[4,s.length-4]) else s end })
35
+ end
36
+
37
+ def splice(string)
38
+ out = '|CHOPHERE|'
39
+ outref = DrawCloud.ref(string)
40
+ case outref
41
+ when String
42
+ out += outref
43
+ else
44
+ out += 'YYYY' + YAML::dump(outref)
45
+ end
46
+ out += '|CHOPHERE|'
47
+ end
48
+
49
+ def hash_to_tag_array(hash)
50
+ hash.collect {|(k,v)| {"Key" => k, "Value" => v} }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ # may not use this work except in compliance with the License. You may
7
+ # obtain a copy of the License in the LICENSE file, or at:
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ # implied. See the License for the specific language governing
15
+ # permissions and limitations under the License.
16
+
17
+ #
18
+
19
+ module DrawCloud
20
+ class Map < Base
21
+ class MapLookup
22
+ attr_accessor :map, :key
23
+ def initialize(map, key)
24
+ @map = map
25
+ @key = key
26
+ end
27
+
28
+ def ref
29
+ {"Fn::FindInMap" => [map.resource_name, map.function_resource, key]}
30
+ end
31
+ end
32
+
33
+ attr_accessor :name, :map_by_function, :values
34
+ def initialize(name, map_by_function, options, values={})
35
+ @name = name
36
+ @map_by_function = map_by_function
37
+ @values = values
38
+ super(options)
39
+ end
40
+
41
+ def [](key)
42
+ MapLookup.new(self, key)
43
+ end
44
+
45
+ def function_resource
46
+ case map_by_function
47
+ when :map_by_region
48
+ {"Ref" => "AWS::Region"}
49
+ when Parameter
50
+ map_by_function.ref
51
+ else
52
+ raise ArgumentError, "Unknown map function #{map_by_function}"
53
+ end
54
+ end
55
+
56
+ def load_into_config(config)
57
+ config.cf_add_mapping resource_name, self
58
+ super(config)
59
+ end
60
+
61
+ def to_h
62
+ values
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright:: Copyright (c) 2012, SweetSpot Diabetes Care, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
6
+ # may not use this work except in compliance with the License. You may
7
+ # obtain a copy of the License in the LICENSE file, or at:
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
+ # implied. See the License for the specific language governing
15
+ # permissions and limitations under the License.
16
+
17
+ #
18
+
19
+ module DrawCloud
20
+ class NetworkAcl < Base
21
+ attr_accessor :name, :entries
22
+ def initialize(name, options={}, &block)
23
+ @name = name
24
+ @entries = []
25
+ super(options, &block)
26
+ end
27
+
28
+ def network_acl
29
+ self
30
+ end
31
+
32
+ def allow_in(protocol, cidr=:any, ports_or_types=[])
33
+ add_entry :allow, protocol, :ingress, cidr, ports_or_types
34
+ end
35
+
36
+ def allow_out(protocol, cidr=:any, ports_or_types=[])
37
+ add_entry :allow, protocol, :egress, cidr, ports_or_types
38
+ end
39
+
40
+ def deny_in(protocol, cidr=:any, ports_or_types=[])
41
+ add_entry :deny, protocol, :ingress, cidr, ports_or_types
42
+ end
43
+
44
+ def deny_out(protocol, cidr=:any, ports_or_types=[])
45
+ add_entry :deny, protocol, :egress, cidr, ports_or_types
46
+ end
47
+
48
+ def provides(service)
49
+ end
50
+
51
+ def consumes(service)
52
+ end
53
+
54
+ def add_entry(action, protocol, direction, cidr, ports_or_types)
55
+ entries.concat NetworkAclEntry.entries_from_spec(action, protocol, direction,
56
+ cidr, ports_or_types, :parent => self)
57
+ end
58
+ private :add_entry
59
+
60
+ def load_into_config(config)
61
+ config.cf_add_resource resource_name, self
62
+ ingress_index = 1
63
+ egress_index = 1
64
+ entries.each do |e|
65
+ if e.outgoing?
66
+ e.index = egress_index * 10
67
+ egress_index += 1
68
+ else
69
+ e.index = ingress_index * 10
70
+ ingress_index += 1
71
+ end
72
+
73
+ e.load_into_config(config)
74
+ end
75
+ super(config)
76
+ end
77
+
78
+ def resource_name
79
+ resource_style(name) + "NetworkACL"
80
+ end
81
+
82
+ def to_h
83
+ h = {
84
+ "Type" => "AWS::EC2::NetworkAcl",
85
+ "Properties" => {}
86
+ }
87
+ h["Properties"]["VpcId"] = DrawCloud.ref(vpc) if vpc
88
+ add_standard_properties(h)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,36 @@
1
+ module DrawCloud
2
+ class NetworkAcl
3
+ include Base
4
+
5
+ attr_accessor :vpc, :name, :entries
6
+ def initialize(name, options={}, &block)
7
+ @name = name
8
+ @vpc = options.fetch(:vpc, nil)
9
+ @routes = []
10
+ self.instance_exec(self, &block) if block
11
+ end
12
+
13
+ def to(name, to_cidr, options={})
14
+ raise(Exeception, "No :via specified") unless options[:via]
15
+ @routes << RouteTableEntry.new(name, to_cidr, options[:via], :route_table => self)
16
+ end
17
+
18
+ def load_into_config(config)
19
+ config.cf_add_resource resource_name, self
20
+ @routes.each {|r| config.cf_add_resource(r.resource_name, r)}
21
+ end
22
+
23
+ def resource_name
24
+ resource_style(name) + "Table"
25
+ end
26
+
27
+ def to_h
28
+ h = {
29
+ "Type" => "AWS::EC2::RouteTable",
30
+ "Properties" => {}
31
+ }
32
+ h["Properties"]["VpcId"] = vpc.ref if vpc
33
+ h
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,110 @@
1
+ module DrawCloud
2
+ class NetworkAclEntry < Base
3
+ def self.entries_from_spec(action, protocol_spec, direction, cidr, ports_or_types_spec, options={}, &block)
4
+ protocol = case protocol_spec
5
+ when :everything, :any, :all
6
+ -1
7
+ when :icmp
8
+ 1
9
+ when :tcp
10
+ 6
11
+ when :udp
12
+ 17
13
+ when Numeric
14
+ protocol_spec
15
+ else
16
+ raise ArgumentError, "Unknown protocol description #{protocol_spec.inspect}"
17
+ end
18
+
19
+ raise ArgumentError, "Unknown ACL direction #{direction.inspect}" unless direction == :ingress || direction == :egress
20
+
21
+ cidr = "0.0.0.0/0" if :any == cidr
22
+
23
+ pts = if -1 == protocol
24
+ [nil]
25
+ elsif 1 == protocol
26
+ if :any == ports_or_types_spec
27
+ [[-1, -1]]
28
+ elsif :echo == ports_or_types_spec
29
+ [[8, 0], [0, 0]]
30
+ else
31
+ raise ArgumentError, "Can't understand ICMP specification #{ports_or_types_spec.inspect} - maybe you need to add this code"
32
+ end
33
+ elsif 6 == protocol || 17 == protocol
34
+ case ports_or_types_spec
35
+ when Numeric
36
+ [ports_or_types_spec]
37
+ when Range
38
+ [[ports_or_types_spec.min, ports_or_types_spec.max]]
39
+ when Array
40
+ ports_or_types_spec.collect {|p| if p.is_a?(Range) then [p.min, p.max] else [p, p] end }
41
+ else
42
+ raise ArgumentError, "Can't understand TCP/UDP port specification #{ports_or_types_spec.inspect} - maybe you need to add this code"
43
+ end
44
+ end
45
+
46
+ pts.collect do |s|
47
+ NetworkAclEntry.new(action, protocol, direction, cidr, ports_or_types_spec, options)
48
+ end
49
+ end
50
+
51
+ attr_accessor :index, :action, :protocol, :direction, :cidr, :ports
52
+ def initialize(action, protocol, direction, cidr, ports_or_types, options={}, &block)
53
+ @action = action
54
+ @protocol = protocol
55
+ @direction = direction
56
+ @cidr = cidr
57
+ @ports_or_types = ports_or_types
58
+ super(options, &block)
59
+ end
60
+
61
+ def outgoing?
62
+ :egress == direction
63
+ end
64
+
65
+ def icmp?
66
+ 1 == protocol
67
+ end
68
+
69
+ def tcp_or_udp?
70
+ 6 == protocol || 17 == protocol
71
+ end
72
+
73
+ def load_into_config(config)
74
+ config.cf_add_resource resource_name, self
75
+ super(config)
76
+ end
77
+
78
+ def resource_name
79
+ DrawCloud.resource_name(network_acl) + direction.to_s.capitalize + "Rule" + index.to_s
80
+ end
81
+
82
+ def to_h
83
+ h = {
84
+ "Type" => "AWS::EC2::NetworkAclEntry",
85
+ "Properties" => {
86
+ "RuleNumber" => index,
87
+ "Protocol" => protocol,
88
+ "RuleAction" => case action
89
+ when :allow
90
+ "allow"
91
+ when :deny
92
+ "deny"
93
+ else
94
+ raise ArgumentError, "Unknown NetworkAclEntry action #{action.inspect}"
95
+ end,
96
+ "Egress" => outgoing?,
97
+ "CidrBlock" => cidr
98
+ }
99
+ }
100
+ h["Properties"]["NetworkAclId"] = DrawCloud.ref(network_acl) if network_acl
101
+ if icmp?
102
+ h["Properties"]["Icmp"] = {"Type" => ports_or_types[0], "Code" => ports_or_types[1] }
103
+ end
104
+ if tcp_or_udp?
105
+ h["Properties"]["PortRange"] = {"From" => ports_or_types[0], "To" => ports_or_types[1] }
106
+ end
107
+ add_standard_properties(h)
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,36 @@
1
+ module DrawCloud
2
+ class NetworkAclEntry
3
+ include Base
4
+
5
+ attr_accessor :acl, :index, :action, :protocol, :cidr, :ports
6
+ def initialize(name, options={}, &block)
7
+ @name = name
8
+ @vpc = options.fetch(:vpc, nil)
9
+ @routes = []
10
+ self.instance_exec(self, &block) if block
11
+ end
12
+
13
+ def to(name, to_cidr, options={})
14
+ raise(Exeception, "No :via specified") unless options[:via]
15
+ @routes << RouteTableEntry.new(name, to_cidr, options[:via], :route_table => self)
16
+ end
17
+
18
+ def load_into_config(config)
19
+ config.cf_add_resource resource_name, self
20
+ @routes.each {|r| config.cf_add_resource(r.resource_name, r)}
21
+ end
22
+
23
+ def resource_name
24
+ resource_style(name) + "Table"
25
+ end
26
+
27
+ def to_h
28
+ h = {
29
+ "Type" => "AWS::EC2::RouteTable",
30
+ "Properties" => {}
31
+ }
32
+ h["Properties"]["VpcId"] = vpc.ref if vpc
33
+ h
34
+ end
35
+ end
36
+ end