awspec 0.83.0 → 0.84.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35e0d4f4b803b52d799f8f40579fa88eda612267
4
- data.tar.gz: 8329066b3d6b470ce05746c33774900b4c1f196d
3
+ metadata.gz: 2cc2bd071ea04f3b2175755926830351f496624c
4
+ data.tar.gz: eb61149da8f117126acabac296f0aebee339f6f0
5
5
  SHA512:
6
- metadata.gz: b1b2f9061e86bb879597803daf5e8dd784c3eda525a3eaec6a928392bbeeb1066f27fc5ee6e074057f3030ead4292de5e481719f141e71e396245ae9f272692a
7
- data.tar.gz: 163f822f89c775a756f12889a30117a1ead75244e2eca930f9a1df4da69c52e8abdb232700f0d5930d074af3c300b49bebd6e89a249c866b3f60d8be9fda2a89
6
+ metadata.gz: 2da4033f7141921eb56c5d12983864f65505a63a57c4c4a7c512994353cb40d170270c3a8aed5f8b7677547e376b23d5ffad819d84b13618b38fc2164d38e04c
7
+ data.tar.gz: f0ae057b8e2e7cfe943f00032b73f1e502ba295ad5c395cde0183c5d2d531f429e004d427ccc3746fd1fce77284b6bb0b6dfd48c8bf98d12d0e2afc1675da12c
@@ -29,3 +29,11 @@ describe alb('my-alb') do
29
29
  it { should have_subnet('subnet-1234a567') }
30
30
  end
31
31
  ```
32
+
33
+ ### belong_to_vpc
34
+
35
+ ```ruby
36
+ describe alb('my-alb') do
37
+ it { should belong_to_vpc('my-vpc') }
38
+ end
39
+ ```
@@ -1,4 +1,4 @@
1
- # exist
1
+ ### exist
2
2
 
3
3
  ```ruby
4
4
  describe alb_listener('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2') do
@@ -7,3 +7,23 @@ describe alb_listener('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:li
7
7
  its(:protocol) { should eq 'HTTP' }
8
8
  end
9
9
  ```
10
+
11
+ ### have_rule
12
+
13
+ ```ruby
14
+ describe alb_listener('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2') do
15
+ it { should have_rule('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener-rule/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2/9683b2d02a6cabee') }
16
+ it do
17
+ should have_rule.priority('10')
18
+ .conditions(field: 'path-pattern', values: ['/img/*'])
19
+ .actions(target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067', type: 'forward')
20
+ end
21
+ it do
22
+ should have_rule.priority('10')
23
+ .if(field: 'path-pattern', values: ['/img/*'])
24
+ .then(target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067', type: 'forward')
25
+ end
26
+ it { should have_rule.conditions([{ field: 'path-pattern', values: ['/admin/*'] }, { field: 'host-header', values: ['admin.example.com'] }]) }
27
+ it { should have_rule.actions(target_group_name: 'my-alb-target-group', type: 'forward') }
28
+ end
29
+ ```
@@ -0,0 +1,35 @@
1
+ # exist
2
+
3
+ ```ruby
4
+ describe alb_target_group('my-alb-target-group') do
5
+ it { should exist }
6
+ its(:health_check_path) { should eq '/' }
7
+ its(:health_check_port) { should eq 'traffic-port' }
8
+ its(:health_check_protocol) { should eq 'HTTP' }
9
+ end
10
+ ```
11
+
12
+ ### have_ec2
13
+
14
+ ```ruby
15
+ describe alb_target_group('my-alb-target-group') do
16
+ it { should have_ec2('my-ec2') }
17
+ end
18
+ ```
19
+
20
+ ### belong_to_alb
21
+
22
+ ```ruby
23
+ describe alb_target_group('my-alb-target-group') do
24
+ it { should belong_to_alb('my-alb') }
25
+ end
26
+ ```
27
+
28
+ ### belong_to_vpc
29
+
30
+ ```ruby
31
+ describe alb_target_group('my-alb-target-group') do
32
+ it { should belong_to_vpc('my-vpc') }
33
+ end
34
+ ```
35
+
@@ -3,6 +3,7 @@
3
3
  [acm](#acm)
4
4
  | [alb](#alb)
5
5
  | [alb_listener](#alb_listener)
6
+ | [alb_target_group](#alb_target_group)
6
7
  | [ami](#ami)
7
8
  | [autoscaling_group](#autoscaling_group)
8
9
  | [cloudfront_distribution](#cloudfront_distribution)
@@ -109,6 +110,15 @@ describe alb('my-alb') do
109
110
  end
110
111
  ```
111
112
 
113
+
114
+ ### belong_to_vpc
115
+
116
+ ```ruby
117
+ describe alb('my-alb') do
118
+ it { should belong_to_vpc('my-vpc') }
119
+ end
120
+ ```
121
+
112
122
  ### its(:load_balancer_arn), its(:dns_name), its(:canonical_hosted_zone_id), its(:created_time), its(:load_balancer_name), its(:scheme), its(:vpc_id), its(:type), its(:security_groups), its(:ip_address_type)
113
123
  ## <a name="alb_listener">alb_listener</a>
114
124
 
@@ -116,7 +126,70 @@ AlbListener resource type.
116
126
 
117
127
  ### exist
118
128
 
129
+ ```ruby
130
+ describe alb_listener('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2') do
131
+ it { should exist }
132
+ its(:port) { should eq 80 }
133
+ its(:protocol) { should eq 'HTTP' }
134
+ end
135
+ ```
136
+
137
+
138
+ ### have_rule
139
+
140
+ ```ruby
141
+ describe alb_listener('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2') do
142
+ it { should have_rule('arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener-rule/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2/9683b2d02a6cabee') }
143
+ it do
144
+ should have_rule.priority('10')
145
+ .conditions(field: 'path-pattern', values: ['/img/*'])
146
+ .actions(target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067', type: 'forward')
147
+ end
148
+ it do
149
+ should have_rule.priority('10')
150
+ .if(field: 'path-pattern', values: ['/img/*'])
151
+ .then(target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067', type: 'forward')
152
+ end
153
+ it { should have_rule.conditions([{ field: 'path-pattern', values: ['/admin/*'] }, { field: 'host-header', values: ['admin.example.com'] }]) }
154
+ it { should have_rule.actions(target_group_name: 'my-alb-target-group', type: 'forward') }
155
+ end
156
+ ```
157
+
119
158
  ### its(:listener_arn), its(:load_balancer_arn), its(:port), its(:protocol), its(:certificates), its(:ssl_policy)
159
+ ## <a name="alb_target_group">alb_target_group</a>
160
+
161
+ AlbTargetGroup resource type.
162
+
163
+ ### exist
164
+
165
+ ### have_ec2
166
+
167
+ ```ruby
168
+ describe alb_target_group('my-alb-target-group') do
169
+ it { should have_ec2('my-ec2') }
170
+ end
171
+ ```
172
+
173
+
174
+ ### belong_to_alb
175
+
176
+ ```ruby
177
+ describe alb_target_group('my-alb-target-group') do
178
+ it { should belong_to_alb('my-alb') }
179
+ end
180
+ ```
181
+
182
+
183
+ ### belong_to_vpc
184
+
185
+ ```ruby
186
+ describe alb_target_group('my-alb-target-group') do
187
+ it { should belong_to_vpc('my-vpc') }
188
+ end
189
+ ```
190
+
191
+
192
+ ### its(:target_group_arn), its(:target_group_name), its(:protocol), its(:port), its(:vpc_id), its(:health_check_protocol), its(:health_check_port), its(:health_check_interval_seconds), its(:health_check_timeout_seconds), its(:healthy_threshold_count), its(:unhealthy_threshold_count), its(:health_check_path), its(:load_balancer_arns)
120
193
  ## <a name="ami">ami</a>
121
194
 
122
195
  AMI resource type.
@@ -8,7 +8,8 @@ module Awspec::Generator
8
8
  @type = Awspec::Type::Alb.new('my-alb')
9
9
  @ret = @type.resource_via_client
10
10
  @matchers = [
11
- Awspec::Type::Alb::STATES.map { |state| 'be_' + state }.join(', ')
11
+ Awspec::Type::Alb::STATES.map { |state| 'be_' + state }.join(', '),
12
+ 'belong_to_vpc'
12
13
  ]
13
14
  @ignore_matchers = Awspec::Type::Alb::STATES.map { |state| 'be_' + state }
14
15
  @describes = []
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class AlbTargetGroup < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'AlbTargetGroup'
8
+ @type = Awspec::Type::AlbTargetGroup.new('my-alb-target-group')
9
+ @ret = @type.resource_via_client
10
+ @matchers = %w(belong_to_alb belong_to_vpc)
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -21,6 +21,24 @@ module Awspec::Helper
21
21
  rescue
22
22
  return nil
23
23
  end
24
+
25
+ def find_alb_target_group(id)
26
+ res = elbv2_client.describe_target_groups({ names: [id] })
27
+ res.target_groups.single_resource(id)
28
+ rescue
29
+ return nil
30
+ end
31
+
32
+ def select_rule_by_alb_listener_id(id)
33
+ selected = []
34
+ next_marker = nil
35
+ loop do
36
+ res = elbv2_client.describe_rules(marker: next_marker, listener_arn: id)
37
+ selected += res.rules unless res.nil?
38
+ (res.nil? && next_marker = res.next_marker) || break
39
+ end
40
+ selected
41
+ end
24
42
  end
25
43
  end
26
44
  end
@@ -15,7 +15,7 @@ module Awspec
15
15
  network_acl network_interface rds rds_db_cluster_parameter_group rds_db_parameter_group route53_hosted_zone
16
16
  route_table s3_bucket security_group ses_identity subnet vpc cloudfront_distribution
17
17
  elastictranscoder_pipeline waf_web_acl customer_gateway vpn_gateway vpn_connection internet_gateway acm
18
- cloudwatch_logs dynamodb_table eip sqs alb_listener
18
+ cloudwatch_logs dynamodb_table eip sqs alb_listener alb_target_group
19
19
  )
20
20
 
21
21
  ACCOUNT_ATTRIBUTES = %w(
@@ -45,7 +45,7 @@ require 'awspec/matcher/have_origin'
45
45
  # Kms
46
46
  require 'awspec/matcher/have_key_policy'
47
47
 
48
- # WafWebAcl
48
+ # WafWebAcl / AlbListener
49
49
  require 'awspec/matcher/have_rule'
50
50
 
51
51
  # CloudWatch Logs
@@ -57,3 +57,6 @@ require 'awspec/matcher/have_key_schema'
57
57
 
58
58
  # EIP
59
59
  require 'awspec/matcher/belong_to_domain'
60
+
61
+ # Alb Target Group
62
+ require 'awspec/matcher/belong_to_alb'
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :belong_to_alb do |alb_arn|
2
+ match do |type|
3
+ return true if type.load_balancer_arns.include?(alb_arn)
4
+ ret = type.find_alb(alb_arn)
5
+ return false unless ret
6
+ type.load_balancer_arns.include?(ret.load_balancer_arn)
7
+ end
8
+ end
@@ -1,6 +1,7 @@
1
1
  RSpec::Matchers.define :have_rule do |rule_id|
2
- match do |web_acl|
3
- web_acl.has_rule?(rule_id, @priority, @action)
2
+ match do |type|
3
+ return type.has_rule?(rule_id, @priority, @action) if type.instance_of?(Awspec::Type::WafWebAcl)
4
+ type.has_rule?(rule_id, @priority, @conditions, @actions) if type.instance_of?(Awspec::Type::AlbListener)
4
5
  end
5
6
 
6
7
  chain :priority do |priority|
@@ -14,4 +15,20 @@ RSpec::Matchers.define :have_rule do |rule_id|
14
15
  chain :action do |action|
15
16
  @action = action
16
17
  end
18
+
19
+ chain :conditions do |conditions|
20
+ @conditions = conditions
21
+ end
22
+
23
+ chain :actions do |actions|
24
+ @actions = actions
25
+ end
26
+
27
+ chain :if do |conditions|
28
+ @conditions = conditions
29
+ end
30
+
31
+ chain :then do |actions|
32
+ @actions = actions
33
+ end
17
34
  end
@@ -51,6 +51,91 @@ Aws.config[:elasticloadbalancingv2] = {
51
51
  protocol: 'HTTP'
52
52
  }
53
53
  ]
54
+ },
55
+ describe_target_groups: {
56
+ target_groups: [
57
+ {
58
+ health_check_interval_seconds: 30,
59
+ health_check_path: '/',
60
+ health_check_port: 'traffic-port',
61
+ health_check_protocol: 'HTTP',
62
+ health_check_timeout_seconds: 5,
63
+ healthy_threshold_count: 5,
64
+ load_balancer_arns: [
65
+ 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:loadbalancer/app/my-alb/1aa1bb1cc1ddee11'
66
+ ],
67
+ matcher: {
68
+ http_code: '200'
69
+ },
70
+ port: 80,
71
+ protocol: 'HTTP',
72
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067',
73
+ target_group_name: 'my-alb-target-group',
74
+ unhealthy_threshold_count: 2,
75
+ vpc_id: 'vpc-ab123cde'
76
+ }
77
+ ]
78
+ },
79
+ describe_rules: {
80
+ rules: [
81
+ {
82
+ actions: [
83
+ {
84
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/55556bc24d8a067/55556bc24d8a067',
85
+ type: 'forward'
86
+ }
87
+ ],
88
+ conditions: [
89
+ {
90
+ field: 'host-header',
91
+ values: [
92
+ 'admin.example.com'
93
+ ]
94
+ },
95
+ {
96
+ field: 'path-pattern',
97
+ values: [
98
+ '/admin/*'
99
+ ]
100
+ }
101
+ ],
102
+ is_default: false,
103
+ priority: '50',
104
+ rule_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener-rule/app/my-alb/1aa1bb1cc1ddee11/7777778efc522ab2/7777778efc522ab2'
105
+ },
106
+ {
107
+ actions: [
108
+ {
109
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067',
110
+ type: 'forward'
111
+ }
112
+ ],
113
+ conditions: [
114
+ {
115
+ field: 'path-pattern',
116
+ values: [
117
+ '/img/*'
118
+ ]
119
+ }
120
+ ],
121
+ is_default: false,
122
+ priority: '10',
123
+ rule_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener-rule/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2/9683b2d02a6cabee'
124
+ },
125
+ {
126
+ actions: [
127
+ {
128
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:targetgroup/my-targets/73e2d6bc24d8a067',
129
+ type: 'forward'
130
+ }
131
+ ],
132
+ conditions: [
133
+ ],
134
+ is_default: true,
135
+ priority: 'default',
136
+ rule_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener-rule/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2/defaaaaaaaultbbbb'
137
+ }
138
+ ]
54
139
  }
55
140
  }
56
141
  }
@@ -0,0 +1,325 @@
1
+ # rubocop:disable Metrics/LineLength
2
+ Aws.config[:elasticloadbalancingv2] = {
3
+ stub_responses: {
4
+ describe_load_balancers: {
5
+ load_balancers: [
6
+ {
7
+ load_balancer_arn:
8
+ 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:loadbalancer/app/my-alb/1aa1bb1cc1ddee11',
9
+ dns_name:
10
+ 'internal-my-elb-1551266724.ap-northeast-1.elb.amazonaws.com',
11
+ canonical_hosted_zone_id: 'A12BCDEDCBA34BC',
12
+ created_time: Time.new(2017, 4, 4, 9, 00, 00, '+00:00'),
13
+ load_balancer_name: 'my-alb',
14
+ scheme: 'internal',
15
+ vpc_id: 'vpc-ab123cde',
16
+ state:
17
+ {
18
+ code: 'active',
19
+ reason: nil
20
+ },
21
+ type: 'application',
22
+ availability_zones:
23
+ [
24
+ {
25
+ zone_name: 'ap-northeast-1a',
26
+ subnet_id: 'subnet-1234a567'
27
+ },
28
+ {
29
+ zone_name: 'ap-northeast-1c',
30
+ subnet_id: 'subnet-abcd7890'
31
+ }
32
+ ],
33
+ security_groups: ['sg-1a2b3cd4'],
34
+ ip_address_type: 'ipv4'
35
+ }
36
+ ],
37
+ next_marker: nil
38
+ },
39
+ describe_listeners: {
40
+ listeners: [
41
+ {
42
+ default_actions: [
43
+ {
44
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:targetgroup/my-targets/73e2d6bc24d8a067',
45
+ type: 'forward'
46
+ }
47
+ ],
48
+ listener_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:listener/app/my-alb/1aa1bb1cc1ddee11/f2f7dc8efc522ab2',
49
+ load_balancer_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:loadbalancer/app/my-alb/1aa1bb1cc1ddee11',
50
+ port: 80,
51
+ protocol: 'HTTP'
52
+ }
53
+ ]
54
+ },
55
+ describe_target_groups: {
56
+ target_groups: [
57
+ {
58
+ health_check_interval_seconds: 30,
59
+ health_check_path: '/',
60
+ health_check_port: 'traffic-port',
61
+ health_check_protocol: 'HTTP',
62
+ health_check_timeout_seconds: 5,
63
+ healthy_threshold_count: 5,
64
+ load_balancer_arns: [
65
+ 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:loadbalancer/app/my-alb/1aa1bb1cc1ddee11'
66
+ ],
67
+ matcher: {
68
+ http_code: '200'
69
+ },
70
+ port: 80,
71
+ protocol: 'HTTP',
72
+ target_group_arn: 'arn:aws:elasticloadbalancing:ap-northeast-1:1234567890:123456789012:targetgroup/73e2d6bc24d8a067/73e2d6bc24d8a067',
73
+ target_group_name: 'my-alb-target-group',
74
+ unhealthy_threshold_count: 2,
75
+ vpc_id: 'vpc-ab123cde'
76
+ }
77
+ ]
78
+ },
79
+ describe_target_health: {
80
+ target_health_descriptions: [
81
+ {
82
+ target: {
83
+ id: 'i-0f76fade',
84
+ port: 80
85
+ },
86
+ target_health: {
87
+ description: 'Given target group is not configured to receive traffic from ELB',
88
+ reason: 'Target.NotInUse',
89
+ state: 'unused'
90
+ }
91
+ },
92
+ {
93
+ health_check_port: '80',
94
+ target: {
95
+ id: 'i-ec12345a',
96
+ port: 80
97
+ },
98
+ target_health: {
99
+ state: 'healthy'
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ }
105
+ }
106
+
107
+ Aws.config[:ec2] = {
108
+ stub_responses: {
109
+ describe_instances: {
110
+ reservations: [
111
+ {
112
+ instances: [
113
+ {
114
+ instance_id: 'i-ec12345a',
115
+ image_id: 'ami-abc12def',
116
+ vpc_id: 'vpc-ab123cde',
117
+ subnet_id: 'subnet-1234a567',
118
+ public_ip_address: '123.0.456.789',
119
+ private_ip_address: '10.0.1.1',
120
+ instance_type: 't2.small',
121
+ state: {
122
+ name: 'running'
123
+ },
124
+ security_groups: [
125
+ {
126
+ group_id: 'sg-1a2b3cd4',
127
+ group_name: 'my-security-group-name'
128
+ }
129
+ ],
130
+ iam_instance_profile: {
131
+ arn: 'arn:aws:iam::123456789012:instance-profile/Ec2IamProfileName',
132
+ id: 'ABCDEFGHIJKLMNOPQRSTU'
133
+ },
134
+ block_device_mappings: [
135
+ {
136
+ device_name: '/dev/sda',
137
+ ebs: {
138
+ volume_id: 'vol-123a123b'
139
+ }
140
+ }
141
+ ],
142
+ network_interfaces: [
143
+ {
144
+ network_interface_id: 'eni-12ab3cde',
145
+ subnet_id: 'subnet-1234a567',
146
+ vpc_id: 'vpc-ab123cde',
147
+ attachment: {
148
+ device_index: 1
149
+ }
150
+ }
151
+ ],
152
+ tags: [
153
+ {
154
+ key: 'Name',
155
+ value: 'my-ec2'
156
+ }
157
+ ]
158
+ }
159
+ ]
160
+ }
161
+ ]
162
+ },
163
+ describe_security_groups: {
164
+ security_groups: [
165
+ {
166
+ vpc_id: 'vpc-ab123cde',
167
+ owner_id: '112233445566',
168
+ group_id: 'sg-1a2b3cd4',
169
+ group_name: 'my-security-group-name',
170
+ tags: [
171
+ {
172
+ key: 'env',
173
+ value: 'dev'
174
+ }
175
+ ],
176
+ ip_permissions: [
177
+ {
178
+ from_port: 80,
179
+ to_port: 80,
180
+ ip_protocol: 'tcp',
181
+ ip_ranges: [
182
+ {
183
+ cidr_ip: '123.456.789.012/32'
184
+ },
185
+ {
186
+ cidr_ip: '456.789.123.456/32'
187
+ }
188
+ ],
189
+ user_id_group_pairs: []
190
+ },
191
+ {
192
+ from_port: 22,
193
+ to_port: 22,
194
+ ip_protocol: 'tcp',
195
+ ip_ranges: [],
196
+ user_id_group_pairs: [
197
+ {
198
+ group_id: 'sg-5a6b7cd8',
199
+ group_name: 'group-name-sg'
200
+ }
201
+ ]
202
+ },
203
+ {
204
+ from_port: 60_000,
205
+ to_port: 60_000,
206
+ ip_protocol: 'tcp',
207
+ ip_ranges: [
208
+ {
209
+ cidr_ip: '100.456.789.012/32'
210
+ }
211
+ ],
212
+ user_id_group_pairs: []
213
+ },
214
+ {
215
+ from_port: 70_000,
216
+ to_port: 70_000,
217
+ ip_protocol: 'tcp',
218
+ ip_ranges: [
219
+ {
220
+ cidr_ip: '100.456.789.012/32'
221
+ }
222
+ ],
223
+ user_id_group_pairs: []
224
+ },
225
+ {
226
+ from_port: 70_000,
227
+ to_port: 70_000,
228
+ ip_protocol: 'tcp',
229
+ ip_ranges: [
230
+ {
231
+ cidr_ip: '101.456.789.012/32'
232
+ }
233
+ ],
234
+ user_id_group_pairs: []
235
+ },
236
+ {
237
+ from_port: 50_000,
238
+ to_port: 50_009,
239
+ ip_protocol: 'tcp',
240
+ ip_ranges: [
241
+ {
242
+ cidr_ip: '123.456.789.012/32'
243
+ }
244
+ ],
245
+ user_id_group_pairs: []
246
+ },
247
+ {
248
+ from_port: nil,
249
+ to_port: nil,
250
+ ip_protocol: '-1',
251
+ ip_ranges: [],
252
+ user_id_group_pairs: [
253
+ {
254
+ user_id: '1234567890',
255
+ group_name: nil,
256
+ group_id: 'sg-3a4b5cd6',
257
+ vpc_id: nil,
258
+ vpc_peering_connection_id: nil,
259
+ peering_status: nil
260
+ }
261
+ ]
262
+ }
263
+ ],
264
+ ip_permissions_egress: [
265
+ {
266
+ from_port: 50_000,
267
+ to_port: 50_000,
268
+ ip_protocol: 'tcp',
269
+ ip_ranges: [
270
+ {
271
+ cidr_ip: '100.456.789.012/32'
272
+ }
273
+ ]
274
+ },
275
+ {
276
+ from_port: 8080,
277
+ to_port: 8080,
278
+ ip_protocol: 'tcp',
279
+ ip_ranges: [],
280
+ user_id_group_pairs: [
281
+ {
282
+ user_id: '5678901234',
283
+ group_name: 'group-in-other-aws-account-with-vpc-peering',
284
+ group_id: 'sg-9a8b7c6d',
285
+ vpc_id: 'vpc-5b6a7c8f',
286
+ vpc_peering_connection_id: 'pcx-f9e8d7c6',
287
+ peering_status: 'active'
288
+ }
289
+ ]
290
+ }
291
+ ]
292
+ }
293
+ ]
294
+ },
295
+ describe_subnets: {
296
+ subnets: [
297
+ {
298
+ state: 'available',
299
+ vpc_id: 'vpc-ab123cde',
300
+ subnet_id: 'subnet-1234a567',
301
+ cidr_block: '10.0.1.0/24',
302
+ tags: [
303
+ {
304
+ key: 'Name',
305
+ value: 'my-subnet'
306
+ }
307
+ ]
308
+ }
309
+ ]
310
+ },
311
+ describe_vpcs: {
312
+ vpcs: [
313
+ {
314
+ vpc_id: 'vpc-ab123cde',
315
+ tags: [
316
+ {
317
+ key: 'Name',
318
+ value: 'my-vpc'
319
+ }
320
+ ]
321
+ }
322
+ ]
323
+ }
324
+ }
325
+ }
@@ -7,5 +7,30 @@ module Awspec::Type
7
7
  def id
8
8
  @id ||= resource_via_client.listener_arn if resource_via_client
9
9
  end
10
+
11
+ def has_rule?(rule_id = nil, priority = nil, conditions = nil, actions = nil)
12
+ rules = select_rule_by_alb_listener_id(id)
13
+ ret = rules.select do |rule|
14
+ conditions = [conditions] if conditions.is_a?(Hash)
15
+ actions = [actions] if actions.is_a?(Hash)
16
+ next false if !rule_id.nil? && rule.rule_arn != rule_id
17
+ next false if !priority.nil? && rule.priority != priority
18
+ next false if !conditions.nil? && rule.conditions.map(&:to_h).sort_by(&:to_s) != conditions.sort_by(&:to_s)
19
+ unless actions.nil?
20
+ actions = actions.map do |action|
21
+ if action.key?(:target_group_name)
22
+ target_group = find_alb_target_group(action[:target_group_name])
23
+ action[:target_group_arn] = target_group.target_group_arn
24
+ action.delete(:target_group_name)
25
+ end
26
+ action
27
+ end
28
+ next false if rule.actions.map(&:to_h).sort_by(&:to_s) != actions.sort_by(&:to_s)
29
+ end
30
+ true
31
+ end
32
+ ret.single_resource("rule_id = #{rule_id}, priority = #{priority}, \
33
+ conditions = #{conditions}, actions = #{actions}")
34
+ end
10
35
  end
11
36
  end
@@ -0,0 +1,22 @@
1
+ module Awspec::Type
2
+ class AlbTargetGroup < ResourceBase
3
+ def resource_via_client
4
+ @resource_via_client ||= find_alb_target_group(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.target_group_name if resource_via_client
9
+ end
10
+
11
+ def has_ec2?(id)
12
+ ec2 = find_ec2(id)
13
+ return nil unless ec2
14
+ descriptions = elbv2_client.describe_target_health(
15
+ target_group_arn: resource_via_client.target_group_arn
16
+ ).target_health_descriptions
17
+ descriptions.find do |description|
18
+ description.target.id == ec2.instance_id
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.83.0'
2
+ VERSION = '0.84.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.83.0
4
+ version: 0.84.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -209,6 +209,7 @@ files:
209
209
  - doc/_resource_types/acm.md
210
210
  - doc/_resource_types/alb.md
211
211
  - doc/_resource_types/alb_listener.md
212
+ - doc/_resource_types/alb_target_group.md
212
213
  - doc/_resource_types/ami.md
213
214
  - doc/_resource_types/autoscaling_group.md
214
215
  - doc/_resource_types/cloudfront_distribution.md
@@ -279,6 +280,7 @@ files:
279
280
  - lib/awspec/generator/doc/type/acm.rb
280
281
  - lib/awspec/generator/doc/type/alb.rb
281
282
  - lib/awspec/generator/doc/type/alb_listener.rb
283
+ - lib/awspec/generator/doc/type/alb_target_group.rb
282
284
  - lib/awspec/generator/doc/type/ami.rb
283
285
  - lib/awspec/generator/doc/type/autoscaling_group.rb
284
286
  - lib/awspec/generator/doc/type/base.rb
@@ -407,6 +409,7 @@ files:
407
409
  - lib/awspec/matcher/be_denied.rb
408
410
  - lib/awspec/matcher/be_opened.rb
409
411
  - lib/awspec/matcher/be_opened_only.rb
412
+ - lib/awspec/matcher/belong_to_alb.rb
410
413
  - lib/awspec/matcher/belong_to_cache_subnet_group.rb
411
414
  - lib/awspec/matcher/belong_to_db_subnet_group.rb
412
415
  - lib/awspec/matcher/belong_to_domain.rb
@@ -435,6 +438,7 @@ files:
435
438
  - lib/awspec/stub/acm.rb
436
439
  - lib/awspec/stub/alb.rb
437
440
  - lib/awspec/stub/alb_listener.rb
441
+ - lib/awspec/stub/alb_target_group.rb
438
442
  - lib/awspec/stub/ami.rb
439
443
  - lib/awspec/stub/autoscaling_group.rb
440
444
  - lib/awspec/stub/cloudfront_distribution.rb
@@ -494,6 +498,7 @@ files:
494
498
  - lib/awspec/type/acm.rb
495
499
  - lib/awspec/type/alb.rb
496
500
  - lib/awspec/type/alb_listener.rb
501
+ - lib/awspec/type/alb_target_group.rb
497
502
  - lib/awspec/type/ami.rb
498
503
  - lib/awspec/type/autoscaling_group.rb
499
504
  - lib/awspec/type/base.rb