awspec 1.13.0 → 1.14.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 +5 -5
- data/doc/_resource_types/redshift.md +61 -0
- data/doc/_resource_types/redshift_cluster_parameter_group.md +17 -0
- data/doc/resource_types.md +97 -0
- data/lib/awspec/command/generate.rb +2 -2
- data/lib/awspec/error.rb +22 -0
- data/lib/awspec/generator.rb +2 -0
- data/lib/awspec/generator/doc/type/redshift.rb +21 -0
- data/lib/awspec/generator/doc/type/redshift_cluster_parameter_group.rb +17 -0
- data/lib/awspec/generator/spec/kms.rb +10 -2
- data/lib/awspec/generator/spec/redshift.rb +65 -0
- data/lib/awspec/generator/spec/redshift_cluster_parameter_group.rb +23 -0
- data/lib/awspec/helper/finder.rb +4 -1
- data/lib/awspec/helper/finder/redshift.rb +33 -0
- data/lib/awspec/helper/type.rb +2 -1
- data/lib/awspec/matcher.rb +4 -0
- data/lib/awspec/matcher/belong_to_cluster_subnet_group.rb +5 -0
- data/lib/awspec/matcher/have_cluster_parameter_group.rb +9 -0
- data/lib/awspec/resource_reader.rb +1 -0
- data/lib/awspec/stub/kms.rb +4 -0
- data/lib/awspec/stub/redshift.rb +67 -0
- data/lib/awspec/stub/redshift_cluster_parameter_group.rb +20 -0
- data/lib/awspec/type/base.rb +4 -0
- data/lib/awspec/type/iam_policy.rb +12 -0
- data/lib/awspec/type/redshift.rb +88 -0
- data/lib/awspec/type/redshift_cluster_parameter_group.rb +20 -0
- data/lib/awspec/version.rb +1 -1
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '02079c9922dca56746510acc4b39754b272ac5a4'
|
4
|
+
data.tar.gz: 74e3e1c789724abfafd496dbabbfb351d1cb2f42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3657fdcfd445899ba09db82190e34290e0263100358cb77ad3c520a339f425cda0ab6ff745bf7cf96405ce18a4586d89ab6ae339290e1fe8c744ff28868aff11
|
7
|
+
data.tar.gz: eb5233b347173d62d76b8a0d2492983f5b764ee7d970c612f4a49fea8234b61dd7cf50f006a2de05767b9cd387f7b084d273aed548d68c02610089c1176c282f
|
@@ -0,0 +1,61 @@
|
|
1
|
+
### exist
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
describe redshift('my-redshift') do
|
5
|
+
it { should exist }
|
6
|
+
end
|
7
|
+
```
|
8
|
+
|
9
|
+
### be_available, be_cancelling_resize, be_creating, be_deleting, be_final_snapshot, be_hardware_failure, be_incompatible_hsm, be_incompatible_network, be_incompatible_parameters, be_incompatible_restore, be_modifying, be_rebooting, be_renaming, be_resizing, be_rotating_keys, be_storage_full, be_updating_hsm
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
describe redshift('my-redshift') do
|
13
|
+
it { should be_available }
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
### have_cluster_parameter_group
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
describe redshift('my-redshift') do
|
21
|
+
it { should have_cluster_parameter_group('my-pg') }
|
22
|
+
it do
|
23
|
+
should have_cluster_parameter_group('my-pg')\
|
24
|
+
.parameter_apply_status('in-sync')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
### have_security_group
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
describe redshift('my-redshift') do
|
33
|
+
it { should have_security_group('sg-1a2b3c4d') }
|
34
|
+
it { should have_security_group('group-name-sg') }
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### have_tag
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
describe redshift('my-redshift') do
|
42
|
+
it { should have_tag('Name').value('my-cluster') }
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### belong_to_cluster_subnet_group
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
describe redshift('my-redshift') do
|
50
|
+
it { should belong_to_cluster_subnet_group('my-sg') }
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### belong_to_vpc
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
describe redshift('my-redshift') do
|
58
|
+
it { should belong_to_vpc('vpc-ab123cde') }
|
59
|
+
it { should belong_to_vpc('my-vpc') }
|
60
|
+
end
|
61
|
+
```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
### first
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
describe redshift_cluster_parameter_group('my-redshift-cluster-parameter-group') do
|
5
|
+
its(:datestyle) { should eq 'ISO, MDY' }
|
6
|
+
its(:query_group) { should eq 'default' }
|
7
|
+
its(:require_ssl) { should eq 'false' }
|
8
|
+
end
|
9
|
+
```
|
10
|
+
|
11
|
+
### exist
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
describe redshift_cluster_parameter_group('my-redshift-cluster-parameter-group') do
|
15
|
+
it { should exist }
|
16
|
+
end
|
17
|
+
```
|
data/doc/resource_types.md
CHANGED
@@ -56,6 +56,8 @@
|
|
56
56
|
| [rds](#rds)
|
57
57
|
| [rds_db_cluster_parameter_group](#rds_db_cluster_parameter_group)
|
58
58
|
| [rds_db_parameter_group](#rds_db_parameter_group)
|
59
|
+
| [redshift](#redshift)
|
60
|
+
| [redshift_cluster_parameter_group](#redshift_cluster_parameter_group)
|
59
61
|
| [route53_hosted_zone](#route53_hosted_zone)
|
60
62
|
| [route_table](#route_table)
|
61
63
|
| [s3_bucket](#s3_bucket)
|
@@ -2578,6 +2580,101 @@ end
|
|
2578
2580
|
```
|
2579
2581
|
|
2580
2582
|
|
2583
|
+
## <a name="redshift">redshift</a>
|
2584
|
+
|
2585
|
+
Redshift resource type.
|
2586
|
+
|
2587
|
+
### exist
|
2588
|
+
|
2589
|
+
```ruby
|
2590
|
+
describe redshift('my-redshift') do
|
2591
|
+
it { should exist }
|
2592
|
+
end
|
2593
|
+
```
|
2594
|
+
|
2595
|
+
|
2596
|
+
### be_available, be_cancelling_resize, be_creating, be_deleting, be_final_snapshot, be_hardware_failure, be_incompatible_hsm, be_incompatible_network, be_incompatible_parameters, be_incompatible_restore, be_modifying, be_rebooting, be_renaming, be_resizing, be_rotating_keys, be_storage_full, be_updating_hsm
|
2597
|
+
|
2598
|
+
```ruby
|
2599
|
+
describe redshift('my-redshift') do
|
2600
|
+
it { should be_available }
|
2601
|
+
end
|
2602
|
+
```
|
2603
|
+
|
2604
|
+
|
2605
|
+
### have_cluster_parameter_group
|
2606
|
+
|
2607
|
+
```ruby
|
2608
|
+
describe redshift('my-redshift') do
|
2609
|
+
it { should have_cluster_parameter_group('my-pg') }
|
2610
|
+
it do
|
2611
|
+
should have_cluster_parameter_group('my-pg')\
|
2612
|
+
.parameter_apply_status('in-sync')
|
2613
|
+
end
|
2614
|
+
end
|
2615
|
+
```
|
2616
|
+
|
2617
|
+
|
2618
|
+
### have_security_group
|
2619
|
+
|
2620
|
+
```ruby
|
2621
|
+
describe redshift('my-redshift') do
|
2622
|
+
it { should have_security_group('sg-1a2b3c4d') }
|
2623
|
+
it { should have_security_group('group-name-sg') }
|
2624
|
+
end
|
2625
|
+
```
|
2626
|
+
|
2627
|
+
|
2628
|
+
### have_tag
|
2629
|
+
|
2630
|
+
```ruby
|
2631
|
+
describe redshift('my-redshift') do
|
2632
|
+
it { should have_tag('Name').value('my-cluster') }
|
2633
|
+
end
|
2634
|
+
```
|
2635
|
+
|
2636
|
+
|
2637
|
+
### belong_to_cluster_subnet_group
|
2638
|
+
|
2639
|
+
```ruby
|
2640
|
+
describe redshift('my-redshift') do
|
2641
|
+
it { should belong_to_cluster_subnet_group('my-sg') }
|
2642
|
+
end
|
2643
|
+
```
|
2644
|
+
|
2645
|
+
|
2646
|
+
### belong_to_vpc
|
2647
|
+
|
2648
|
+
```ruby
|
2649
|
+
describe redshift('my-redshift') do
|
2650
|
+
it { should belong_to_vpc('vpc-ab123cde') }
|
2651
|
+
it { should belong_to_vpc('my-vpc') }
|
2652
|
+
end
|
2653
|
+
```
|
2654
|
+
|
2655
|
+
### its(:vpc_id), its(:cluster_identifier), its(:node_type), its(:cluster_status), its(:modify_status), its(:master_username), its(:db_name), its(:endpoint), its(:cluster_create_time), its(:automated_snapshot_retention_period), its(:manual_snapshot_retention_period), its(:cluster_security_groups), its(:cluster_subnet_group_name), its(:vpc_id), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:cluster_version), its(:allow_version_upgrade), its(:number_of_nodes), its(:publicly_accessible), its(:encrypted), its(:restore_status), its(:data_transfer_progress), its(:hsm_status), its(:cluster_snapshot_copy_status), its(:cluster_public_key), its(:cluster_nodes), its(:elastic_ip_status), its(:cluster_revision_number), its(:kms_key_id), its(:enhanced_vpc_routing), its(:iam_roles), its(:pending_actions), its(:maintenance_track_name), its(:elastic_resize_number_of_node_options), its(:deferred_maintenance_windows), its(:snapshot_schedule_identifier), its(:snapshot_schedule_state), its(:resize_info)
|
2656
|
+
## <a name="redshift_cluster_parameter_group">redshift_cluster_parameter_group</a>
|
2657
|
+
|
2658
|
+
RedshiftClusterParameterGroup resource type.
|
2659
|
+
|
2660
|
+
```ruby
|
2661
|
+
describe redshift_cluster_parameter_group('my-redshift-cluster-parameter-group') do
|
2662
|
+
its(:datestyle) { should eq 'ISO, MDY' }
|
2663
|
+
its(:query_group) { should eq 'default' }
|
2664
|
+
its(:require_ssl) { should eq 'false' }
|
2665
|
+
end
|
2666
|
+
```
|
2667
|
+
|
2668
|
+
|
2669
|
+
### exist
|
2670
|
+
|
2671
|
+
```ruby
|
2672
|
+
describe redshift_cluster_parameter_group('my-redshift-cluster-parameter-group') do
|
2673
|
+
it { should exist }
|
2674
|
+
end
|
2675
|
+
```
|
2676
|
+
|
2677
|
+
|
2581
2678
|
## <a name="route53_hosted_zone">route53_hosted_zone</a>
|
2582
2679
|
|
2583
2680
|
Route53HostedZone resource type.
|
@@ -9,7 +9,7 @@ module Awspec
|
|
9
9
|
|
10
10
|
types = %w(
|
11
11
|
vpc ec2 rds security_group elb network_acl route_table subnet nat_gateway network_interface alb nlb
|
12
|
-
internet_gateway autoscaling_group alb_listener nlb_listener
|
12
|
+
internet_gateway autoscaling_group alb_listener nlb_listener redshift
|
13
13
|
)
|
14
14
|
|
15
15
|
types.each do |type|
|
@@ -37,7 +37,7 @@ module Awspec
|
|
37
37
|
end
|
38
38
|
|
39
39
|
types = %w(
|
40
|
-
rds_db_parameter_group rds_db_cluster_parameter_group
|
40
|
+
rds_db_parameter_group rds_db_cluster_parameter_group redshift_cluster_parameter_group
|
41
41
|
)
|
42
42
|
|
43
43
|
types.each do |type|
|
data/lib/awspec/error.rb
CHANGED
@@ -3,4 +3,26 @@ module Awspec
|
|
3
3
|
end
|
4
4
|
class InvalidAccountError < StandardError
|
5
5
|
end
|
6
|
+
##
|
7
|
+
# The exception when sending message to a unavailable AWS resource.
|
8
|
+
#
|
9
|
+
# It should be raised everytime a resource is not available (or doesn't
|
10
|
+
# exist) before trying to invoke a method from it and raising instead
|
11
|
+
# NoMethodError exception.
|
12
|
+
class NoExistingResource < StandardError
|
13
|
+
##
|
14
|
+
# Overrides the superclass initialize method to include more information
|
15
|
+
# and default error message.
|
16
|
+
# Expected parameters:
|
17
|
+
# - resource_type: the name of the resource type. Probably the class method return is the best option to be used.
|
18
|
+
# - id: the string used to search for the AWS resource. It will vary depending on the resource type, but probably
|
19
|
+
# will be an string.
|
20
|
+
|
21
|
+
def initialize(resource_type, id)
|
22
|
+
@resource_type = resource_type
|
23
|
+
@id = id
|
24
|
+
message = "The resource type #{resource_type} with id #{id} does not exist"
|
25
|
+
super message
|
26
|
+
end
|
27
|
+
end
|
6
28
|
end
|
data/lib/awspec/generator.rb
CHANGED
@@ -35,6 +35,8 @@ require 'awspec/generator/spec/codebuild'
|
|
35
35
|
require 'awspec/generator/spec/autoscaling_group'
|
36
36
|
require 'awspec/generator/spec/alb_listener'
|
37
37
|
require 'awspec/generator/spec/nlb_listener'
|
38
|
+
require 'awspec/generator/spec/redshift'
|
39
|
+
require 'awspec/generator/spec/redshift_cluster_parameter_group'
|
38
40
|
|
39
41
|
# Doc
|
40
42
|
require 'awspec/generator/doc/type'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Doc
|
3
|
+
module Type
|
4
|
+
class Redshift < Base
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@type_name = 'Redshift'
|
8
|
+
@type = Awspec::Type::Redshift.new('my-redshift')
|
9
|
+
@ret = @type.resource_via_client
|
10
|
+
@matchers = [
|
11
|
+
Awspec::Type::Redshift::STATES.map { |state| 'be_' + state.tr('-', '_') }.join(', '),
|
12
|
+
'belong_to_vpc',
|
13
|
+
'belong_to_cluster_subnet_group'
|
14
|
+
]
|
15
|
+
@ignore_matchers = Awspec::Type::Redshift::STATES.map { |state| 'be_' + state.tr('-', '_') }
|
16
|
+
@describes = %w(vpc_id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Doc
|
3
|
+
module Type
|
4
|
+
class RedshiftClusterParameterGroup < Base
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@type_name = 'RedshiftClusterParameterGroup'
|
8
|
+
@type = Awspec::Type::RedshiftClusterParameterGroup.new('my-redshift-cluster-parameter-group')
|
9
|
+
@ret = @type.resource_via_client
|
10
|
+
@matchers = []
|
11
|
+
@ignore_matchers = []
|
12
|
+
@describes = []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,7 +3,7 @@ module Awspec::Generator
|
|
3
3
|
class Kms
|
4
4
|
include Awspec::Helper::Finder
|
5
5
|
def generate_all
|
6
|
-
aliases = select_all_kms_aliases
|
6
|
+
aliases = select_all_kms_aliases.select { |kms_alias| customer_managed_key?(kms_alias) }
|
7
7
|
raise 'Not Found alias' if aliases.empty?
|
8
8
|
ERB.new(keys_spec_template, nil, '-').result(binding).chomp
|
9
9
|
end
|
@@ -14,13 +14,21 @@ module Awspec::Generator
|
|
14
14
|
describe kms('<%= kms_alias.alias_name.split('/').last %>') do
|
15
15
|
it { should exist }
|
16
16
|
<% if find_kms_key(kms_alias.target_key_id).enabled -%>
|
17
|
-
it { should
|
17
|
+
it { should be_enabled }
|
18
18
|
<% end -%>
|
19
19
|
end
|
20
20
|
<% end %>
|
21
21
|
EOF
|
22
22
|
template
|
23
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def customer_managed_key?(kms_alias)
|
28
|
+
# An aliase that has no target key id field is predefined by AWS.
|
29
|
+
# see: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/KMS/Client.html#list_aliases-instance_method
|
30
|
+
!kms_alias.target_key_id.nil?
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class Redshift
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_by_vpc_id(vpc_id)
|
6
|
+
describes = %w(
|
7
|
+
node_type master_username db_name availability_zone
|
8
|
+
allow_version_upgrade number_of_nodes publicly_accessible encrypted
|
9
|
+
kms_key_id enhanced_vpc_routing pending_actions maintenance_track_name
|
10
|
+
elastic_resize_number_of_node_options
|
11
|
+
)
|
12
|
+
|
13
|
+
vpc = find_vpc(vpc_id)
|
14
|
+
raise 'Not Found VPC' unless vpc
|
15
|
+
@vpc_id = vpc[:vpc_id]
|
16
|
+
@vpc_tag_name = vpc.tag_name
|
17
|
+
clusters = select_redshift_by_vpc_id(@vpc_id)
|
18
|
+
specs = clusters.map do |cluster|
|
19
|
+
sg_group_names = cluster[:vpc_security_groups].map do |sg|
|
20
|
+
sg_id = sg.vpc_security_group_id
|
21
|
+
ret = find_security_group(sg_id)
|
22
|
+
ret[:group_name]
|
23
|
+
end
|
24
|
+
content = ERB.new(redshift_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
25
|
+
end
|
26
|
+
specs.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:disable all
|
30
|
+
def redshift_spec_template
|
31
|
+
template = <<-'EOF'
|
32
|
+
describe redshift('<%= cluster.cluster_identifier %>') do
|
33
|
+
it { should exist }
|
34
|
+
it { should be_<%= cluster.cluster_status %> }
|
35
|
+
<% describes.each do |describe| %>
|
36
|
+
<%- if cluster.members.include?(describe.to_sym) && !cluster[describe.to_sym].nil? -%>
|
37
|
+
<%- if cluster[describe].is_a?(String) -%>
|
38
|
+
its(:<%= describe %>) { should eq '<%= cluster[describe] %>' }
|
39
|
+
<%- else -%>
|
40
|
+
its(:<%= describe %>) { should eq <%= cluster[describe] %> }
|
41
|
+
<%- end -%>
|
42
|
+
<%- end -%>
|
43
|
+
<% end %>
|
44
|
+
<% sg_group_names.each do |sg_group_name| %>
|
45
|
+
it { should have_security_group('<%= sg_group_name %>') }
|
46
|
+
<% end %>
|
47
|
+
<%- if @vpc_tag_name -%>
|
48
|
+
it { should belong_to_vpc('<%= @vpc_tag_name %>') }
|
49
|
+
<%- else -%>
|
50
|
+
it { should belong_to_vpc('<%= @vpc_id %>') }
|
51
|
+
<%- end -%>
|
52
|
+
it { should belong_to_cluster_subnet_group('<%= cluster.cluster_subnet_group_name %>') }
|
53
|
+
<% cluster.cluster_parameter_groups.each do |pg| %>
|
54
|
+
it { should have_cluster_parameter_group('<%= pg.parameter_group_name %>').parameter_apply_status('<%= pg.parameter_apply_status %>') }
|
55
|
+
<% end %>
|
56
|
+
<% cluster.tags.each do |tag| %>
|
57
|
+
it { should have_tag('<%= tag.key %>').value('<%= tag.value %>') }
|
58
|
+
<% end %>
|
59
|
+
end
|
60
|
+
EOF
|
61
|
+
template
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Awspec::Generator
|
2
|
+
module Spec
|
3
|
+
class RedshiftClusterParameterGroup
|
4
|
+
include Awspec::Helper::Finder
|
5
|
+
def generate_by_parameter_group(parameter_group)
|
6
|
+
@parameter_group = parameter_group
|
7
|
+
res = select_all_redshift_cluster_parameters(@parameter_group)
|
8
|
+
ERB.new(redshift_cluster_parameters_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
def redshift_cluster_parameters_spec_template
|
12
|
+
template = <<-'EOF'
|
13
|
+
describe redshift_cluster_parameter_group('<%= @parameter_group %>') do
|
14
|
+
<% res.each do |key, value| %>
|
15
|
+
its('<%= key %>') { should eq '<%= value %>' }
|
16
|
+
<% end %>
|
17
|
+
end
|
18
|
+
EOF
|
19
|
+
template
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/awspec/helper/finder.rb
CHANGED
@@ -42,6 +42,7 @@ require 'awspec/helper/finder/batch'
|
|
42
42
|
require 'awspec/helper/finder/eks'
|
43
43
|
require 'awspec/helper/finder/sns_topic'
|
44
44
|
require 'awspec/helper/finder/emr'
|
45
|
+
require 'awspec/helper/finder/redshift'
|
45
46
|
|
46
47
|
require 'awspec/helper/finder/account_attributes'
|
47
48
|
|
@@ -93,6 +94,7 @@ module Awspec::Helper
|
|
93
94
|
include Awspec::Helper::Finder::Eks
|
94
95
|
include Awspec::Helper::Finder::SNSTopic
|
95
96
|
include Awspec::Helper::Finder::Emr
|
97
|
+
include Awspec::Helper::Finder::Redshift
|
96
98
|
|
97
99
|
CLIENTS = {
|
98
100
|
ec2_client: Aws::EC2::Client,
|
@@ -132,7 +134,8 @@ module Awspec::Helper
|
|
132
134
|
batch_client: Aws::Batch::Client,
|
133
135
|
eks_client: Aws::EKS::Client,
|
134
136
|
sns_client: Aws::SNS::Client,
|
135
|
-
emr_client: Aws::EMR::Client
|
137
|
+
emr_client: Aws::EMR::Client,
|
138
|
+
redshift_client: Aws::Redshift::Client
|
136
139
|
}
|
137
140
|
|
138
141
|
CLIENT_OPTIONS = {
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Awspec::Helper
|
2
|
+
module Finder
|
3
|
+
module Redshift
|
4
|
+
def find_redshift_cluster_identifier(id)
|
5
|
+
res = redshift_client.describe_clusters(cluster_identifier: id)
|
6
|
+
res.clusters.single_resource(id)
|
7
|
+
rescue
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def select_redshift_by_vpc_id(vpc_id)
|
12
|
+
res = redshift_client.describe_clusters
|
13
|
+
res.clusters.select do |clusters|
|
14
|
+
clusters.vpc_id == vpc_id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def select_all_redshift_cluster_parameters(parameter_group)
|
19
|
+
parameters = {}
|
20
|
+
res = redshift_client.describe_cluster_parameters({
|
21
|
+
parameter_group_name: parameter_group
|
22
|
+
})
|
23
|
+
loop do
|
24
|
+
res.parameters.each do |param|
|
25
|
+
parameters[param.parameter_name] = param.parameter_value
|
26
|
+
end
|
27
|
+
(res.respond_to?(:next_page?) && res.next_page? && res = res.next_page) || break
|
28
|
+
end
|
29
|
+
parameters
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/awspec/helper/type.rb
CHANGED
@@ -18,7 +18,8 @@ module Awspec
|
|
18
18
|
rds rds_db_cluster_parameter_group rds_db_parameter_group route53_hosted_zone
|
19
19
|
route_table s3_bucket security_group ses_identity subnet vpc cloudfront_distribution
|
20
20
|
elastictranscoder_pipeline waf_web_acl customer_gateway vpn_gateway vpn_connection internet_gateway acm
|
21
|
-
cloudwatch_logs dynamodb_table eip sqs ssm_parameter cloudformation_stack codebuild sns_topic
|
21
|
+
cloudwatch_logs dynamodb_table eip sqs ssm_parameter cloudformation_stack codebuild sns_topic redshift
|
22
|
+
redshift_cluster_parameter_group
|
22
23
|
)
|
23
24
|
|
24
25
|
ACCOUNT_ATTRIBUTES = %w(
|
data/lib/awspec/matcher.rb
CHANGED
@@ -74,3 +74,7 @@ require 'awspec/matcher/have_vpc_peering_connection'
|
|
74
74
|
# SNSTopic
|
75
75
|
require 'awspec/matcher/include_subscribed'
|
76
76
|
require 'awspec/matcher/have_subscription_attributes'
|
77
|
+
|
78
|
+
# Redshift
|
79
|
+
require 'awspec/matcher/belong_to_cluster_subnet_group'
|
80
|
+
require 'awspec/matcher/have_cluster_parameter_group'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
RSpec::Matchers.define :have_cluster_parameter_group do |name|
|
2
|
+
match do |cluster_identifier|
|
3
|
+
cluster_identifier.has_cluster_parameter_group?(name, @parameter_apply_status)
|
4
|
+
end
|
5
|
+
|
6
|
+
chain :parameter_apply_status do |parameter_apply_status|
|
7
|
+
@parameter_apply_status = parameter_apply_status
|
8
|
+
end
|
9
|
+
end
|
data/lib/awspec/stub/kms.rb
CHANGED
@@ -6,6 +6,10 @@ Aws.config[:kms] = {
|
|
6
6
|
alias_arn: 'arn:aws:kms:us-east-1:1234567890:alias/my-kms-key',
|
7
7
|
alias_name: 'alias/my-kms-key',
|
8
8
|
target_key_id: 'b9989d41-eeaa-401f-8616-00546948aa92'
|
9
|
+
},
|
10
|
+
{
|
11
|
+
alias_arn: 'arn:aws:kms:us-east-1:1234567890:alias/aws/example',
|
12
|
+
alias_name: 'alias/aws/example'
|
9
13
|
}
|
10
14
|
]
|
11
15
|
},
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Aws.config[:redshift] = {
|
2
|
+
stub_responses: {
|
3
|
+
describe_clusters: {
|
4
|
+
clusters: [
|
5
|
+
{
|
6
|
+
cluster_identifier: 'my-redshift',
|
7
|
+
node_type: 't2.medium',
|
8
|
+
cluster_status: 'available',
|
9
|
+
db_name: 'my-db',
|
10
|
+
vpc_security_groups: [
|
11
|
+
{
|
12
|
+
vpc_security_group_id: 'sg-1a2b3c4d',
|
13
|
+
status: 'active'
|
14
|
+
}
|
15
|
+
],
|
16
|
+
cluster_parameter_groups: [
|
17
|
+
{
|
18
|
+
parameter_group_name: 'my-pg',
|
19
|
+
parameter_apply_status: 'in-sync'
|
20
|
+
}
|
21
|
+
],
|
22
|
+
cluster_subnet_group_name: 'my-sg',
|
23
|
+
vpc_id: 'vpc-ab123cde',
|
24
|
+
availability_zone: 'ap-northeast-1a',
|
25
|
+
tags: [
|
26
|
+
{
|
27
|
+
key: 'Name',
|
28
|
+
value: 'my-cluster'
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
Aws.config[:ec2] = {
|
38
|
+
stub_responses: {
|
39
|
+
describe_vpcs: {
|
40
|
+
vpcs: [
|
41
|
+
{
|
42
|
+
vpc_id: 'vpc-ab123cde',
|
43
|
+
tags: [
|
44
|
+
{
|
45
|
+
key: 'Name',
|
46
|
+
value: 'my-vpc'
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
]
|
51
|
+
},
|
52
|
+
describe_security_groups: {
|
53
|
+
security_groups: [
|
54
|
+
{
|
55
|
+
group_id: 'sg-1a2b3c4d',
|
56
|
+
group_name: 'group-name-sg',
|
57
|
+
tags: [
|
58
|
+
{
|
59
|
+
key: 'Name',
|
60
|
+
value: 'my-db-sg'
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Aws.config[:redshift] = {
|
2
|
+
stub_responses: {
|
3
|
+
describe_cluster_parameters: {
|
4
|
+
parameters: [
|
5
|
+
{
|
6
|
+
parameter_name: 'datestyle',
|
7
|
+
parameter_value: 'ISO, MDY'
|
8
|
+
},
|
9
|
+
{
|
10
|
+
parameter_name: 'query_group',
|
11
|
+
parameter_value: 'default'
|
12
|
+
},
|
13
|
+
{
|
14
|
+
parameter_name: 'require_ssl',
|
15
|
+
parameter_value: 'false'
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
data/lib/awspec/type/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'aws-sdk'
|
2
2
|
require 'awspec/resource_reader'
|
3
3
|
require 'awspec/helper/finder'
|
4
|
+
require 'awspec/error'
|
4
5
|
|
5
6
|
module Awspec::Type
|
6
7
|
class Base
|
@@ -36,8 +37,11 @@ module Awspec::Type
|
|
36
37
|
def method_missing(name)
|
37
38
|
name_str = name.to_s if name.class == Symbol
|
38
39
|
describe = name_str.tr('-', '_').to_sym
|
40
|
+
|
39
41
|
if !resource_via_client.nil? && resource_via_client.members.include?(describe)
|
40
42
|
resource_via_client[describe]
|
43
|
+
elsif resource_via_client.nil?
|
44
|
+
raise Awspec::NoExistingResource.new(self.class, @display_name)
|
41
45
|
else
|
42
46
|
super unless self.respond_to?(:resource)
|
43
47
|
method_missing_via_black_list(name, delegate_to: resource)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'awspec/error'
|
2
|
+
|
1
3
|
module Awspec::Type
|
2
4
|
class IamPolicy < ResourceBase
|
3
5
|
def resource_via_client
|
@@ -9,10 +11,12 @@ module Awspec::Type
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def attachable?
|
14
|
+
check_existence
|
12
15
|
resource_via_client.is_attachable
|
13
16
|
end
|
14
17
|
|
15
18
|
def attached_to_user?(user_id = nil)
|
19
|
+
check_existence
|
16
20
|
users = select_attached_users(id)
|
17
21
|
if user_id
|
18
22
|
user = find_iam_user(user_id)
|
@@ -26,6 +30,7 @@ module Awspec::Type
|
|
26
30
|
end
|
27
31
|
|
28
32
|
def attached_to_group?(group_id = nil)
|
33
|
+
check_existence
|
29
34
|
groups = select_attached_groups(@id)
|
30
35
|
if group_id
|
31
36
|
group = find_iam_group(group_id)
|
@@ -39,6 +44,7 @@ module Awspec::Type
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def attached_to_role?(role_id = nil)
|
47
|
+
check_existence
|
42
48
|
roles = select_attached_roles(@id)
|
43
49
|
if role_id
|
44
50
|
role = find_iam_role(role_id)
|
@@ -50,5 +56,11 @@ module Awspec::Type
|
|
50
56
|
!roles.empty?
|
51
57
|
end
|
52
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def check_existence
|
63
|
+
raise Awspec::NoExistingResource.new(self.class, @display_name) if resource_via_client.nil?
|
64
|
+
end
|
53
65
|
end
|
54
66
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Awspec::Type
|
2
|
+
class Redshift < ResourceBase
|
3
|
+
def resource_via_client
|
4
|
+
@resource_via_client ||= find_redshift_cluster_identifier(@display_name)
|
5
|
+
end
|
6
|
+
|
7
|
+
def id
|
8
|
+
@id ||= resource_via_client.cluster_identifier if resource_via_client
|
9
|
+
end
|
10
|
+
|
11
|
+
STATES = %w(
|
12
|
+
available cancelling-resize creating deleting
|
13
|
+
final-snapshot hardware-failure incompatible-hsm
|
14
|
+
incompatible-network incompatible-parameters incompatible-restore
|
15
|
+
modifying rebooting renaming resizing rotating-keys
|
16
|
+
storage-full updating-hsm
|
17
|
+
)
|
18
|
+
|
19
|
+
STATES.each do |state|
|
20
|
+
define_method state.tr('-', '_') + '?' do
|
21
|
+
resource_via_client.cluster_status == state
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_security_group?(sg_id)
|
26
|
+
return true if has_vpc_security_group_id?(sg_id)
|
27
|
+
return true if has_vpc_security_group_name?(sg_id)
|
28
|
+
return true if has_vpc_security_group_tag_name?(sg_id)
|
29
|
+
return true if has_cluster_security_group_name?(sg_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_cluster_parameter_group?(name, parameter_apply_status = nil)
|
33
|
+
pgs = resource_via_client.cluster_parameter_groups
|
34
|
+
pgs.find do |pg|
|
35
|
+
if parameter_apply_status.nil?
|
36
|
+
pg.parameter_group_name == name
|
37
|
+
else
|
38
|
+
pg.parameter_group_name == name && \
|
39
|
+
pg.parameter_apply_status == parameter_apply_status
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_tag?(tag_key, tag_value)
|
45
|
+
resource_via_client.tags do |tag|
|
46
|
+
tag.key == tag_key && tag.value == tag_value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def has_vpc_security_group_id?(sg_id)
|
53
|
+
sgs = resource_via_client.vpc_security_groups
|
54
|
+
sgs.find do |sg|
|
55
|
+
sg.vpc_security_group_id == sg_id
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_vpc_security_group_name?(sg_id)
|
60
|
+
sgs = resource_via_client.vpc_security_groups
|
61
|
+
res = ec2_client.describe_security_groups({
|
62
|
+
filters: [{ name: 'group-name', values: [sg_id] }]
|
63
|
+
})
|
64
|
+
return false unless res.security_groups.count == 1
|
65
|
+
sgs.find do |sg|
|
66
|
+
sg.vpc_security_group_id == res.security_groups.first.group_id
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_vpc_security_group_tag_name?(sg_id)
|
71
|
+
sgs = resource_via_client.vpc_security_groups
|
72
|
+
res = ec2_client.describe_security_groups({
|
73
|
+
filters: [{ name: 'tag:Name', values: [sg_id] }]
|
74
|
+
})
|
75
|
+
return false unless res.security_groups.count == 1
|
76
|
+
sgs.find do |sg|
|
77
|
+
sg.vpc_security_group_id == res.security_groups.first.group_id
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def has_cluster_security_group_name?(sg_id)
|
82
|
+
sgs = resource_via_client.cluster_security_groups
|
83
|
+
sgs.find do |sg|
|
84
|
+
sg.cluster_security_group_name == sg_id
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Awspec::Type
|
2
|
+
class RedshiftClusterParameterGroup < ResourceBase
|
3
|
+
def resource_via_client
|
4
|
+
@resource_via_client ||= select_all_redshift_cluster_parameters(@display_name)
|
5
|
+
end
|
6
|
+
|
7
|
+
def id
|
8
|
+
@id ||= @display_name unless resource_via_client.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(name)
|
12
|
+
param_name = name.to_s
|
13
|
+
if resource_via_client.include?(param_name)
|
14
|
+
resource_via_client[param_name].to_s
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/awspec/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -271,6 +271,8 @@ files:
|
|
271
271
|
- doc/_resource_types/rds_account_attributes.md
|
272
272
|
- doc/_resource_types/rds_db_cluster_parameter_group.md
|
273
273
|
- doc/_resource_types/rds_db_parameter_group.md
|
274
|
+
- doc/_resource_types/redshift.md
|
275
|
+
- doc/_resource_types/redshift_cluster_parameter_group.md
|
274
276
|
- doc/_resource_types/route53_hosted_zone.md
|
275
277
|
- doc/_resource_types/route_table.md
|
276
278
|
- doc/_resource_types/s3_bucket.md
|
@@ -362,6 +364,8 @@ files:
|
|
362
364
|
- lib/awspec/generator/doc/type/rds_account_attributes.rb
|
363
365
|
- lib/awspec/generator/doc/type/rds_db_cluster_parameter_group.rb
|
364
366
|
- lib/awspec/generator/doc/type/rds_db_parameter_group.rb
|
367
|
+
- lib/awspec/generator/doc/type/redshift.rb
|
368
|
+
- lib/awspec/generator/doc/type/redshift_cluster_parameter_group.rb
|
365
369
|
- lib/awspec/generator/doc/type/route53_hosted_zone.rb
|
366
370
|
- lib/awspec/generator/doc/type/route_table.rb
|
367
371
|
- lib/awspec/generator/doc/type/s3_bucket.rb
|
@@ -406,6 +410,8 @@ files:
|
|
406
410
|
- lib/awspec/generator/spec/rds.rb
|
407
411
|
- lib/awspec/generator/spec/rds_db_cluster_parameter_group.rb
|
408
412
|
- lib/awspec/generator/spec/rds_db_parameter_group.rb
|
413
|
+
- lib/awspec/generator/spec/redshift.rb
|
414
|
+
- lib/awspec/generator/spec/redshift_cluster_parameter_group.rb
|
409
415
|
- lib/awspec/generator/spec/route53_hosted_zone.rb
|
410
416
|
- lib/awspec/generator/spec/route_table.rb
|
411
417
|
- lib/awspec/generator/spec/s3_bucket.rb
|
@@ -451,6 +457,7 @@ files:
|
|
451
457
|
- lib/awspec/helper/finder/lambda.rb
|
452
458
|
- lib/awspec/helper/finder/nlb.rb
|
453
459
|
- lib/awspec/helper/finder/rds.rb
|
460
|
+
- lib/awspec/helper/finder/redshift.rb
|
454
461
|
- lib/awspec/helper/finder/route53.rb
|
455
462
|
- lib/awspec/helper/finder/s3.rb
|
456
463
|
- lib/awspec/helper/finder/security_group.rb
|
@@ -472,6 +479,7 @@ files:
|
|
472
479
|
- lib/awspec/matcher/be_opened_only.rb
|
473
480
|
- lib/awspec/matcher/belong_to_alb.rb
|
474
481
|
- lib/awspec/matcher/belong_to_cache_subnet_group.rb
|
482
|
+
- lib/awspec/matcher/belong_to_cluster_subnet_group.rb
|
475
483
|
- lib/awspec/matcher/belong_to_db_subnet_group.rb
|
476
484
|
- lib/awspec/matcher/belong_to_domain.rb
|
477
485
|
- lib/awspec/matcher/belong_to_iam_group.rb
|
@@ -481,6 +489,7 @@ files:
|
|
481
489
|
- lib/awspec/matcher/belong_to_subnet.rb
|
482
490
|
- lib/awspec/matcher/belong_to_vpc.rb
|
483
491
|
- lib/awspec/matcher/have_attribute_definition.rb
|
492
|
+
- lib/awspec/matcher/have_cluster_parameter_group.rb
|
484
493
|
- lib/awspec/matcher/have_custom_response_error_code.rb
|
485
494
|
- lib/awspec/matcher/have_db_parameter_group.rb
|
486
495
|
- lib/awspec/matcher/have_inline_policy.rb
|
@@ -562,6 +571,8 @@ files:
|
|
562
571
|
- lib/awspec/stub/rds.rb
|
563
572
|
- lib/awspec/stub/rds_db_cluster_parameter_group.rb
|
564
573
|
- lib/awspec/stub/rds_db_parameter_group.rb
|
574
|
+
- lib/awspec/stub/redshift.rb
|
575
|
+
- lib/awspec/stub/redshift_cluster_parameter_group.rb
|
565
576
|
- lib/awspec/stub/route53_hosted_zone.rb
|
566
577
|
- lib/awspec/stub/route_table.rb
|
567
578
|
- lib/awspec/stub/s3_bucket.rb
|
@@ -639,6 +650,8 @@ files:
|
|
639
650
|
- lib/awspec/type/rds_account_attributes.rb
|
640
651
|
- lib/awspec/type/rds_db_cluster_parameter_group.rb
|
641
652
|
- lib/awspec/type/rds_db_parameter_group.rb
|
653
|
+
- lib/awspec/type/redshift.rb
|
654
|
+
- lib/awspec/type/redshift_cluster_parameter_group.rb
|
642
655
|
- lib/awspec/type/resource_base.rb
|
643
656
|
- lib/awspec/type/route53_hosted_zone.rb
|
644
657
|
- lib/awspec/type/route_table.rb
|
@@ -675,7 +688,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
675
688
|
version: '0'
|
676
689
|
requirements: []
|
677
690
|
rubyforge_project:
|
678
|
-
rubygems_version: 2.
|
691
|
+
rubygems_version: 2.6.14
|
679
692
|
signing_key:
|
680
693
|
specification_version: 4
|
681
694
|
summary: RSpec tests for your AWS resources.
|