Skip to content

Commit ee26a0e

Browse files
authored
Merge pull request #600 from alpineriveredge/add-wafv2-web-acl
Add wafv2_web_acl resource
2 parents b75adca + df66fa7 commit ee26a0e

File tree

18 files changed

+410
-17
lines changed

18 files changed

+410
-17
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Lint/DuplicateMethods:
2121
- 'lib/awspec/type/eks_nodegroup.rb'
2222
- 'lib/awspec/type/resource_base.rb'
2323
- 'lib/awspec/type/wafv2_ip_set.rb'
24+
- 'lib/awspec/type/wafv2_web_acl.rb'
2425

2526
Lint/ErbNewArguments:
2627
Enabled: false

doc/_resource_types/wafv2_ip_set.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
You can set `scope` to CLOUDFRONT or REGIONAL ( default: `REGIONAL` ).
44

55
```ruby
6-
describe wafv2_ip_set('my-ip-set'), scope: 'REGIONAL' do
6+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'REGIONAL' do
7+
it { should exist }
8+
end
9+
10+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'CLOUDFRONT', region: 'us-east-1' do
711
it { should exist }
812
end
913
```
1014

1115
### have_ip_address
1216

1317
```ruby
14-
describe wafv2_ip_set('my-ip-set'), scope: 'REGIONAL' do
18+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'REGIONAL' do
1519
it { should have_ip_address('10.0.0.0/32') }
1620
end
1721
```

doc/_resource_types/wafv2_web_acl.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### exist
2+
3+
You can set `scope` to CLOUDFRONT or REGIONAL ( default: `REGIONAL` ).
4+
5+
```ruby
6+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'REGIONAL' do
7+
it { should exist }
8+
its(:default_action) { should eq 'ALLOW' }
9+
end
10+
11+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'CLOUDFRONT', region: 'us-east-1' do
12+
it { should exist }
13+
its(:default_action) { should eq 'ALLOW' }
14+
end
15+
```
16+
17+
### have_rule
18+
19+
```ruby
20+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'REGIONAL' do
21+
it { should have_rule('AWS-AWSManagedRulesCommonRuleSet') }
22+
it { should have_rule('AWS-AWSManagedRulesKnownBadInputsRuleSet').order(1) }
23+
it { should have_rule('AWS-AWSManagedRulesLinuxRuleSet').order(2).override_action('NONE') }
24+
end
25+
```

doc/resource_types.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
| [waf_web_acl](#waf_web_acl)
9191
| [wafregional_web_acl](#wafregional_web_acl)
9292
| [wafv2_ip_set](#wafv2_ip_set)
93+
| [wafv2_web_acl](#wafv2_web_acl)
9394
| [account](#account)
9495

9596
## <a name="acm">acm</a>
@@ -4310,7 +4311,11 @@ Wafv2IpSet resource type.
43104311
You can set `scope` to CLOUDFRONT or REGIONAL ( default: `REGIONAL` ).
43114312

43124313
```ruby
4313-
describe wafv2_ip_set('my-ip-set'), scope: 'REGIONAL' do
4314+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'REGIONAL' do
4315+
it { should exist }
4316+
end
4317+
4318+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'CLOUDFRONT', region: 'us-east-1' do
43144319
it { should exist }
43154320
end
43164321
```
@@ -4319,12 +4324,44 @@ end
43194324
### have_ip_address
43204325

43214326
```ruby
4322-
describe wafv2_ip_set('my-ip-set'), scope: 'REGIONAL' do
4327+
describe wafv2_ip_set('my-wafv2-ip-set'), scope: 'REGIONAL' do
43234328
it { should have_ip_address('10.0.0.0/32') }
43244329
end
43254330
```
43264331

43274332
### its(:name), its(:id), its(:arn), its(:description), its(:ip_address_version), its(:addresses)
4333+
## <a name="wafv2_web_acl">wafv2_web_acl</a>
4334+
4335+
Wafv2WebAcl resource type.
4336+
4337+
### exist
4338+
4339+
You can set `scope` to CLOUDFRONT or REGIONAL ( default: `REGIONAL` ).
4340+
4341+
```ruby
4342+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'REGIONAL' do
4343+
it { should exist }
4344+
its(:default_action) { should eq 'ALLOW' }
4345+
end
4346+
4347+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'CLOUDFRONT', region: 'us-east-1' do
4348+
it { should exist }
4349+
its(:default_action) { should eq 'ALLOW' }
4350+
end
4351+
```
4352+
4353+
4354+
### have_rule
4355+
4356+
```ruby
4357+
describe wafv2_web_acl('my-wafv2-web-acl'), scope: 'REGIONAL' do
4358+
it { should have_rule('AWS-AWSManagedRulesCommonRuleSet') }
4359+
it { should have_rule('AWS-AWSManagedRulesKnownBadInputsRuleSet').order(1) }
4360+
it { should have_rule('AWS-AWSManagedRulesLinuxRuleSet').order(2).override_action('NONE') }
4361+
end
4362+
```
4363+
4364+
### its(:name), its(:id), its(:arn), its(:description), its(:data_protection_config), its(:capacity), its(:pre_process_firewall_manager_rule_groups), its(:post_process_firewall_manager_rule_groups), its(:managed_by_firewall_manager), its(:label_namespace), its(:custom_response_bodies), its(:captcha_config), its(:challenge_config), its(:token_domains), its(:association_config), its(:retrofitted_by_firewall_manager)
43284365
# Account and Attributes
43294366

43304367
## <a name="account">account</a>

lib/awspec/generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
require 'awspec/generator/spec/managed_prefix_list'
4747
require 'awspec/generator/spec/codepipeline'
4848
require 'awspec/generator/spec/wafv2_ip_set'
49+
require 'awspec/generator/spec/wafv2_web_acl'
4950

5051
# Doc
5152
require 'awspec/generator/doc/type'

lib/awspec/generator/doc/type/wafv2_ip_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Wafv2IpSet < Base
77
def initialize
88
super
99
@type_name = 'Wafv2IpSet'
10-
@type = Awspec::Type::Wafv2IpSet.new('my-ip-set')
10+
@type = Awspec::Type::Wafv2IpSet.new('my-wafv2-ip-set')
1111
@ret = @type.resource_via_client
1212
@matchers = []
1313
@ignore_matchers = []
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Awspec::Generator
4+
module Doc
5+
module Type
6+
class Wafv2WebAcl < Base
7+
def initialize
8+
super
9+
@type_name = 'Wafv2WebAcl'
10+
@type = Awspec::Type::Wafv2WebAcl.new('my-wafv2-web-acl')
11+
@ret = @type.resource_via_client
12+
@matchers = []
13+
@ignore_matchers = []
14+
@describes = []
15+
end
16+
end
17+
end
18+
end
19+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
module Awspec::Generator
4+
module Spec
5+
class Wafv2WebAcl
6+
include Awspec::Helper::Finder
7+
def generate_by_scope(scope)
8+
web_acls = select_all_web_acls(scope)
9+
raise 'Not Found WAFV2 Web ACL' if web_acls.empty?
10+
11+
specs = web_acls.map do |acl|
12+
web_acl = get_web_acl(scope, acl.name, acl.id)
13+
ERB.new(wafv2_web_acl_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
14+
end
15+
specs.join("\n")
16+
end
17+
18+
def wafv2_web_acl_spec_template
19+
<<-'EOF'
20+
describe wafv2_web_acl('<%= web_acl.name %>'), scope: '<%= scope %>' do
21+
it { should exist }
22+
its(:name) { should eq '<%= web_acl.name %>' }
23+
its(:id) { should eq '<%= web_acl.id %>' }
24+
its(:arn) { should eq '<%= web_acl.arn %>' }
25+
its(:default_action) { should eq '<%= web_acl.default_action.allow ? 'ALLOW' : 'BLOCK' %>' }
26+
its(:description) { should eq '<%= web_acl.description %>' }
27+
its(:capacity) { should eq <%= web_acl.capacity %> }
28+
its(:managed_by_firewall_manager) { should eq <%= web_acl.managed_by_firewall_manager %> }
29+
its(:label_namespace) { should eq '<%= web_acl.label_namespace %>' }
30+
its(:retrofitted_by_firewall_manager) { should eq <%= web_acl.retrofitted_by_firewall_manager %> }
31+
<% web_acl.rules.each do |rule| %>
32+
it { should have_rule('<%= rule.name %>').order(<%= rule.priority %>) }
33+
<% end %>
34+
end
35+
EOF
36+
end
37+
end
38+
end
39+
end

lib/awspec/helper/finder/wafv2.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ def get_ip_set(scope, name, id)
2222
res = wafv2_client.get_ip_set({ name: name, scope: scope, id: id })
2323
res.ip_set
2424
end
25+
26+
def find_web_acl(scope, name)
27+
web_acls = select_all_web_acls(scope)
28+
web_acl = web_acls.find do |acl|
29+
acl.name == name
30+
end
31+
return false unless web_acl
32+
33+
get_web_acl(scope, name, web_acl.id)
34+
end
35+
36+
def select_all_web_acls(scope)
37+
res = wafv2_client.list_web_acls({ scope: scope })
38+
res.web_acls
39+
end
40+
41+
def get_web_acl(scope, name, id)
42+
res = wafv2_client.get_web_acl({ name: name, scope: scope, id: id })
43+
res.web_acl
44+
end
2545
end
2646
end
2747
end

lib/awspec/helper/type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Type
2424
internet_gateway acm cloudwatch_logs dynamodb_table eip sqs ssm_parameter cloudformation_stack
2525
codebuild sns_topic redshift redshift_cluster_parameter_group codedeploy codedeploy_deployment_group
2626
secretsmanager msk transit_gateway cognito_identity_pool cognito_user_pool vpc_endpoints
27-
transfer_server managed_prefix_list codepipeline wafv2_ip_set
27+
transfer_server managed_prefix_list codepipeline wafv2_ip_set wafv2_web_acl
2828
]
2929

3030
ACCOUNT_ATTRIBUTES = %w[

0 commit comments

Comments
 (0)