draw_cloud 0.0.1
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.
- data/README.md +22 -0
- data/lib/draw_cloud.rb +75 -0
- data/lib/draw_cloud/as_group.rb +104 -0
- data/lib/draw_cloud/as_group.rb~ +54 -0
- data/lib/draw_cloud/as_launch_configuration.rb +71 -0
- data/lib/draw_cloud/as_launch_configuration.rb~ +50 -0
- data/lib/draw_cloud/base.rb +264 -0
- data/lib/draw_cloud/base64_func.rb +30 -0
- data/lib/draw_cloud/configuration.rb +61 -0
- data/lib/draw_cloud/configuration.rb~ +64 -0
- data/lib/draw_cloud/ec2_instance.rb +141 -0
- data/lib/draw_cloud/ec2_instance.rb~ +78 -0
- data/lib/draw_cloud/ec2_instance_template.rb +29 -0
- data/lib/draw_cloud/ec2_instance_template.rb~ +36 -0
- data/lib/draw_cloud/elastic_ip.rb +97 -0
- data/lib/draw_cloud/elastic_ip.rb~ +19 -0
- data/lib/draw_cloud/get_att_func.rb +31 -0
- data/lib/draw_cloud/get_att_func.rb~ +19 -0
- data/lib/draw_cloud/iam_access_key.rb +53 -0
- data/lib/draw_cloud/iam_access_key.rb~ +43 -0
- data/lib/draw_cloud/iam_policy.rb +71 -0
- data/lib/draw_cloud/iam_policy.rb~ +41 -0
- data/lib/draw_cloud/iam_user.rb +53 -0
- data/lib/draw_cloud/iam_user.rb~ +44 -0
- data/lib/draw_cloud/internet_gateway.rb +66 -0
- data/lib/draw_cloud/join_func.rb +31 -0
- data/lib/draw_cloud/join_func.rb~ +24 -0
- data/lib/draw_cloud/locations.rb +25 -0
- data/lib/draw_cloud/locations.rb~ +53 -0
- data/lib/draw_cloud/map.rb +65 -0
- data/lib/draw_cloud/network_acl.rb +91 -0
- data/lib/draw_cloud/network_acl.rb~ +36 -0
- data/lib/draw_cloud/network_acl_entry.rb +110 -0
- data/lib/draw_cloud/network_acl_entry.rb~ +36 -0
- data/lib/draw_cloud/network_interface.rb +71 -0
- data/lib/draw_cloud/network_interface.rb~ +46 -0
- data/lib/draw_cloud/output.rb +38 -0
- data/lib/draw_cloud/output.rb~ +39 -0
- data/lib/draw_cloud/parameter.rb +58 -0
- data/lib/draw_cloud/parameter.rb~ +30 -0
- data/lib/draw_cloud/rds_instance.rb +117 -0
- data/lib/draw_cloud/rds_security_group.rb +57 -0
- data/lib/draw_cloud/route_table.rb +56 -0
- data/lib/draw_cloud/route_table_entry.rb +59 -0
- data/lib/draw_cloud/route_table_entry.rb~ +33 -0
- data/lib/draw_cloud/s3_bucket.rb~ +41 -0
- data/lib/draw_cloud/security_group.rb +85 -0
- data/lib/draw_cloud/security_group.rb~ +71 -0
- data/lib/draw_cloud/service.rb~ +75 -0
- data/lib/draw_cloud/simple_ref.rb +30 -0
- data/lib/draw_cloud/simple_ref.rb~ +17 -0
- data/lib/draw_cloud/sns_topic.rb +58 -0
- data/lib/draw_cloud/sns_topic.rb~ +39 -0
- data/lib/draw_cloud/subnet.rb +104 -0
- data/lib/draw_cloud/subnet.rb~ +56 -0
- data/lib/draw_cloud/utilities.rb +65 -0
- data/lib/draw_cloud/version.rb +3 -0
- data/lib/draw_cloud/vpc.rb +57 -0
- data/lib/draw_cloud/vpc.rb~ +55 -0
- data/lib/draw_cloud/wait_handle.rb +78 -0
- data/lib/draw_cloud/wait_handle.rb~ +10 -0
- metadata +195 -0
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
drawcloud
|
2
|
+
=========
|
3
|
+
|
4
|
+
Draw AWS CloudFormation configurations in Ruby
|
5
|
+
|
6
|
+
|
7
|
+
Copyright and License
|
8
|
+
=====================
|
9
|
+
|
10
|
+
Copyright 2013 SweetSpot Diabetes Care, Inc.
|
11
|
+
|
12
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you
|
13
|
+
may not use this work except in compliance with the License. You may
|
14
|
+
obtain a copy of the License in the LICENSE file, or at:
|
15
|
+
|
16
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
|
18
|
+
Unless required by applicable law or agreed to in writing, software
|
19
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
21
|
+
implied. See the License for the specific language governing
|
22
|
+
permissions and limitations under the License.
|
data/lib/draw_cloud.rb
ADDED
@@ -0,0 +1,75 @@
|
|
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
|
+
module DrawCloud
|
19
|
+
def self.ref(object)
|
20
|
+
if object.respond_to? :ref
|
21
|
+
object.ref
|
22
|
+
elsif object.is_a? Symbol
|
23
|
+
resource_style(object)
|
24
|
+
elsif object.respond_to? :each_pair
|
25
|
+
object.each_with_object({}) {|(k,v),x| x[k] = DrawCloud.ref(v)}
|
26
|
+
else
|
27
|
+
object
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.resource_style(str)
|
32
|
+
str.to_s.camelize
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.resource_name(o)
|
36
|
+
if o.respond_to? :resource_name
|
37
|
+
o.resource_name
|
38
|
+
else
|
39
|
+
resource_style(o)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require_relative "draw_cloud/utilities"
|
44
|
+
require_relative "draw_cloud/locations"
|
45
|
+
require_relative "draw_cloud/base"
|
46
|
+
require_relative "draw_cloud/simple_ref"
|
47
|
+
require_relative "draw_cloud/join_func"
|
48
|
+
require_relative "draw_cloud/base64_func"
|
49
|
+
require_relative "draw_cloud/get_att_func"
|
50
|
+
require_relative "draw_cloud/configuration"
|
51
|
+
require_relative "draw_cloud/map"
|
52
|
+
require_relative "draw_cloud/parameter"
|
53
|
+
require_relative "draw_cloud/output"
|
54
|
+
require_relative "draw_cloud/vpc"
|
55
|
+
require_relative "draw_cloud/sns_topic"
|
56
|
+
require_relative "draw_cloud/security_group"
|
57
|
+
require_relative "draw_cloud/iam_policy"
|
58
|
+
require_relative "draw_cloud/iam_user"
|
59
|
+
require_relative "draw_cloud/iam_access_key"
|
60
|
+
require_relative "draw_cloud/subnet"
|
61
|
+
require_relative "draw_cloud/network_acl"
|
62
|
+
require_relative "draw_cloud/network_acl_entry"
|
63
|
+
require_relative "draw_cloud/route_table"
|
64
|
+
require_relative "draw_cloud/route_table_entry"
|
65
|
+
require_relative "draw_cloud/internet_gateway"
|
66
|
+
require_relative "draw_cloud/rds_instance"
|
67
|
+
require_relative "draw_cloud/rds_security_group"
|
68
|
+
require_relative "draw_cloud/wait_handle"
|
69
|
+
require_relative "draw_cloud/ec2_instance"
|
70
|
+
require_relative "draw_cloud/ec2_instance_template"
|
71
|
+
require_relative "draw_cloud/as_launch_configuration"
|
72
|
+
require_relative "draw_cloud/as_group"
|
73
|
+
require_relative "draw_cloud/elastic_ip"
|
74
|
+
require_relative "draw_cloud/network_interface"
|
75
|
+
end
|
@@ -0,0 +1,104 @@
|
|
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
|
+
module DrawCloud
|
19
|
+
class ASGroup < Base
|
20
|
+
NOTIFY_EC2_INSTANCE_LAUNCH = "autoscaling:EC2_INSTANCE_LAUNCH"
|
21
|
+
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR = "autoscaling:EC2_INSTANCE_LAUNCH_ERROR"
|
22
|
+
NOTIFY_EC2_INSTANCE_TERMINATE = "autoscaling:EC2_INSTANCE_TERMINATE"
|
23
|
+
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR = "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
|
24
|
+
NOTIFY_EC2_TEST_NOTIFICATION = "autoscaling:TEST_NOTIFICATION"
|
25
|
+
ALL_NOTIFICATIONS = [ NOTIFY_EC2_INSTANCE_LAUNCH,
|
26
|
+
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
|
27
|
+
NOTIFY_EC2_INSTANCE_TERMINATE,
|
28
|
+
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR,
|
29
|
+
NOTIFY_EC2_TEST_NOTIFICATION ]
|
30
|
+
ALL_ERRORS = [ NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
|
31
|
+
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR ]
|
32
|
+
ALL_ACTIVITY = [ NOTIFY_EC2_INSTANCE_LAUNCH,
|
33
|
+
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
|
34
|
+
NOTIFY_EC2_INSTANCE_TERMINATE,
|
35
|
+
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR ]
|
36
|
+
|
37
|
+
attr_accessor :name, :availability_zones, :cooldown, :launch_configuration_name, :max_size, :min_size, :desired_capacity, :tags, :vpc_zone_identifier, :notification_configuration
|
38
|
+
alias :subnets :vpc_zone_identifier
|
39
|
+
alias :launch_configuration :launch_configuration_name
|
40
|
+
alias :launch_configuration= :launch_configuration_name=
|
41
|
+
def initialize(name, options={}, &block)
|
42
|
+
@name = name
|
43
|
+
@availability_zones = options.fetch(:availability_zones, [])
|
44
|
+
@cooldown = options.fetch(:cooldown, nil)
|
45
|
+
@launch_configuration_name = options.fetch(:launch_configuration_name, nil)
|
46
|
+
@max_size = options.fetch(:max_size, nil)
|
47
|
+
@min_size = options.fetch(:min_size, nil)
|
48
|
+
@notification_configuration = options.fetch(:notification_configuration, nil)
|
49
|
+
@desired_capacity = options.fetch(:desired_capacity, nil)
|
50
|
+
@tags = options.fetch(:tags, [])
|
51
|
+
@vpc_zone_identifier = options.fetch(:vpc_zone_identifier, nil)
|
52
|
+
super(options, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def as_group
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def notify(topic_arn, notification_types)
|
60
|
+
self.notification_configuration = {:arn => topic_arn, :types => notification_types}
|
61
|
+
end
|
62
|
+
|
63
|
+
def vpc_zone_identifier=(subnets)
|
64
|
+
if subnets.all? {|s| s.respond_to? :availability_zone }
|
65
|
+
self.availability_zones = subnets.collect(&:availability_zone)
|
66
|
+
end
|
67
|
+
@vpc_zone_identifier = subnets
|
68
|
+
end
|
69
|
+
alias :subnets= :vpc_zone_identifier=
|
70
|
+
|
71
|
+
def load_into_config(config)
|
72
|
+
config.cf_add_resource resource_name, self
|
73
|
+
super(config)
|
74
|
+
end
|
75
|
+
|
76
|
+
def resource_name
|
77
|
+
resource_style(name) + "AS"
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_h
|
81
|
+
h = {
|
82
|
+
"Type" => "AWS::AutoScaling::AutoScalingGroup",
|
83
|
+
"Properties" => {
|
84
|
+
"AvailabilityZones" => availability_zones.collect {|g| DrawCloud.ref(g) },
|
85
|
+
"LaunchConfigurationName" => DrawCloud.ref(launch_configuration_name),
|
86
|
+
"MaxSize" => max_size,
|
87
|
+
"MinSize" => min_size,
|
88
|
+
"Tags" => [], # FIXME
|
89
|
+
}
|
90
|
+
}
|
91
|
+
p = h["Properties"]
|
92
|
+
p["AvailabilityZones"] = DrawCloud.ref(availability_zones) if cooldown
|
93
|
+
p["Cooldown"] = DrawCloud.ref(cooldown) if cooldown
|
94
|
+
p["DesiredCapacity"] = DrawCloud.ref(desired_capacity) if desired_capacity
|
95
|
+
p["VPCZoneIdentifier"] = vpc_zone_identifier.collect {|z| DrawCloud.ref(z) }
|
96
|
+
p["NotificationConfiguration"] = {
|
97
|
+
"TopicARN" => DrawCloud.ref(self.notification_configuration[:arn]),
|
98
|
+
"NotificationTypes" => self.notification_configuration[:types],
|
99
|
+
} if self.notification_configuration
|
100
|
+
|
101
|
+
add_standard_properties(h)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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 ASGroup < Base
|
9
|
+
attr_accessor :name, :availability_zones, :cooldown, :launch_configuration_name, :max_size, :min_size, :desired_capacity, :tags, :vpc_zone_identifier
|
10
|
+
alias :instance_class :instance_type
|
11
|
+
alias :instance_class= :instance_type=
|
12
|
+
def initialize(name, options={}, &block)
|
13
|
+
@name = name
|
14
|
+
@image_id = options.fetch(:image_id, nil)
|
15
|
+
@instance_monitoring = options.fetch(:instance_monitoring, nil)
|
16
|
+
@instance_type = options.fetch(:instance_type, nil)
|
17
|
+
@kernel_id = options.fetch(:kernel_id, nil)
|
18
|
+
@key_name = options.fetch(:key_name, nil)
|
19
|
+
@ram_disk_id = options.fetch(:ram_disk_id, nil)
|
20
|
+
@security_groups = options.fetch(:security_groups, nil)
|
21
|
+
@user_data = options.fetch(:user_data, nil)
|
22
|
+
@tags = {}
|
23
|
+
super(options, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def as_launch_configuration
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_into_config(config)
|
31
|
+
config.cf_add_resource resource_name, self
|
32
|
+
super(config)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h
|
36
|
+
h = {
|
37
|
+
"Type" => "AWS::AutoScaling::LaunchConfiguration",
|
38
|
+
"Properties" => {
|
39
|
+
"ImageId" => DrawCloud.ref(image_id),
|
40
|
+
"InstanceType" => DrawCloud.ref(instance_type),
|
41
|
+
}
|
42
|
+
}
|
43
|
+
p = h["Properties"]
|
44
|
+
p["InstanceMonitoring"] = DrawCloud.ref(instance_monitoring) if instance_monitoring
|
45
|
+
p["KernelId"] = DrawCloud.ref(kernel_id) if kernel_id
|
46
|
+
p["KeyName"] = DrawCloud.ref(key_name) if key_name
|
47
|
+
p["RamDiskId"] = DrawCloud.ref(ram_disk_id) if ram_disk_id
|
48
|
+
p["SecurityGroups"] = security_groups if security_groups
|
49
|
+
p["UserData"] = user_data if user_data
|
50
|
+
h["Metadata"] = DrawCloud.ref(metadata) unless metadata.nil? || metadata.empty?
|
51
|
+
add_standard_properties(h)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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 ASLaunchConfiguration < Base
|
21
|
+
attr_accessor :name, :image_id, :instance_monitoring, :instance_type, :kernel_id, :key_name, :ram_disk_id, :security_groups, :user_data, :metadata, :tags
|
22
|
+
alias :instance_class :instance_type
|
23
|
+
alias :instance_class= :instance_type=
|
24
|
+
alias :monitoring :instance_monitoring
|
25
|
+
alias :monitoring= :instance_monitoring=
|
26
|
+
def initialize(name, options={}, &block)
|
27
|
+
@name = name
|
28
|
+
@image_id = options.fetch(:image_id, nil)
|
29
|
+
@instance_monitoring = options.fetch(:instance_monitoring, nil)
|
30
|
+
@instance_type = options.fetch(:instance_type, nil)
|
31
|
+
@kernel_id = options.fetch(:kernel_id, nil)
|
32
|
+
@key_name = options.fetch(:key_name, nil)
|
33
|
+
@ram_disk_id = options.fetch(:ram_disk_id, nil)
|
34
|
+
@security_groups = options.fetch(:security_groups, nil)
|
35
|
+
@user_data = options.fetch(:user_data, nil)
|
36
|
+
super(options, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def as_launch_configuration
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_into_config(config)
|
44
|
+
config.cf_add_resource resource_name, self
|
45
|
+
super(config)
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_name
|
49
|
+
resource_style(name) + "LaunchConfig"
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_h
|
53
|
+
h = {
|
54
|
+
"Type" => "AWS::AutoScaling::LaunchConfiguration",
|
55
|
+
"Properties" => {
|
56
|
+
"ImageId" => DrawCloud.ref(image_id),
|
57
|
+
"InstanceType" => DrawCloud.ref(instance_type),
|
58
|
+
}
|
59
|
+
}
|
60
|
+
p = h["Properties"]
|
61
|
+
p["InstanceMonitoring"] = DrawCloud.ref(instance_monitoring) if instance_monitoring
|
62
|
+
p["KernelId"] = DrawCloud.ref(kernel_id) if kernel_id
|
63
|
+
p["KeyName"] = DrawCloud.ref(key_name) if key_name
|
64
|
+
p["RamDiskId"] = DrawCloud.ref(ram_disk_id) if ram_disk_id
|
65
|
+
p["SecurityGroups"] = security_groups.collect {|s| DrawCloud.ref(s)} if security_groups
|
66
|
+
p["UserData"] = DrawCloud.ref(user_data) if user_data
|
67
|
+
h["Metadata"] = DrawCloud.ref(metadata) unless metadata.nil? || metadata.empty?
|
68
|
+
add_standard_properties(h)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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 ASLaunchConfiguration < Base
|
9
|
+
attr_accessor :name, :image_id, :instance_monitoring, :instance_type, :kernel_id, :key_name, :ram_disk_id, :security_groups, :user_data
|
10
|
+
def initialize(name, cidr, options={}, &block)
|
11
|
+
@name = name
|
12
|
+
@cidr = cidr
|
13
|
+
@availability_zone = options.fetch(:availability_zone, nil)
|
14
|
+
@route_table = options.fetch(:route_table, nil)
|
15
|
+
@network_acl = options.fetch(:network_acl, nil)
|
16
|
+
super(options, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def subnet
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_into_config(config)
|
24
|
+
config.cf_add_resource resource_name, self
|
25
|
+
if route_table
|
26
|
+
route_table.load_into_config(config)
|
27
|
+
assoc = SubnetRouteTableAssociation.new(self, route_table)
|
28
|
+
config.cf_add_resource assoc.resource_name, assoc
|
29
|
+
end
|
30
|
+
if network_acl
|
31
|
+
network_acl.load_into_config(config)
|
32
|
+
assoc = SubnetNetworkAclAssociation.new(self, network_acl)
|
33
|
+
config.cf_add_resource assoc.resource_name, assoc
|
34
|
+
end
|
35
|
+
super(config)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_h
|
39
|
+
h = {
|
40
|
+
"Type" => "AWS::EC2::Subnet",
|
41
|
+
"Properties" => {
|
42
|
+
"CidrBlock" => cidr,
|
43
|
+
}
|
44
|
+
}
|
45
|
+
h["Properties"]["VpcId"] = DrawCloud.ref(vpc) if vpc
|
46
|
+
h["Properties"]["AvailabilityZone"] = DrawCloud.ref(@availability_zone) if @availability_zone
|
47
|
+
add_standard_properties(h)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,264 @@
|
|
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
|
+
require "json"
|
20
|
+
require "active_support/inflector"
|
21
|
+
require "deep_merge"
|
22
|
+
|
23
|
+
module DrawCloud
|
24
|
+
class Base
|
25
|
+
include Utilities
|
26
|
+
include Locations
|
27
|
+
|
28
|
+
attr_accessor( :mappings,
|
29
|
+
:parameters,
|
30
|
+
:resources,
|
31
|
+
:outputs,
|
32
|
+
|
33
|
+
:subnets,
|
34
|
+
:route_tables,
|
35
|
+
:network_acls,
|
36
|
+
:security_groups,
|
37
|
+
:iam_users,
|
38
|
+
:iam_policies,
|
39
|
+
:iam_access_keys,
|
40
|
+
:gateways,
|
41
|
+
:rdses,
|
42
|
+
:elastic_ips,
|
43
|
+
:network_interfaces,
|
44
|
+
:wait_handles,
|
45
|
+
:ec2_instances,
|
46
|
+
:as_launch_configurations,
|
47
|
+
:as_groups,
|
48
|
+
:vpcs,
|
49
|
+
:sns_topics,
|
50
|
+
|
51
|
+
:depends_on,
|
52
|
+
:deletion_policy,
|
53
|
+
:metadata,
|
54
|
+
|
55
|
+
:parent )
|
56
|
+
|
57
|
+
def initialize(options={}, &block)
|
58
|
+
@mappings = {}
|
59
|
+
@parameters = {}
|
60
|
+
@resources = {}
|
61
|
+
@outputs = {}
|
62
|
+
|
63
|
+
@subnets = []
|
64
|
+
@route_tables = []
|
65
|
+
@network_acls = []
|
66
|
+
@security_groups = []
|
67
|
+
@iam_users = []
|
68
|
+
@iam_policies = []
|
69
|
+
@iam_access_keys = []
|
70
|
+
@gateways = []
|
71
|
+
@rdses = []
|
72
|
+
@ec2_instances = []
|
73
|
+
@as_launch_configurations = []
|
74
|
+
@as_groups = []
|
75
|
+
@elastic_ips = []
|
76
|
+
@network_interfaces = []
|
77
|
+
@wait_handles = []
|
78
|
+
@vpcs = []
|
79
|
+
@sns_topics = []
|
80
|
+
|
81
|
+
@parent = options.fetch(:parent, nil)
|
82
|
+
|
83
|
+
self.instance_exec(self, &block) if block
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_into_config(config)
|
87
|
+
[@mappings, @parameters, @resources, @outputs].each do |i|
|
88
|
+
i.each {|k,v| v.load_into_config(config)}
|
89
|
+
end
|
90
|
+
|
91
|
+
[@gateways, @subnets, @route_tables, @network_acls, @security_groups, @iam_users, @iam_policies, @iam_access_keys,
|
92
|
+
@rdses, @ec2_instances, @as_launch_configurations, @as_groups, @elastic_ips, @network_interfaces, @wait_handles, @vpcs, @sns_topics].each do |a|
|
93
|
+
a.each {|g| g.load_into_config(config) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def resource_name
|
98
|
+
resource_style(name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_standard_properties(hash)
|
102
|
+
hash["DependsOn"] = DrawCloud.resource_name(depends_on) if depends_on
|
103
|
+
hash["DeletionPolicy"] = DrawCloud.resource_style(deletion_policy) if deletion_policy
|
104
|
+
hash["Metadata"] = DrawCloud.ref(metadata) unless metadata.nil?
|
105
|
+
hash
|
106
|
+
end
|
107
|
+
|
108
|
+
def ref
|
109
|
+
{"Ref" => resource_name}
|
110
|
+
end
|
111
|
+
|
112
|
+
def [](attribute)
|
113
|
+
fngetatt(self, attribute)
|
114
|
+
end
|
115
|
+
|
116
|
+
## Definers
|
117
|
+
|
118
|
+
def create_mapping(name, map_by_function, values={})
|
119
|
+
m = Map.new(name, map_by_function, {:parent => self}, values)
|
120
|
+
mappings[m.resource_name] = m
|
121
|
+
m
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_output(name, options={}, &block)
|
125
|
+
o = Output.new(name, options.merge(:parent => self), &block)
|
126
|
+
outputs[o.resource_name] = o
|
127
|
+
o
|
128
|
+
end
|
129
|
+
|
130
|
+
def create_parameter(name, type, options={}, &block)
|
131
|
+
p = Parameter.new(name, type, options.merge(:parent => self), &block)
|
132
|
+
parameters[p.resource_name] = p
|
133
|
+
p
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_service(name, options={}, &block)
|
137
|
+
# NOOP
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_vpc(name, cidr, options={}, &block)
|
141
|
+
v = Vpc.new(name, cidr, options.merge(:parent => self), &block)
|
142
|
+
vpcs << v
|
143
|
+
v
|
144
|
+
end
|
145
|
+
|
146
|
+
def create_sns_topic(name, options={}, &block)
|
147
|
+
s = SNSTopic.new(name, options.merge(:parent => self), &block)
|
148
|
+
sns_topics << s
|
149
|
+
s
|
150
|
+
end
|
151
|
+
|
152
|
+
def create_subnet(name, cidr, options={}, &block)
|
153
|
+
# collisioncheck
|
154
|
+
s = Subnet.new(name, cidr, options.merge(:parent => self), &block)
|
155
|
+
subnets << s
|
156
|
+
s
|
157
|
+
end
|
158
|
+
|
159
|
+
def create_route_table(name, options={}, &block)
|
160
|
+
r = RouteTable.new(name, options.merge(:parent => self), &block)
|
161
|
+
route_tables << r
|
162
|
+
r
|
163
|
+
end
|
164
|
+
|
165
|
+
def create_network_acl(name, options={}, &block)
|
166
|
+
a = NetworkAcl.new(name, options.merge(:parent => self), &block)
|
167
|
+
network_acls << a
|
168
|
+
a
|
169
|
+
end
|
170
|
+
|
171
|
+
def create_security_group(name, description=nil, options={}, &block)
|
172
|
+
g = SecurityGroup.new(name, description, options.merge(:parent => self), &block)
|
173
|
+
security_groups << g
|
174
|
+
g
|
175
|
+
end
|
176
|
+
|
177
|
+
def create_iam_user(name, options={}, &block)
|
178
|
+
u = IAMUser.new(name, options.merge(:parent => self), &block)
|
179
|
+
iam_users << u
|
180
|
+
u
|
181
|
+
end
|
182
|
+
|
183
|
+
def create_iam_policy(name, options={}, &block)
|
184
|
+
p = IAMPolicy.new(name, options.merge(:parent => self), &block)
|
185
|
+
iam_policies << p
|
186
|
+
p
|
187
|
+
end
|
188
|
+
|
189
|
+
def create_iam_access_key(name, options={}, &block)
|
190
|
+
a = IAMAccessKey.new(name, options.merge(:parent => self), &block)
|
191
|
+
iam_access_keys << a
|
192
|
+
a
|
193
|
+
end
|
194
|
+
|
195
|
+
def create_rds(name, options={}, &block)
|
196
|
+
r = RDSInstance.new(name, options.merge(:parent => self), &block)
|
197
|
+
rdses << r
|
198
|
+
r
|
199
|
+
end
|
200
|
+
|
201
|
+
def create_ec2_instance_template(name, options={}, &block)
|
202
|
+
EC2InstanceTemplate.new(name, options.merge(:parent => self), &block)
|
203
|
+
end
|
204
|
+
|
205
|
+
def create_ec2_instance(name, options={}, &block)
|
206
|
+
e = EC2Instance.new(name, options.merge(:parent => self), &block)
|
207
|
+
ec2_instances << e
|
208
|
+
e
|
209
|
+
end
|
210
|
+
|
211
|
+
def create_as_launch_configuration(name, options={}, &block)
|
212
|
+
lc = ASLaunchConfiguration.new(name, options.merge(:parent => self), &block)
|
213
|
+
as_launch_configurations << lc
|
214
|
+
lc
|
215
|
+
end
|
216
|
+
|
217
|
+
def create_as_group(name, options={}, &block)
|
218
|
+
asg = ASGroup.new(name, options.merge(:parent => self), &block)
|
219
|
+
as_groups << asg
|
220
|
+
asg
|
221
|
+
end
|
222
|
+
|
223
|
+
def create_wait_handle(name, timeout=nil, options={}, &block)
|
224
|
+
h = WaitHandle.new(name, timeout, options.merge(:parent => self), &block)
|
225
|
+
wait_handles << h
|
226
|
+
h
|
227
|
+
end
|
228
|
+
|
229
|
+
def create_elastic_ip(name, options={}, &block)
|
230
|
+
eip = ElasticIp.new(name, options.merge(:parent => self), &block)
|
231
|
+
elastic_ips << eip
|
232
|
+
eip
|
233
|
+
end
|
234
|
+
|
235
|
+
def create_network_interface(name, options={}, &block)
|
236
|
+
eni = NetworkInterface.new(name, options.merge(:parent => self), &block)
|
237
|
+
network_interfaces << eni
|
238
|
+
eni
|
239
|
+
end
|
240
|
+
|
241
|
+
## Accessors (list below so grep works)
|
242
|
+
# def elastic_ip
|
243
|
+
# def internet_gateway
|
244
|
+
# def network_acl
|
245
|
+
# def rds
|
246
|
+
# def route_table
|
247
|
+
# def security_group
|
248
|
+
# def subnet
|
249
|
+
# def vpc
|
250
|
+
[:elastic_ip, :network_interface, :ec2_instance, :as_launch_configuration, :as_group,
|
251
|
+
:internet_gateway, :network_acl, :rds, :route_table, :security_group,
|
252
|
+
:subnet, :vpc, :iam_user, :iam_policy, :iam_access_key].each do |accessor|
|
253
|
+
self.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
254
|
+
def #{accessor}()
|
255
|
+
if parent
|
256
|
+
parent.#{accessor}
|
257
|
+
else
|
258
|
+
nil
|
259
|
+
end
|
260
|
+
end
|
261
|
+
RUBY_EVAL
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|