awspec 0.33.0 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -1
- data/lib/awspec.rb +1 -0
- data/lib/awspec/command/generate.rb +3 -4
- data/lib/awspec/error.rb +4 -0
- data/lib/awspec/ext.rb +1 -0
- data/lib/awspec/ext/array.rb +8 -0
- data/lib/awspec/generator.rb +1 -0
- data/lib/awspec/generator/spec/lambda.rb +29 -0
- data/lib/awspec/helper/finder.rb +2 -0
- data/lib/awspec/helper/finder/ami.rb +5 -3
- data/lib/awspec/helper/finder/autoscaling.rb +2 -2
- data/lib/awspec/helper/finder/cloudwatch.rb +4 -3
- data/lib/awspec/helper/finder/directconnect.rb +1 -1
- data/lib/awspec/helper/finder/ebs.rb +4 -3
- data/lib/awspec/helper/finder/ec2.rb +15 -51
- data/lib/awspec/helper/finder/elasticache.rb +2 -2
- data/lib/awspec/helper/finder/elb.rb +2 -2
- data/lib/awspec/helper/finder/iam.rb +1 -1
- data/lib/awspec/helper/finder/lambda.rb +8 -2
- data/lib/awspec/helper/finder/rds.rb +2 -2
- data/lib/awspec/helper/finder/route53.rb +3 -1
- data/lib/awspec/helper/finder/security_group.rb +10 -11
- data/lib/awspec/helper/finder/ses.rb +2 -2
- data/lib/awspec/helper/finder/subnet.rb +24 -0
- data/lib/awspec/helper/finder/vpc.rb +14 -28
- data/lib/awspec/helper/type.rb +8 -10
- data/lib/awspec/matcher/have_route.rb +1 -1
- data/lib/awspec/stub/duplicated_resource_type.rb +26 -0
- data/lib/awspec/stub/lambda.rb +5 -2
- data/lib/awspec/type/ami.rb +2 -2
- data/lib/awspec/type/autoscaling_group.rb +1 -1
- data/lib/awspec/type/base.rb +1 -1
- data/lib/awspec/type/cloudwatch_alarm.rb +4 -4
- data/lib/awspec/type/directconnect_virtual_interface.rb +2 -2
- data/lib/awspec/type/ebs.rb +5 -5
- data/lib/awspec/type/ec2.rb +12 -12
- data/lib/awspec/type/elasticache.rb +5 -5
- data/lib/awspec/type/elb.rb +8 -8
- data/lib/awspec/type/iam_group.rb +3 -3
- data/lib/awspec/type/iam_policy.rb +4 -4
- data/lib/awspec/type/iam_role.rb +2 -2
- data/lib/awspec/type/iam_user.rb +2 -2
- data/lib/awspec/type/lambda.rb +2 -2
- data/lib/awspec/type/launch_configuration.rb +3 -3
- data/lib/awspec/type/nat_gateway.rb +2 -2
- data/lib/awspec/type/network_acl.rb +5 -5
- data/lib/awspec/type/rds.rb +17 -17
- data/lib/awspec/type/route53_hosted_zone.rb +2 -2
- data/lib/awspec/type/route_table.rb +2 -2
- data/lib/awspec/type/security_group.rb +39 -39
- data/lib/awspec/type/ses_identity.rb +5 -5
- data/lib/awspec/type/subnet.rb +2 -2
- data/lib/awspec/type/vpc.rb +4 -4
- data/lib/awspec/version.rb +1 -1
- metadata +7 -2
@@ -1,29 +1,28 @@
|
|
1
1
|
module Awspec::Helper
|
2
2
|
module Finder
|
3
3
|
module SecurityGroup
|
4
|
-
def find_security_group(
|
4
|
+
def find_security_group(sg_id)
|
5
5
|
res = ec2_client.describe_security_groups({
|
6
|
-
filters: [{ name: 'group-id', values: [
|
6
|
+
filters: [{ name: 'group-id', values: [sg_id] }]
|
7
7
|
})
|
8
|
-
|
9
|
-
return
|
8
|
+
resource = res.security_groups.single_resource(sg_id)
|
9
|
+
return resource if resource
|
10
10
|
res = ec2_client.describe_security_groups({
|
11
|
-
filters: [{ name: 'group-name', values: [
|
11
|
+
filters: [{ name: 'group-name', values: [sg_id] }]
|
12
12
|
})
|
13
|
-
|
14
|
-
return
|
13
|
+
resource = res.security_groups.single_resource(sg_id)
|
14
|
+
return resource if resource
|
15
15
|
res = ec2_client.describe_security_groups({
|
16
|
-
filters: [{ name: 'tag:Name', values: [
|
16
|
+
filters: [{ name: 'tag:Name', values: [sg_id] }]
|
17
17
|
})
|
18
|
-
|
19
|
-
return res[:security_groups].first if res[:security_groups].count == 1
|
18
|
+
res.security_groups.single_resource(sg_id)
|
20
19
|
end
|
21
20
|
|
22
21
|
def select_security_group_by_vpc_id(vpc_id)
|
23
22
|
res = ec2_client.describe_security_groups({
|
24
23
|
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
25
24
|
})
|
26
|
-
res
|
25
|
+
res.security_groups
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -3,10 +3,10 @@ module Awspec::Helper
|
|
3
3
|
module Ses
|
4
4
|
def find_ses_identity(id)
|
5
5
|
res = ses_client.list_identities
|
6
|
-
ret = res
|
6
|
+
ret = res.identities.select do |identity|
|
7
7
|
identity == id
|
8
8
|
end
|
9
|
-
ret.
|
9
|
+
ret.single_resource(id)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Awspec::Helper
|
2
|
+
module Finder
|
3
|
+
module Subnet
|
4
|
+
def find_subnet(subnet_id)
|
5
|
+
res = ec2_client.describe_subnets({
|
6
|
+
filters: [{ name: 'subnet-id', values: [subnet_id] }]
|
7
|
+
})
|
8
|
+
resource = res.subnets.single_resource(subnet_id)
|
9
|
+
return resource if resource
|
10
|
+
res = ec2_client.describe_subnets({
|
11
|
+
filters: [{ name: 'tag:Name', values: [subnet_id] }]
|
12
|
+
})
|
13
|
+
res.subnets.single_resource(subnet_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def select_subnet_by_vpc_id(vpc_id)
|
17
|
+
res = ec2_client.describe_subnets({
|
18
|
+
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
19
|
+
})
|
20
|
+
res.subnets
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -5,65 +5,50 @@ module Awspec::Helper
|
|
5
5
|
res = ec2_client.describe_vpcs({
|
6
6
|
filters: [{ name: 'vpc-id', values: [id] }]
|
7
7
|
})
|
8
|
-
|
8
|
+
resource = res.vpcs.single_resource(id)
|
9
|
+
return resource if resource
|
9
10
|
res = ec2_client.describe_vpcs({
|
10
11
|
filters: [{ name: 'tag:Name', values: [id] }]
|
11
12
|
})
|
12
|
-
|
13
|
+
res.vpcs.single_resource(id)
|
13
14
|
end
|
14
15
|
|
15
16
|
def find_route_table(route_table_id)
|
16
17
|
res = ec2_client.describe_route_tables({
|
17
18
|
filters: [{ name: 'route-table-id', values: [route_table_id] }]
|
18
19
|
})
|
19
|
-
|
20
|
+
resource = res.route_tables.single_resource(route_table_id)
|
21
|
+
return resource if resource
|
20
22
|
res = ec2_client.describe_route_tables({
|
21
23
|
filters: [{ name: 'tag:Name', values: [route_table_id] }]
|
22
24
|
})
|
23
|
-
|
25
|
+
res.route_tables.single_resource(route_table_id)
|
24
26
|
end
|
25
27
|
|
26
28
|
def find_network_acl(id)
|
27
29
|
res = ec2_client.describe_network_acls({
|
28
30
|
filters: [{ name: 'network-acl-id', values: [id] }]
|
29
31
|
})
|
30
|
-
|
32
|
+
resource = res.network_acls.single_resource(id)
|
33
|
+
return resource if resource
|
31
34
|
res = ec2_client.describe_network_acls({
|
32
35
|
filters: [{ name: 'tag:Name', values: [id] }]
|
33
36
|
})
|
34
|
-
|
37
|
+
res.network_acls.single_resource(id)
|
35
38
|
end
|
36
39
|
|
37
40
|
def select_route_table_by_vpc_id(vpc_id)
|
38
41
|
res = ec2_client.describe_route_tables({
|
39
42
|
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
40
43
|
})
|
41
|
-
res
|
44
|
+
res.route_tables
|
42
45
|
end
|
43
46
|
|
44
47
|
def select_network_acl_by_vpc_id(vpc_id)
|
45
48
|
res = ec2_client.describe_network_acls({
|
46
49
|
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
47
50
|
})
|
48
|
-
res
|
49
|
-
end
|
50
|
-
|
51
|
-
def find_subnet(subnet_id)
|
52
|
-
res = ec2_client.describe_subnets({
|
53
|
-
filters: [{ name: 'subnet-id', values: [subnet_id] }]
|
54
|
-
})
|
55
|
-
return res[:subnets].first if res[:subnets].count == 1
|
56
|
-
res = ec2_client.describe_subnets({
|
57
|
-
filters: [{ name: 'tag:Name', values: [subnet_id] }]
|
58
|
-
})
|
59
|
-
return res[:subnets].first if res[:subnets].count == 1
|
60
|
-
end
|
61
|
-
|
62
|
-
def select_subnet_by_vpc_id(vpc_id)
|
63
|
-
res = ec2_client.describe_subnets({
|
64
|
-
filters: [{ name: 'vpc-id', values: [vpc_id] }]
|
65
|
-
})
|
66
|
-
res[:subnets]
|
51
|
+
res.network_acls
|
67
52
|
end
|
68
53
|
|
69
54
|
def find_vpc_peering_connection(vpc_peering_connection_id)
|
@@ -75,7 +60,8 @@ module Awspec::Helper
|
|
75
60
|
}
|
76
61
|
]
|
77
62
|
})
|
78
|
-
|
63
|
+
resource = res.vpc_peering_connections.single_resource(vpc_peering_connection_id)
|
64
|
+
return resource if resource
|
79
65
|
res = ec2_client.describe_vpc_peering_connections({
|
80
66
|
filters: [
|
81
67
|
{
|
@@ -84,7 +70,7 @@ module Awspec::Helper
|
|
84
70
|
}
|
85
71
|
]
|
86
72
|
})
|
87
|
-
|
73
|
+
res.vpc_peering_connections.single_resource(vpc_peering_connection_id)
|
88
74
|
end
|
89
75
|
end
|
90
76
|
end
|
data/lib/awspec/helper/type.rb
CHANGED
@@ -19,18 +19,16 @@ module Awspec
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def self.deprecate_resource_type(old_type, new_type)
|
23
|
+
define_method(old_type) do |*args, &block|
|
24
|
+
puts ''
|
25
|
+
warn Color.on_red(Color.white("!!! `#{old_type}` type is deprecated. use `#{new_type}` !!!"))
|
26
|
+
send(new_type, *args, &block)
|
27
|
+
end
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
puts Color.on_red(Color.white('!!! `s3` type is deprecated. use `s3_bucket` !!!'))
|
32
|
-
Awspec::Type::S3Bucket.new(name)
|
33
|
-
end
|
30
|
+
deprecate_resource_type :auto_scaling_group, :autoscaling_group
|
31
|
+
deprecate_resource_type :s3, :s3_bucket
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
@@ -20,7 +20,7 @@ RSpec::Matchers.define :have_route do |destination|
|
|
20
20
|
chain :destination do |dest|
|
21
21
|
# rubocop:disable Metrics/LineLength
|
22
22
|
puts ''
|
23
|
-
|
23
|
+
warn Color.on_red(Color.white('!!! route_table destination is deprecated. see https://github.com/k1LoW/awspec/pull/65 !!!'))
|
24
24
|
# rubocop:enable Metrics/LineLength
|
25
25
|
@use_destination = true
|
26
26
|
@destination = dest
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Aws.config[:ec2] = {
|
2
|
+
stub_responses: {
|
3
|
+
describe_vpcs: {
|
4
|
+
vpcs: [
|
5
|
+
{
|
6
|
+
vpc_id: 'vpc-ab123cde',
|
7
|
+
tags: [
|
8
|
+
{
|
9
|
+
key: 'Name',
|
10
|
+
value: 'my-vpc'
|
11
|
+
}
|
12
|
+
]
|
13
|
+
},
|
14
|
+
{
|
15
|
+
vpc_id: 'vpc-cd456efg',
|
16
|
+
tags: [
|
17
|
+
{
|
18
|
+
key: 'Name',
|
19
|
+
value: 'my-vpc'
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
data/lib/awspec/stub/lambda.rb
CHANGED
@@ -5,9 +5,12 @@ Aws.config[:lambda] = {
|
|
5
5
|
{
|
6
6
|
function_name: 'my-lambda-function-name',
|
7
7
|
function_arn: 'arn:aws:lambda:us-east-1:123456789012:function:my-lambda-function-name',
|
8
|
-
|
8
|
+
description: 'My Lambda Function',
|
9
|
+
runtime: 'python2.7',
|
10
|
+
handler: 'lambda_function.lambda_handler',
|
9
11
|
timeout: 5,
|
10
|
-
memory_size: 256
|
12
|
+
memory_size: 256,
|
13
|
+
code_size: 1234
|
11
14
|
}
|
12
15
|
]
|
13
16
|
},
|
data/lib/awspec/type/ami.rb
CHANGED
@@ -5,7 +5,7 @@ module Awspec::Type
|
|
5
5
|
def initialize(id)
|
6
6
|
super
|
7
7
|
@resource_via_client = find_ami(id)
|
8
|
-
@id = @resource_via_client
|
8
|
+
@id = @resource_via_client.image_id if @resource_via_client
|
9
9
|
end
|
10
10
|
|
11
11
|
STATES = %w(
|
@@ -15,7 +15,7 @@ module Awspec::Type
|
|
15
15
|
|
16
16
|
STATES.each do |state|
|
17
17
|
define_method state + '?' do
|
18
|
-
@resource_via_client
|
18
|
+
@resource_via_client.state == state
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -3,7 +3,7 @@ module Awspec::Type
|
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
5
|
@resource_via_client = find_autoscaling_group(id)
|
6
|
-
@id = @resource_via_client
|
6
|
+
@id = @resource_via_client.auto_scaling_group_arn if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_elb?(name)
|
data/lib/awspec/type/base.rb
CHANGED
@@ -3,19 +3,19 @@ module Awspec::Type
|
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
5
|
@resource_via_client = find_cloudwatch_alarm(id)
|
6
|
-
@id = @resource_via_client
|
6
|
+
@id = @resource_via_client.alarm_arn if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_ok_action?(name)
|
10
|
-
@resource_via_client
|
10
|
+
@resource_via_client.ok_actions.include?(name)
|
11
11
|
end
|
12
12
|
|
13
13
|
def has_alarm_action?(name)
|
14
|
-
@resource_via_client
|
14
|
+
@resource_via_client.alarm_actions.include?(name)
|
15
15
|
end
|
16
16
|
|
17
17
|
def has_insufficient_data_action?(name)
|
18
|
-
@resource_via_client
|
18
|
+
@resource_via_client.insufficient_data_actions.include?(name)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -3,7 +3,7 @@ module Awspec::Type
|
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
5
|
@resource_via_client = find_virtual_interface(id)
|
6
|
-
@id = @resource_via_client
|
6
|
+
@id = @resource_via_client.virtual_interface_id if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
STATES = %w(
|
@@ -13,7 +13,7 @@ module Awspec::Type
|
|
13
13
|
|
14
14
|
STATES.each do |state|
|
15
15
|
define_method state + '?' do
|
16
|
-
@resource_via_client
|
16
|
+
@resource_via_client.virtual_interface_state == state
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/awspec/type/ebs.rb
CHANGED
@@ -5,7 +5,7 @@ module Awspec::Type
|
|
5
5
|
def initialize(id)
|
6
6
|
super
|
7
7
|
@resource_via_client = find_ebs(id)
|
8
|
-
@id = @resource_via_client
|
8
|
+
@id = @resource_via_client.volume_id if @resource_via_client
|
9
9
|
end
|
10
10
|
|
11
11
|
STATES = %w(
|
@@ -14,16 +14,16 @@ module Awspec::Type
|
|
14
14
|
|
15
15
|
STATES.each do |state|
|
16
16
|
define_method state.tr('-', '_') + '?' do
|
17
|
-
@resource_via_client
|
17
|
+
@resource_via_client.state == state
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def attached_to?(instance_id)
|
22
22
|
instance = find_ec2(instance_id)
|
23
23
|
return false unless instance
|
24
|
-
return false unless @resource_via_client
|
25
|
-
@resource_via_client
|
26
|
-
@resource_via_client
|
24
|
+
return false unless @resource_via_client.attachments
|
25
|
+
@resource_via_client.attachments.first.instance_id == instance.instance_id && \
|
26
|
+
@resource_via_client.attachments.first.state == 'attached'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/awspec/type/ec2.rb
CHANGED
@@ -6,7 +6,7 @@ module Awspec::Type
|
|
6
6
|
def initialize(id)
|
7
7
|
super
|
8
8
|
@resource_via_client = find_ec2(id)
|
9
|
-
@id = @resource_via_client
|
9
|
+
@id = @resource_via_client.instance_id if @resource_via_client
|
10
10
|
end
|
11
11
|
|
12
12
|
STATES = %w(
|
@@ -16,13 +16,13 @@ module Awspec::Type
|
|
16
16
|
|
17
17
|
STATES.each do |state|
|
18
18
|
define_method state.tr('-', '_') + '?' do
|
19
|
-
@resource_via_client
|
19
|
+
@resource_via_client.state.name == state
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def disabled_api_termination?
|
24
24
|
ret = find_ec2_attribute(@id, 'disableApiTermination')
|
25
|
-
ret
|
25
|
+
ret.disable_api_termination.value
|
26
26
|
end
|
27
27
|
|
28
28
|
def has_eip?(ip_address = nil)
|
@@ -31,32 +31,32 @@ module Awspec::Type
|
|
31
31
|
}
|
32
32
|
option[:public_ips] = [ip_address] if ip_address
|
33
33
|
ret = ec2_client.describe_addresses(option)
|
34
|
-
return ret
|
35
|
-
return ret
|
34
|
+
return ret.addresses.count == 1 if ip_address
|
35
|
+
return ret.addresses.count > 0 unless ip_address
|
36
36
|
end
|
37
37
|
|
38
38
|
def has_security_group?(sg_id)
|
39
|
-
sgs = @resource_via_client
|
39
|
+
sgs = @resource_via_client.security_groups
|
40
40
|
ret = sgs.find do |sg|
|
41
|
-
sg
|
41
|
+
sg.group_id == sg_id || sg.group_name == sg_id
|
42
42
|
end
|
43
43
|
return true if ret
|
44
44
|
sg2 = find_security_group(sg_id)
|
45
45
|
return false unless sg2.tag_name == sg_id
|
46
46
|
sgs.find do |sg|
|
47
|
-
sg
|
47
|
+
sg.group_id == sg2.group_id
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def has_ebs?(volume_id)
|
52
|
-
blocks = @resource_via_client
|
52
|
+
blocks = @resource_via_client.block_device_mappings
|
53
53
|
ret = blocks.find do |block|
|
54
|
-
next false unless block
|
55
|
-
block
|
54
|
+
next false unless block.ebs
|
55
|
+
block.ebs.volume_id == volume_id
|
56
56
|
end
|
57
57
|
return true if ret
|
58
58
|
blocks2 = find_ebs(volume_id)
|
59
|
-
blocks2
|
59
|
+
blocks2.attachments.find do |attachment|
|
60
60
|
attachment.instance_id == @id
|
61
61
|
end
|
62
62
|
end
|
@@ -3,7 +3,7 @@ module Awspec::Type
|
|
3
3
|
def initialize(id)
|
4
4
|
super
|
5
5
|
@resource_via_client = find_cache_cluster(id)
|
6
|
-
@id = @resource_via_client
|
6
|
+
@id = @resource_via_client.cache_cluster_id if @resource_via_client
|
7
7
|
end
|
8
8
|
|
9
9
|
STATES = %w(
|
@@ -15,17 +15,17 @@ module Awspec::Type
|
|
15
15
|
|
16
16
|
STATES.each do |state|
|
17
17
|
define_method state.tr('-', '_') + '?' do
|
18
|
-
@resource_via_client
|
18
|
+
@resource_via_client.cache_cluster_status == state
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def has_cache_parameter_group?(group_name)
|
23
|
-
@resource_via_client
|
23
|
+
@resource_via_client.cache_parameter_group.cache_parameter_group_name == group_name
|
24
24
|
end
|
25
25
|
|
26
26
|
def vpc_id
|
27
|
-
cache_subnet_group = find_cache_subnet_group(@resource_via_client
|
28
|
-
cache_subnet_group
|
27
|
+
cache_subnet_group = find_cache_subnet_group(@resource_via_client.cache_subnet_group_name)
|
28
|
+
cache_subnet_group.vpc_id if cache_subnet_group
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|