aws-cfn-resources 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aws-cfn-resources.rb +1 -0
  3. data/lib/stack.rb +265 -0
  4. metadata +89 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05b01d2b56114328a00ad7349aca565646973684
4
+ data.tar.gz: fe3c6f155064d989bff61a5cfd9d7e2a21ba68df
5
+ SHA512:
6
+ metadata.gz: c11ab1e170639565f0d60a73e44be099903038aa4f592f8659f7458199aeff31e29ee7021e70df253eff30b23d3aefd90510ce632419da85968001bf9d4f6a5b
7
+ data.tar.gz: 4747f75d1784ffb3c7b369514cea8fa6d9a204eb0f78123f6b71a07095d716e0ba0c7a3c02124878e4ee5b0051e0cd8da035cfb4b31a50d0dd17362ee0b069ea
@@ -0,0 +1 @@
1
+ require 'stack.rb'
@@ -0,0 +1,265 @@
1
+ require 'aws-sdk-v1'
2
+
3
+ #set AWS.config(region: 'region-name')
4
+ #initialize stack with stack = AWS::CloudFormation::Stack.new('stack-name')
5
+
6
+ module AWS
7
+ class CloudFormation
8
+ class Stack
9
+
10
+ def autoscaling_group(logical_id)
11
+ AWS::AutoScaling.new.groups[autoscaling_group_ids[logical_id.to_sym]]
12
+ end
13
+
14
+ def autoscaling_groups
15
+ autoscaling_group_ids.inject({}) { |hash, (k,v)| hash[k] = autoscaling_group(k); hash }
16
+ end
17
+
18
+ def autoscaling_group_ids
19
+ get_resources "AWS::AutoScaling::AutoScalingGroup"
20
+ end
21
+
22
+ def bucket(logical_id)
23
+ AWS::S3.new.buckets[bucket_ids[logical_id.to_sym]]
24
+ end
25
+
26
+ def buckets
27
+ bucket_ids.inject({}) { |hash, (k,v)| hash[k] = bucket(k); hash }
28
+ end
29
+
30
+ def bucket_ids
31
+ get_resources "AWS::S3::Bucket"
32
+ end
33
+
34
+ def cloudwatch_alarm(logical_id)
35
+ AWS::CloudWatch.new.alarms[cloudwatch_alarm_ids[logical_id.to_sym]]
36
+ end
37
+
38
+ def cloudwatch_alarms
39
+ cloudwatch_alarm_ids.inject({}) { |hash, (k,v)| hash[k] = cloudwatch_alarm(k); hash }
40
+ end
41
+
42
+ def cloudwatch_alarm_ids
43
+ get_resources "AWS::CloudWatch::Alarm"
44
+ end
45
+
46
+ def db_instance(logical_id)
47
+ AWS::RDS.new.db_instances[db_instance_ids[logical_id.to_sym]]
48
+ end
49
+
50
+ def db_instances
51
+ db_instance_ids.inject({}) { |hash, (k,v)| hash[k] = db_instance(k); hash }
52
+ end
53
+
54
+ def db_instance_ids
55
+ get_resources "AWS::RDS::DBInstance"
56
+ end
57
+
58
+ def eip(logical_id)
59
+ AWS::EC2.new.elastic_ips[eip_ids[logical_id.to_sym]]
60
+ end
61
+
62
+ alias_method :elastic_ip, :eip
63
+
64
+ def eips
65
+ eip_ids.inject({}) { |hash, (k,v)| hash[k] = eip(k) }
66
+ end
67
+
68
+ alias_method :elastic_ips, :eips
69
+
70
+ def eip_ids
71
+ get_resources "AWS::EC2::EIP"
72
+ end
73
+
74
+ def elb(logical_id)
75
+ AWS::ELB.new.load_balancers[elb_ids[logical_id.to_sym]]
76
+ end
77
+
78
+ def elbs
79
+ elb_ids.inject({}) { |hash, (k,v)| hash[k] = elb(k); hash }
80
+ end
81
+
82
+ def elb_ids
83
+ get_resources "AWS::ElasticLoadBalancing::LoadBalancer"
84
+ end
85
+
86
+ def iam_access_key(user_logical_id, key_logical_id)
87
+ iam_user(user_logical_id).access_keys[iam_access_key_ids[key_logical_id.to_sym]]
88
+ end
89
+
90
+ def iam_access_key_ids
91
+ get_resources "AWS::IAM::AccessKey"
92
+ end
93
+
94
+ def iam_group(logical_id)
95
+ AWS::IAM.new.groups[iam_group_ids[logical_id.to_sym]]
96
+ end
97
+
98
+ def iam_groups
99
+ iam_group_ids.inject({}) { |hash, (k,v)| hash[k] = iam_group(k); hash }
100
+ end
101
+
102
+ def iam_group_ids
103
+ get_resources "AWS::IAM::Group"
104
+ end
105
+
106
+ def iam_policy
107
+ puts "use Stack.iam_group#policies or Stack.iam_user#policies"
108
+ end
109
+
110
+ alias_method :iam_policies, :iam_policy
111
+
112
+ def iam_policy_ids
113
+ get_resources "AWS::IAM::Policy"
114
+ end
115
+
116
+ def iam_user(logical_id)
117
+ AWS::IAM.new.users[iam_user_ids[logical_id.to_sym]]
118
+ end
119
+
120
+ def iam_users
121
+ iam_user_ids.inject({}) { |hash, (k,v)| hash[k] = iam_user(k); hash }
122
+ end
123
+
124
+ def iam_user_ids
125
+ get_resources "AWS::IAM::User"
126
+ end
127
+
128
+ def instance(logical_id)
129
+ AWS::EC2.new.instances[instance_ids[logical_id.to_sym]]
130
+ end
131
+
132
+ def instances
133
+ instance_ids.inject({}) { |hash, (k,v)| hash[k] = instance(k); hash }
134
+ end
135
+
136
+ def instance_ids
137
+ get_resources "AWS::EC2::Instance"
138
+ end
139
+
140
+ def internet_gateway(logical_id)
141
+ AWS::EC2.new.internet_gateways[internet_gateway_ids[logical_id.to_sym]]
142
+ end
143
+
144
+ alias_method :igw, :internet_gateway
145
+
146
+ def internet_gateway_ids
147
+ get_resources "AWS::EC2::InternetGateway"
148
+ end
149
+
150
+ def launch_configuration(logical_id)
151
+ AWS::AutoScaling.new.launch_configurations[launch_configuration_ids[logical_id.to_sym]]
152
+ end
153
+
154
+ alias_method :launch_config, :launch_configuration
155
+
156
+ def launch_configurations
157
+ launch_configuration_ids.inject({}) { |hash, (k,v)| hash[k] = launch_configuration(k); hash }
158
+ end
159
+
160
+ alias_method :launch_configs, :launch_configurations
161
+
162
+ def launch_configuration_ids
163
+ get_resources "AWS::AutoScaling::LaunchConfiguration"
164
+ end
165
+
166
+ def network_interface(logical_id)
167
+ AWS::EC2.new.network_interfaces[network_interface_ids[logical_id.to_sym]]
168
+ end
169
+
170
+ alias_method :nic, :network_interface
171
+
172
+ def network_interfaces
173
+ network_interface_ids.inject({}) { |hash, (k,v)| hash[k] = network_interface(k); hash }
174
+ end
175
+
176
+ alias_method :nics, :network_interfaces
177
+
178
+ def network_interface_ids
179
+ get_resources "AWS::EC2::NetworkInterface"
180
+ end
181
+
182
+ def route_table(logical_id)
183
+ AWS::EC2.new.route_tables[route_table_ids[logical_id.to_sym]]
184
+ end
185
+
186
+ def route_table_ids
187
+ get_resources "AWS::EC2::RouteTable"
188
+ end
189
+
190
+ def scaling_policy(as_group_logical_id, policy_logical_id)
191
+ group = autoscaling_group(as_group_logical_id)
192
+ policy = scaling_policy_ids[policy_logical_id.to_sym].split('/')[-1]
193
+ AWS::AutoScaling::ScalingPolicy.new(group, policy)
194
+ end
195
+
196
+ def scaling_policies(as_group_logical_id)
197
+ scaling_policy_ids.inject({}) { |hash, (k,v)| hash[k] = scaling_policy(as_group_logical_id,k.to_s); hash }
198
+ end
199
+
200
+ def scaling_policy_ids
201
+ get_resources "AWS::AutoScaling::ScalingPolicy"
202
+ end
203
+
204
+ #v1
205
+ def security_group(logical_id)
206
+ AWS::EC2.new.security_groups.filter('group-id',security_group_ids[logical_id.to_sym]).first
207
+ end
208
+
209
+ #v1
210
+ def security_groups
211
+ security_group_ids.inject({}) { |hash, (k,v)| hash[k] = security_group(k); hash }
212
+ end
213
+
214
+ def security_group_ids
215
+ get_resources "AWS::EC2::SecurityGroup"
216
+ end
217
+
218
+ def subnet(logical_id)
219
+ AWS::EC2.new.subnets[subnet_ids[logical_id.to_sym]]
220
+ end
221
+
222
+ def subnets
223
+ subnet_ids.inject({}) { |hash, (k,v)| hash[k] = subnet(k); hash }
224
+ end
225
+
226
+ def subnet_ids
227
+ get_resources "AWS::EC2::Subnet"
228
+ end
229
+
230
+ def volume(logical_id)
231
+ AWS::EC2.new.volumes[volume_ids[logical_id.to_sym]]
232
+ end
233
+
234
+ def volumes
235
+ volume_ids.inject({}) { |hash, (k,v)| hash[k] = volume(k); hash }
236
+ end
237
+
238
+ def volume_ids
239
+ get_resources "AWS::EC2::Volume"
240
+ end
241
+
242
+ def vpc(logical_id)
243
+ AWS::EC2.new.vpcs[vpc_ids[logical_id.to_sym]]
244
+ end
245
+
246
+ def vpcs
247
+ vpc_ids.inject({}) { |hash, (k,v)| hash[k] = vpc(k); hash }
248
+ end
249
+
250
+ def vpc_ids
251
+ get_resources "AWS::EC2::VPC"
252
+ end
253
+
254
+ private
255
+
256
+ def get_resources(resource_type)
257
+ hash = {}
258
+ resource_summaries.select { |rs| rs[:resource_type] == "#{resource_type}" }.collect { |r| hash[r[:logical_resource_id].to_sym] = r[:physical_resource_id] }
259
+ return hash
260
+ end
261
+
262
+ end
263
+ end
264
+ end
265
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-cfn-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shayne Clausson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-v1
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.64'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.64'
55
+ description: Use this gem to retrieve a single resource object, a group of resource
56
+ objects or a listing of physical resource ids from a deployed CloudFormation stack
57
+ email: sclausson@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/aws-cfn-resources.rb
63
+ - lib/stack.rb
64
+ homepage: http://rubygems.org/gems/aws-cfn-resources
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 1.9.3
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Simplifies retrieving AWS resource objects created by CloudFormation
89
+ test_files: []