awspec 0.5.0 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f32e82baf76c33ca5593fa4e208835fb156855
4
- data.tar.gz: 1d874fc92873428cb5bd3ea4669088c035f061c6
3
+ metadata.gz: 64695d36dc5c2eacd3cfb6999fa4639aaad880a5
4
+ data.tar.gz: 8f8929979324810c08d756abb48f7f0259a74d17
5
5
  SHA512:
6
- metadata.gz: 20cb4c38567ea51ad2b752d63be0b177d6a1c08cf8eb12fd68d76f5f314fead66f2f87c80673fe4969a35bea15e5b364f0991a93ca576a6ce5e3acd297ed0b23
7
- data.tar.gz: 5ac15fe44483c9d1dfdd2516beaba709a3b46446b9e2167a85f25db6f3308bf999fe630a6f948c0f5c2985e793d9d9aa43676f8c5206ec905ef6a8e80eee1f3e
6
+ metadata.gz: a38ee03bfc99f1eac2854bc49b43cb31fc533fdebaa11a4bfef33c0a7bbc0d6060bbc769a254483349fa74c8b7c7916a9285030a4dcfe11e889705915dcbbcf6
7
+ data.tar.gz: 04d2562dfed0c1edf4cb1a0cd62c8d9b66b3136c9c7d25b3cad7671b45260d9d0d2d660b8857d120e8c7360a2c65f0d4ee123258222a9a1a4fff6d4b47b6cf20
data/.gitignore CHANGED
@@ -3,8 +3,7 @@
3
3
  /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
- /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
10
- /spec/secrets.yml
9
+ /spec/secrets.yml
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install awspec
20
20
 
21
- ## Usage
21
+ ## Getting Started
22
22
 
23
23
  ### 1. Generate awspec init files
24
24
 
@@ -87,17 +87,21 @@ $ awspec generate ec2 vpc-ab123cde >> spec/ec2_spec.rb
87
87
  - [x] Auto Scaling Group (`auto_scaling_group`)
88
88
  - [x] Subnet (`subnet`)
89
89
  - [x] RouteTable (`route_table`)
90
- - [x] EBS Volume
90
+ - [x] EBS Volume (`ebs`)
91
+ - [x] ELB (`elb`)
92
+
93
+ [Resource Types more infomation here](doc/resource_types.md)
91
94
 
92
95
  ### Next..
93
96
 
94
- - [ ] IAM
97
+ - IAM
98
+ - [ ] IAM User
95
99
  - ...
96
100
 
97
101
  ## TODO
98
102
 
99
- - [ ] Comment format for Document generation
100
- - [X] Spec generate command
103
+ - [x] Comment format for Document generation
104
+ - [x] Spec generate command
101
105
 
102
106
  ## Contributing
103
107
 
data/Rakefile CHANGED
@@ -8,14 +8,18 @@ end
8
8
  if defined?(RSpec)
9
9
  task spec: 'spec:all'
10
10
  namespace :spec do
11
- task all: ['spec:type', 'spec:generator']
11
+ task all: ['spec:type', 'spec:generator_spec', 'spec:generator_doc']
12
12
 
13
13
  RSpec::Core::RakeTask.new(:type) do |t|
14
14
  t.pattern = 'spec/type/*_spec.rb'
15
15
  end
16
16
 
17
- RSpec::Core::RakeTask.new(:generator) do |t|
18
- t.pattern = 'spec/generator/*_spec.rb'
17
+ RSpec::Core::RakeTask.new(:generator_spec) do |t|
18
+ t.pattern = 'spec/generator/spec/*_spec.rb'
19
+ end
20
+
21
+ RSpec::Core::RakeTask.new(:generator_doc) do |t|
22
+ t.pattern = 'spec/generator/doc/*_spec.rb'
19
23
  end
20
24
  end
21
25
  end
@@ -0,0 +1,15 @@
1
+ ### exist
2
+
3
+ ```ruby
4
+ describe ec2('my-ec2') do
5
+ it { should exist }
6
+ end
7
+ ```
8
+
9
+ ### be_running
10
+
11
+ ```ruby
12
+ describe ec2('my-ec2') do
13
+ it { should be_running }
14
+ end
15
+ ```
@@ -0,0 +1,9 @@
1
+ ### have_listener
2
+
3
+ http://docs.aws.amazon.com/en_us/ElasticLoadBalancing/latest/DeveloperGuide/elb-listener-config.html
4
+
5
+ ```ruby
6
+ describe elb('my-elb') do
7
+ it { should have_listener(protocol: 'HTTPS', port: 443, instance_protocol: 'HTTP', instance_port: 80) }
8
+ end
9
+ ```
@@ -0,0 +1,242 @@
1
+ # Resource Types
2
+
3
+ [ec2](#ec2)
4
+ | [rds](#rds)
5
+ | [rds_db_parameter_group](#rds_db_parameter_group)
6
+ | [security_group](#security_group)
7
+ | [vpc](#vpc)
8
+ | [s3](#s3)
9
+ | [route53_hosted_zone](#route53_hosted_zone)
10
+ | [auto_scaling_group](#auto_scaling_group)
11
+ | [subnet](#subnet)
12
+ | [route_table](#route_table)
13
+ | [ebs](#ebs)
14
+ | [elb](#elb)
15
+
16
+ ## <a name="ec2">ec2</a>
17
+
18
+ EC2 resource type.
19
+
20
+ ### exist
21
+
22
+ ```ruby
23
+ describe ec2('my-ec2') do
24
+ it { should exist }
25
+ end
26
+ ```
27
+
28
+
29
+ ### be_stopped
30
+
31
+ ### be_pending
32
+
33
+ ### be_running
34
+
35
+ ```ruby
36
+ describe ec2('my-ec2') do
37
+ it { should be_running }
38
+ end
39
+ ```
40
+
41
+ ### be_shutting_down
42
+
43
+ ### be_terminated
44
+
45
+ ### be_stopping
46
+
47
+ ### have_security_group
48
+
49
+ ### have_eip
50
+
51
+ ### have_ebs
52
+
53
+ ### belong_to_subnet
54
+
55
+ ### belong_to_vpc
56
+
57
+ #### its(:instance_id), its(:image_id), its(:private_dns_name), its(:public_dns_name), its(:state_transition_reason), its(:key_name), its(:ami_launch_index), its(:instance_type), its(:launch_time), its(:placement), its(:kernel_id), its(:ramdisk_id), its(:platform), its(:monitoring), its(:subnet_id), its(:vpc_id), its(:private_ip_address), its(:public_ip_address), its(:state_reason), its(:architecture), its(:root_device_type), its(:root_device_name), its(:virtualization_type), its(:instance_lifecycle), its(:spot_instance_request_id), its(:client_token), its(:source_dest_check), its(:hypervisor), its(:iam_instance_profile), its(:ebs_optimized), its(:sriov_net_support)
58
+ ## <a name="rds">rds</a>
59
+
60
+ RDS resource type.
61
+
62
+ ### exist
63
+
64
+ ### be_upgrading
65
+
66
+ ### be_storage_full
67
+
68
+ ### be_available
69
+
70
+ ### be_backing_up
71
+
72
+ ### be_creating
73
+
74
+ ### be_deleting
75
+
76
+ ### be_failed
77
+
78
+ ### be_inaccessible_encryption_credentials
79
+
80
+ ### be_incompatible_credentials
81
+
82
+ ### be_incompatible_network
83
+
84
+ ### be_incompatible_option_group
85
+
86
+ ### be_incompatible_parameters
87
+
88
+ ### be_restore_error
89
+
90
+ ### be_maintenance
91
+
92
+ ### be_modifying
93
+
94
+ ### be_rebooting
95
+
96
+ ### be_renaming
97
+
98
+ ### be_resetting_master_credentials
99
+
100
+ ### be_incompatible_restore
101
+
102
+ ### have_db_parameter_group
103
+
104
+ ### have_option_group
105
+
106
+ ### have_security_group
107
+
108
+ ### belong_to_db_subnet_group
109
+
110
+ ### belong_to_subnet
111
+
112
+ ### belong_to_vpc
113
+
114
+ #### its(:vpc_id), its(:db_instance_identifier), its(:db_instance_class), its(:engine), its(:db_instance_status), its(:master_username), its(:db_name), its(:endpoint), its(:allocated_storage), its(:instance_create_time), its(:preferred_backup_window), its(:backup_retention_period), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:latest_restorable_time), its(:multi_az), its(:engine_version), its(:auto_minor_version_upgrade), its(:read_replica_source_db_instance_identifier), its(:license_model), its(:iops), its(:character_set_name), its(:secondary_availability_zone), its(:publicly_accessible), its(:storage_type), its(:tde_credential_arn), its(:db_instance_port), its(:db_cluster_identifier), its(:storage_encrypted), its(:kms_key_id), its(:dbi_resource_id), its(:ca_certificate_identifier)
115
+ ## <a name="rds_db_parameter_group">rds_db_parameter_group</a>
116
+
117
+ RdsDbParameterGroup resource type.
118
+
119
+ ### exist
120
+
121
+
122
+ ## <a name="security_group">security_group</a>
123
+
124
+ SecurityGroup resource type.
125
+
126
+ ### exist
127
+
128
+ ### its(:inbound), its(:outbound)
129
+
130
+ #### its(:ip_permissions_count), its(:ip_permissions_egress_count), its(:owner_id), its(:group_name), its(:group_id), its(:description), its(:vpc_id)
131
+ ## <a name="vpc">vpc</a>
132
+
133
+ VPC resource type.
134
+
135
+ ### exist
136
+
137
+ ### be_pending
138
+
139
+ ### be_available
140
+
141
+ ### have_network_acl
142
+
143
+ ### have_route_table
144
+
145
+ #### its(:vpc_id), its(:state), its(:cidr_block), its(:dhcp_options_id), its(:instance_tenancy), its(:is_default)
146
+ ## <a name="s3">s3</a>
147
+
148
+ S3 resource type.
149
+
150
+ ### exist
151
+
152
+ ### have_object
153
+
154
+ #### its(:name), its(:creation_date)
155
+ ## <a name="route53_hosted_zone">route53_hosted_zone</a>
156
+
157
+ Route53HostedZone resource type.
158
+
159
+ ### exist
160
+
161
+ ### have_record_set
162
+
163
+ #### its(:id), its(:name), its(:caller_reference), its(:config), its(:resource_record_set_count)
164
+ ## <a name="auto_scaling_group">auto_scaling_group</a>
165
+
166
+ AutoScalingGroup resource type.
167
+
168
+ ### exist
169
+
170
+ ### have_ec2
171
+
172
+ ### have_elb
173
+
174
+ #### its(:auto_scaling_group_name), its(:auto_scaling_group_arn), its(:launch_configuration_name), its(:min_size), its(:max_size), its(:desired_capacity), its(:default_cooldown), its(:health_check_type), its(:health_check_grace_period), its(:created_time), its(:placement_group), its(:vpc_zone_identifier), its(:status)
175
+ ## <a name="subnet">subnet</a>
176
+
177
+ Subnet resource type.
178
+
179
+ ### exist
180
+
181
+ ### be_pending
182
+
183
+ ### be_available
184
+
185
+ #### its(:subnet_id), its(:state), its(:vpc_id), its(:cidr_block), its(:available_ip_address_count), its(:availability_zone), its(:default_for_az), its(:map_public_ip_on_launch)
186
+ ## <a name="route_table">route_table</a>
187
+
188
+ RouteTable resource type.
189
+
190
+ ### exist
191
+
192
+ ### have_route
193
+
194
+ #### its(:route_table_id), its(:vpc_id)
195
+ ## <a name="ebs">ebs</a>
196
+
197
+ EBS resource type.
198
+
199
+ ### exist
200
+
201
+ ### be_deleted
202
+
203
+ ### be_in_use
204
+
205
+ ### be_deleting
206
+
207
+ ### be_available
208
+
209
+ ### be_error
210
+
211
+ ### be_attached_to
212
+
213
+ ### be_creating
214
+
215
+ #### its(:volume_id), its(:size), its(:snapshot_id), its(:availability_zone), its(:state), its(:create_time), its(:volume_type), its(:iops), its(:encrypted), its(:kms_key_id)
216
+ ## <a name="elb">elb</a>
217
+
218
+ ELB resource type.
219
+
220
+ ### exist
221
+
222
+ ### have_listener
223
+
224
+ http://docs.aws.amazon.com/en_us/ElasticLoadBalancing/latest/DeveloperGuide/elb-listener-config.html
225
+
226
+ ```ruby
227
+ describe elb('my-elb') do
228
+ it { should have_listener(protocol: 'HTTPS', port: 443, instance_protocol: 'HTTP', instance_port: 80) }
229
+ end
230
+ ```
231
+
232
+ ### have_ec2
233
+
234
+ ### have_subnet
235
+
236
+ ### have_security_group
237
+
238
+ ### belong_to_subnet
239
+
240
+ ### belong_to_vpc
241
+
242
+ #### its(:health_check_target), its(:health_check_interval), its(:health_check_timeout), its(:health_check_unhealthy_threshold), its(:health_check_healthy_threshold), its(:load_balancer_name), its(:dns_name), its(:canonical_hosted_zone_name), its(:canonical_hosted_zone_name_id), its(:vpc_id), its(:created_time), its(:scheme)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'awspec'
4
+
5
+ Aws.config[:stub_responses] = true
6
+
7
+ types = Awspec::Helper::Type::TYPES
8
+ types.delete('base')
9
+
10
+ links = types.map do |type|
11
+ '[' + type + '](#' + type + ')'
12
+ end
13
+ header = <<-'EOF'
14
+ # Resource Types
15
+
16
+ <%= links.join("\n| ") %>
17
+
18
+ EOF
19
+ puts ERB.new(header, nil, '-').result(binding)
20
+
21
+ types.map do |type|
22
+ puts eval "Awspec::Generator::Doc::#{type.to_camel_case}.new.generate_doc"
23
+ end
@@ -1,5 +1,13 @@
1
+ types = Awspec::Helper::Type::TYPES
2
+
3
+ # Spec
1
4
  require 'awspec/generator/spec/ec2'
2
5
  require 'awspec/generator/spec/rds'
3
6
  require 'awspec/generator/spec/vpc'
4
7
  require 'awspec/generator/spec/security_group'
5
8
  require 'awspec/generator/spec/route53_hosted_zone'
9
+
10
+ # Doc
11
+ types.each do |type|
12
+ require 'awspec/generator/doc/' + type
13
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class AutoScalingGroup < Base
4
+ def initialize
5
+ @type_name = 'AutoScalingGroup'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::AutoScalingGroup.new('my-auto-scaling-group')
8
+ @ret = @type.group
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Base
4
+ def generate_doc
5
+ @matchers += collect_matchers - @ignore_matchers
6
+ @matchers.sort! do |a, b|
7
+ sort_num(a) <=> sort_num(b)
8
+ end
9
+ @describes += @ret.members.select do |describe|
10
+ next true unless @ret[describe].is_a?(Array) || @ret[describe].is_a?(Hash) || @ret[describe].is_a?(Struct)
11
+ end if @ret.respond_to?(:members)
12
+ its = @describes.map do |describe|
13
+ 'its(:' + describe.to_s + ')'
14
+ end
15
+
16
+ @descriptions = {}
17
+ merge_file = File.dirname(__FILE__) + '/../../../../doc/_resource_types/' + @type_name.to_snake_case + '.md'
18
+ if File.exist?(merge_file)
19
+ matcher = nil
20
+ File.foreach(merge_file) do |line|
21
+ if /\A### (.+)\Z/ =~ line
22
+ matcher = Regexp.last_match[1]
23
+ next
24
+ end
25
+ @descriptions[matcher] = '' unless @descriptions[matcher]
26
+ @descriptions[matcher] += line
27
+ end
28
+ end
29
+ ERB.new(doc_template, nil, '-').result(binding)
30
+ end
31
+
32
+ def collect_matchers
33
+ methods = @type.methods - Awspec::Helper::Finder.instance_methods - Object.methods
34
+ methods.select! do |method|
35
+ method.to_s.include?('?')
36
+ end
37
+ methods.map! do |method|
38
+ next 'exist' if 'exists?' == method.to_s
39
+ next 'have_' + Regexp.last_match[1] if /\Ahas_(.+)\?\z/ =~ method.to_s
40
+ next 'be_' + Regexp.last_match[1] if /\A(.+)\?\z/ =~ method.to_s
41
+ method.to_s
42
+ end
43
+ end
44
+
45
+ def doc_template
46
+ template = <<-'EOF'
47
+ ## <a name="<%= @type_name.to_snake_case %>"><%= @type_name.to_snake_case %></a>
48
+
49
+ <%= @type_name %> resource type.
50
+ <% @matchers.each do |matcher| %>
51
+ ### <%= matcher %>
52
+ <%- if @descriptions.include?(matcher) -%><%= @descriptions[matcher] %><%- end -%>
53
+ <% end %>
54
+ <%- unless its.empty? -%>#### <%= its.join(', ') %><%- end -%>
55
+
56
+ EOF
57
+ template
58
+ end
59
+
60
+ def sort_num(str)
61
+ case str
62
+ when 'exist'
63
+ 0
64
+ when /\Abe_/
65
+ 1
66
+ when /\Ahave_/
67
+ 2
68
+ else
69
+ 3
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Ebs < Base
4
+ def initialize
5
+ @type_name = 'EBS'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Ebs.new('my-ebs')
8
+ @ret = @type.volume
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Ec2 < Base
4
+ def initialize
5
+ @type_name = 'EC2'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Ec2.new('my-ec2')
8
+ @ret = @type.instance
9
+ @matchers = %w(belong_to_vpc belong_to_subnet)
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Elb < Base
4
+ def initialize
5
+ @type_name = 'ELB'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Elb.new('my-elb')
8
+ @ret = @type.lb
9
+ @matchers = %w(belong_to_vpc belong_to_subnet)
10
+ @ignore_matchers = []
11
+ @describes = %w(
12
+ health_check_target health_check_interval health_check_timeout
13
+ health_check_unhealthy_threshold health_check_healthy_threshold
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Rds < Base
4
+ def initialize
5
+ @type_name = 'RDS'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Rds.new('my-rds')
8
+ @ret = @type.instance
9
+ @matchers = %w(belong_to_vpc belong_to_subnet belong_to_db_subnet_group)
10
+ @ignore_matchers = []
11
+ @describes = %w(vpc_id)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class RdsDbParameterGroup < Base
4
+ def initialize
5
+ @type_name = 'RdsDbParameterGroup'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::RdsDbParameterGroup.new('my-rds-db-parameter-group')
8
+ @ret = @type.parameters
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Route53HostedZone < Base
4
+ def initialize
5
+ @type_name = 'Route53HostedZone'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Route53HostedZone.new('example.com.')
8
+ @ret = @type.hosted_zone
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class RouteTable < Base
4
+ def initialize
5
+ @type_name = 'RouteTable'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::RouteTable.new('my-route-table')
8
+ @ret = @type.route_table
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class S3 < Base
4
+ def initialize
5
+ @type_name = 'S3'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::S3.new('my-bucket')
8
+ @ret = @type.bucket
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class SecurityGroup < Base
4
+ def initialize
5
+ @type_name = 'SecurityGroup'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::SecurityGroup.new('my-security-group-name')
8
+ @ret = @type.sg
9
+ @matchers = ['its(:inbound), its(:outbound)']
10
+ @ignore_matchers = %w(be_opened be_inbound_opened be_outbound_opened)
11
+ @describes = %w(ip_permissions_count ip_permissions_egress_count)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Subnet < Base
4
+ def initialize
5
+ @type_name = 'Subnet'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Subnet.new('my-route-table')
8
+ @ret = @type.subnet
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ class Vpc < Base
4
+ def initialize
5
+ @type_name = 'VPC'
6
+ require File.dirname(__FILE__) + '/../../../../spec/stub/' + @type_name.to_snake_case
7
+ @type = Awspec::Type::Vpc.new('my-vpc')
8
+ @ret = @type.vpc
9
+ @matchers = []
10
+ @ignore_matchers = []
11
+ @describes = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,7 @@ require 'awspec/helper/finder/rds'
6
6
  require 'awspec/helper/finder/route53'
7
7
  require 'awspec/helper/finder/s3'
8
8
  require 'awspec/helper/finder/auto_scaling'
9
+ require 'awspec/helper/finder/elb'
9
10
 
10
11
  module Awspec::Helper
11
12
  module Finder
@@ -17,6 +18,7 @@ module Awspec::Helper
17
18
  include Awspec::Helper::Finder::Route53
18
19
  include Awspec::Helper::Finder::S3
19
20
  include Awspec::Helper::Finder::AutoScaling
21
+ include Awspec::Helper::Finder::Elb
20
22
 
21
23
  # rubocop:disable all
22
24
  def initialize(id = nil)
@@ -25,6 +27,7 @@ module Awspec::Helper
25
27
  @route53_client = Aws::Route53::Client.new
26
28
  @s3_client = Aws::S3::Client.new
27
29
  @auto_scaling_client = Aws::AutoScaling::Client.new
30
+ @elb_client = Aws::ElasticLoadBalancing::Client.new
28
31
  end
29
32
  end
30
33
  end
@@ -16,7 +16,7 @@ module Awspec::Helper
16
16
  res = @ec2_client.describe_instances({
17
17
  filters: filters
18
18
  })
19
- else
19
+ elsif id.is_a?(String)
20
20
  # instance_id or tag:Name
21
21
  begin
22
22
  res = @ec2_client.describe_instances({
@@ -29,6 +29,8 @@ module Awspec::Helper
29
29
  filters: [{ name: 'tag:Name', values: [id] }]
30
30
  })
31
31
  end
32
+ else
33
+ return nil
32
34
  end
33
35
  return res[:reservations][0][:instances][0] if res[:reservations].count == 1 && \
34
36
  res[:reservations][0][:instances].count == 1
@@ -0,0 +1,14 @@
1
+ module Awspec::Helper
2
+ module Finder
3
+ module Elb
4
+ def find_elb(id)
5
+ res = @elb_client.describe_load_balancers({
6
+ load_balancer_names: [id]
7
+ })
8
+ return res[:load_balancer_descriptions][0] if res[:load_balancer_descriptions].count == 1
9
+ rescue
10
+ return nil
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,15 +1,14 @@
1
1
  module Awspec
2
2
  module Helper
3
3
  module Type
4
- types = %w(
4
+ TYPES = %w(
5
5
  base ec2 rds rds_db_parameter_group security_group
6
6
  vpc s3 route53_hosted_zone auto_scaling_group subnet
7
- route_table ebs
7
+ route_table ebs elb
8
8
  )
9
9
 
10
- types.each { |type| require "awspec/type/#{type}" }
11
-
12
- types.each do |type|
10
+ TYPES.each do |type|
11
+ require "awspec/type/#{type}"
13
12
  define_method type do |*args|
14
13
  name = args.first
15
14
  eval "Awspec::Type::#{type.to_camel_case}.new(name)"
@@ -15,7 +15,7 @@ module Awspec::Type
15
15
  )
16
16
 
17
17
  states.each do |state|
18
- define_method state + '?' do
18
+ define_method state.tr('-', '_') + '?' do
19
19
  @instance[:state][:name] == state
20
20
  end
21
21
  end
@@ -0,0 +1,71 @@
1
+ module Awspec::Type
2
+ class Elb < Base
3
+ attr_reader :lb
4
+
5
+ def initialize(id)
6
+ super
7
+ @lb = find_elb(id)
8
+ @id = @lb[:load_balancer_name] if @lb
9
+ end
10
+
11
+ health_check_options = %w(
12
+ target interval timeout
13
+ unhealthy_threshold healthy_threshold
14
+ )
15
+
16
+ health_check_options.each do |option|
17
+ define_method 'health_check_' + option do
18
+ @lb[:health_check][option]
19
+ end
20
+ end
21
+
22
+ def method_missing(name)
23
+ describe = name.to_sym
24
+ if @lb.members.include?(describe)
25
+ @lb[describe]
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def has_ec2?(id)
32
+ ec2 = find_ec2(id)
33
+ @lb.instances.find do |instance|
34
+ instance.instance_id = ec2.instance_id
35
+ end if ec2
36
+ end
37
+
38
+ def has_security_group?(sg_id)
39
+ sgs = @lb[:security_groups]
40
+ ret = sgs.find do |sg|
41
+ sg == sg_id
42
+ end
43
+ return true if ret
44
+ sg2 = find_security_group(sg_id)
45
+ return false unless sg2.tag_name == sg_id || sg2[:group_name] == sg_id
46
+ sgs.find do |sg|
47
+ sg == sg2[:group_name]
48
+ end
49
+ end
50
+
51
+ def has_subnet?(subnet_id)
52
+ subnets = @lb[:subnets]
53
+ ret = subnets.find do |s|
54
+ s == subnet_id
55
+ end
56
+ return true if ret
57
+ res = find_subnet(subnet_id)
58
+ ret = subnets.find do |s|
59
+ s == res[:subnet_id]
60
+ end
61
+ end
62
+
63
+ def has_listener?(protocol:, port:, instance_protocol:, instance_port:)
64
+ @lb[:listener_descriptions].find do |desc|
65
+ listener = desc.listener
66
+ listener.protocol == protocol && listener.load_balancer_port == port && \
67
+ listener.instance_protocol == instance_protocol && listener.instance_port == instance_port
68
+ end
69
+ end
70
+ end
71
+ end
@@ -19,7 +19,7 @@ module Awspec::Type
19
19
  )
20
20
 
21
21
  states.each do |state|
22
- define_method state + '?' do
22
+ define_method state.tr('-', '_') + '?' do
23
23
  @instance[:db_instance_status] == state
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -140,13 +140,30 @@ files:
140
140
  - Rakefile
141
141
  - awspec.gemspec
142
142
  - bin/awspec
143
+ - doc/_resource_types/ec2.md
144
+ - doc/_resource_types/elb.md
145
+ - doc/resource_types.md
143
146
  - lib/awspec.rb
144
147
  - lib/awspec/cli.rb
145
148
  - lib/awspec/command/generate.rb
149
+ - lib/awspec/docgen.rb
146
150
  - lib/awspec/ext.rb
147
151
  - lib/awspec/ext/string.rb
148
152
  - lib/awspec/ext/struct.rb
149
153
  - lib/awspec/generator.rb
154
+ - lib/awspec/generator/doc/auto_scaling_group.rb
155
+ - lib/awspec/generator/doc/base.rb
156
+ - lib/awspec/generator/doc/ebs.rb
157
+ - lib/awspec/generator/doc/ec2.rb
158
+ - lib/awspec/generator/doc/elb.rb
159
+ - lib/awspec/generator/doc/rds.rb
160
+ - lib/awspec/generator/doc/rds_db_parameter_group.rb
161
+ - lib/awspec/generator/doc/route53_hosted_zone.rb
162
+ - lib/awspec/generator/doc/route_table.rb
163
+ - lib/awspec/generator/doc/s3.rb
164
+ - lib/awspec/generator/doc/security_group.rb
165
+ - lib/awspec/generator/doc/subnet.rb
166
+ - lib/awspec/generator/doc/vpc.rb
150
167
  - lib/awspec/generator/spec/ec2.rb
151
168
  - lib/awspec/generator/spec/rds.rb
152
169
  - lib/awspec/generator/spec/route53_hosted_zone.rb
@@ -156,6 +173,7 @@ files:
156
173
  - lib/awspec/helper/finder.rb
157
174
  - lib/awspec/helper/finder/auto_scaling.rb
158
175
  - lib/awspec/helper/finder/ec2.rb
176
+ - lib/awspec/helper/finder/elb.rb
159
177
  - lib/awspec/helper/finder/rds.rb
160
178
  - lib/awspec/helper/finder/route53.rb
161
179
  - lib/awspec/helper/finder/s3.rb
@@ -174,6 +192,7 @@ files:
174
192
  - lib/awspec/type/base.rb
175
193
  - lib/awspec/type/ebs.rb
176
194
  - lib/awspec/type/ec2.rb
195
+ - lib/awspec/type/elb.rb
177
196
  - lib/awspec/type/rds.rb
178
197
  - lib/awspec/type/rds_db_parameter_group.rb
179
198
  - lib/awspec/type/route53_hosted_zone.rb