awspec 0.55.0 → 0.56.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/awspec.rb +1 -0
  3. data/lib/awspec/generator/template.rb +6 -3
  4. data/lib/awspec/shared_context.rb +11 -0
  5. data/lib/awspec/type/ami.rb +7 -5
  6. data/lib/awspec/type/autoscaling_group.rb +8 -6
  7. data/lib/awspec/type/base.rb +15 -7
  8. data/lib/awspec/type/cloudfront_distribution.rb +8 -6
  9. data/lib/awspec/type/cloudtrail.rb +10 -8
  10. data/lib/awspec/type/cloudwatch_alarm.rb +9 -7
  11. data/lib/awspec/type/cloudwatch_event.rb +8 -6
  12. data/lib/awspec/type/directconnect_virtual_interface.rb +11 -4
  13. data/lib/awspec/type/ebs.rb +14 -7
  14. data/lib/awspec/type/ec2.rb +20 -13
  15. data/lib/awspec/type/elasticache.rb +13 -6
  16. data/lib/awspec/type/elasticache_cache_parameter_group.rb +15 -8
  17. data/lib/awspec/type/elasticsearch.rb +9 -7
  18. data/lib/awspec/type/elastictranscoder_pipeline.rb +7 -5
  19. data/lib/awspec/type/elb.rb +11 -9
  20. data/lib/awspec/type/iam_group.rb +8 -6
  21. data/lib/awspec/type/iam_policy.rb +8 -6
  22. data/lib/awspec/type/iam_role.rb +8 -6
  23. data/lib/awspec/type/iam_user.rb +8 -6
  24. data/lib/awspec/type/kms.rb +8 -6
  25. data/lib/awspec/type/lambda.rb +8 -6
  26. data/lib/awspec/type/launch_configuration.rb +7 -5
  27. data/lib/awspec/type/nat_gateway.rb +8 -6
  28. data/lib/awspec/type/network_acl.rb +10 -8
  29. data/lib/awspec/type/network_interface.rb +14 -12
  30. data/lib/awspec/type/rds.rb +14 -12
  31. data/lib/awspec/type/rds_db_cluster_parameter_group.rb +13 -9
  32. data/lib/awspec/type/rds_db_parameter_group.rb +13 -9
  33. data/lib/awspec/type/route53_hosted_zone.rb +11 -7
  34. data/lib/awspec/type/route_table.rb +8 -6
  35. data/lib/awspec/type/s3_bucket.rb +15 -13
  36. data/lib/awspec/type/security_group.rb +14 -13
  37. data/lib/awspec/type/ses_identity.rb +15 -13
  38. data/lib/awspec/type/subnet.rb +7 -5
  39. data/lib/awspec/type/vpc.rb +13 -11
  40. data/lib/awspec/type/waf_web_acl.rb +8 -6
  41. data/lib/awspec/version.rb +1 -1
  42. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2786648f3e7a7e6b273f3d154686f6d247113f0
4
- data.tar.gz: a65ca8501700768f0b39ec7a24c6de49b03749b2
3
+ metadata.gz: 29b03262bb9f7a144d1baa26418051af1898f0a2
4
+ data.tar.gz: 4ad6c4180e0837b971d4ae7dcb5dfaf92d444245
5
5
  SHA512:
6
- metadata.gz: 12665c4e7ae28e5e2bf4e1168ffdcd29d4f10c08e5b7c2de597f3f72eaa8ec71e44ed923b517998666ee330d93ad29366eecce818ac88ebad7fe824fe7b665bf
7
- data.tar.gz: 5910721661c227d6ae285e738efafa734f5822701afdd8f385e917fa9c86d2d1fb69a44c5e31cb9673b06b33f17927eaa7a26d33b702e16656c35189cbedabd9
6
+ metadata.gz: d17e5911fc2e6927a0cc2db573e02f2dc77731fb2b24f192995427f1ba7c63e6a2f1cc4a8a3c3bb4a0be226d30728429576489a8eb15861827a1d817fa2e4e2f
7
+ data.tar.gz: 174d4e576def401d02993ffe598723ecb8b76cf3783120796b7ea70b869cd27ca9bb3929ae7997689a0355fc3021bd01a896eaf9ab73733ef647ab4011ade3ac
@@ -14,6 +14,7 @@ require 'awspec/ext'
14
14
  require 'awspec/generator'
15
15
  require 'awspec/toolbox'
16
16
  require 'awspec/resource_reader'
17
+ require 'awspec/shared_context'
17
18
 
18
19
  module Awspec
19
20
  end
@@ -16,9 +16,12 @@ module Awspec::Generator
16
16
  content = <<-"EOF"
17
17
  module Awspec::Type
18
18
  class #{@type.camelize} < Base
19
- def initialize(id)
20
- super
21
- # @id = # @FIXME
19
+ def resource_via_client
20
+ @resource_via_client ||= # FIXME
21
+ end
22
+
23
+ def id
24
+ @id ||= # FIXME
22
25
  end
23
26
  end
24
27
  end
@@ -0,0 +1,11 @@
1
+ shared_context 'region', :region do
2
+ before do |example|
3
+ region = example.metadata[:region]
4
+ @_region = Aws.config[:region]
5
+ Aws.config[:region] = region
6
+ end
7
+
8
+ after do
9
+ Aws.config[:region] = @_region
10
+ end
11
+ end
@@ -2,10 +2,12 @@ module Awspec::Type
2
2
  class Ami < Base
3
3
  aws_resource Aws::EC2::Image
4
4
 
5
- def initialize(id)
6
- super
7
- @resource_via_client = find_ami(id)
8
- @id = @resource_via_client.image_id if @resource_via_client
5
+ def resource_via_client
6
+ @resource_via_client ||= find_ami(@display_name)
7
+ end
8
+
9
+ def id
10
+ @id ||= resource_via_client.image_id if resource_via_client
9
11
  end
10
12
 
11
13
  STATES = %w(
@@ -15,7 +17,7 @@ module Awspec::Type
15
17
 
16
18
  STATES.each do |state|
17
19
  define_method state + '?' do
18
- @resource_via_client.state == state
20
+ resource_via_client.state == state
19
21
  end
20
22
  end
21
23
  end
@@ -1,20 +1,22 @@
1
1
  module Awspec::Type
2
2
  class AutoscalingGroup < Base
3
- def initialize(id)
4
- super
5
- @resource_via_client = find_autoscaling_group(id)
6
- @id = @resource_via_client.auto_scaling_group_arn if @resource_via_client
3
+ def resource_via_client
4
+ @resource_via_client ||= find_autoscaling_group(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.auto_scaling_group_arn if resource_via_client
7
9
  end
8
10
 
9
11
  def has_elb?(name)
10
- @resource_via_client.load_balancer_names.find do |lb_name|
12
+ resource_via_client.load_balancer_names.find do |lb_name|
11
13
  lb_name == name
12
14
  end
13
15
  end
14
16
 
15
17
  def has_ec2?(id)
16
18
  ec2 = find_ec2(id)
17
- @resource_via_client.instances.find do |instance|
19
+ resource_via_client.instances.find do |instance|
18
20
  instance.instance_id = ec2.instance_id
19
21
  end if ec2
20
22
  end
@@ -9,8 +9,8 @@ module Awspec::Type
9
9
 
10
10
  attr_reader :id, :resource_via_client
11
11
 
12
- def initialize(id = nil)
13
- @display_name = id
12
+ def initialize(display_name = nil)
13
+ @display_name = display_name
14
14
  @id = nil
15
15
  end
16
16
 
@@ -24,18 +24,26 @@ module Awspec::Type
24
24
  end
25
25
 
26
26
  def exists?
27
- @id
27
+ id
28
+ end
29
+
30
+ def id
31
+ raise 'this method must be override!'
32
+ end
33
+
34
+ def resource_via_client
35
+ raise 'this method must be override!'
28
36
  end
29
37
 
30
38
  def self.aws_resource(resource)
31
39
  define_method :resource do
32
- @resource ||= Awspec::ResourceReader.new(resource.new(@id))
40
+ @resource ||= Awspec::ResourceReader.new(resource.new(id))
33
41
  end
34
42
  end
35
43
 
36
44
  def self.tags_allowed
37
45
  define_method :has_tag? do |key, value|
38
- tags = @resource_via_client.tags
46
+ tags = resource_via_client.tags
39
47
  return false unless tags
40
48
  tags.any? { |t| t['key'] == key && t['value'] == value }
41
49
  end
@@ -43,8 +51,8 @@ module Awspec::Type
43
51
 
44
52
  def method_missing(name)
45
53
  describe = name.to_sym
46
- if @resource_via_client.members.include?(describe)
47
- @resource_via_client[describe]
54
+ if resource_via_client.members.include?(describe)
55
+ resource_via_client[describe]
48
56
  else
49
57
  super unless self.respond_to?(:resource)
50
58
  method_missing_via_black_list(name, delegate_to: resource)
@@ -1,9 +1,11 @@
1
1
  module Awspec::Type
2
2
  class CloudfrontDistribution < Base
3
- def initialize(id)
4
- super
5
- @resource_via_client = find_cloudfront_distribution(id)
6
- @id = @resource_via_client.id if @resource_via_client
3
+ def resource_via_client
4
+ @resource_via_client ||= find_cloudfront_distribution(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.id if resource_via_client
7
9
  end
8
10
 
9
11
  STATUSES = %w(
@@ -12,7 +14,7 @@ module Awspec::Type
12
14
 
13
15
  STATUSES.each do |status|
14
16
  define_method status.underscore + '?' do
15
- @resource_via_client.status == status
17
+ resource_via_client.status == status
16
18
  end
17
19
  end
18
20
 
@@ -21,7 +23,7 @@ module Awspec::Type
21
23
  origin_path: nil,
22
24
  origin_access_identity: nil)
23
25
  return false unless [origin_id, domain_name].any?
24
- @resource_via_client.origins.items.find do |origin|
26
+ resource_via_client.origins.items.find do |origin|
25
27
  next false if !origin_id.nil? && origin.id != origin_id
26
28
  next false if !domain_name.nil? && origin.domain_name != domain_name
27
29
  next false if !origin_path.nil? && origin.origin_path != origin_path
@@ -2,26 +2,28 @@ module Awspec::Type
2
2
  class Cloudtrail < Base
3
3
  aws_resource Aws::CloudTrail
4
4
 
5
- def initialize(id)
6
- super
7
- @resource_via_client = find_trail(id)
8
- @id = @resource_via_client.name if @resource_via_client
5
+ def resource_via_client
6
+ @resource_via_client ||= find_trail(@display_name)
7
+ end
8
+
9
+ def id
10
+ @id ||= resource_via_client.name if resource_via_client
9
11
  end
10
12
 
11
13
  def has_global_service_events_included?
12
- @resource_via_client.include_global_service_events
14
+ resource_via_client.include_global_service_events
13
15
  end
14
16
 
15
17
  def multi_region_trail?
16
- @resource_via_client.is_multi_region_trail
18
+ resource_via_client.is_multi_region_trail
17
19
  end
18
20
 
19
21
  def has_log_file_validation_enabled?
20
- @resource_via_client.log_file_validation_enabled
22
+ resource_via_client.log_file_validation_enabled
21
23
  end
22
24
 
23
25
  def logging?
24
- is_logging?(@id)
26
+ is_logging?(id)
25
27
  end
26
28
  end
27
29
  end
@@ -1,21 +1,23 @@
1
1
  module Awspec::Type
2
2
  class CloudwatchAlarm < Base
3
- def initialize(id)
4
- super
5
- @resource_via_client = find_cloudwatch_alarm(id)
6
- @id = @resource_via_client.alarm_arn if @resource_via_client
3
+ def resource_via_client
4
+ @resource_via_client ||= find_cloudwatch_alarm(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.alarm_arn if resource_via_client
7
9
  end
8
10
 
9
11
  def has_ok_action?(name)
10
- @resource_via_client.ok_actions.include?(name)
12
+ resource_via_client.ok_actions.include?(name)
11
13
  end
12
14
 
13
15
  def has_alarm_action?(name)
14
- @resource_via_client.alarm_actions.include?(name)
16
+ resource_via_client.alarm_actions.include?(name)
15
17
  end
16
18
 
17
19
  def has_insufficient_data_action?(name)
18
- @resource_via_client.insufficient_data_actions.include?(name)
20
+ resource_via_client.insufficient_data_actions.include?(name)
19
21
  end
20
22
  end
21
23
  end
@@ -1,17 +1,19 @@
1
1
  module Awspec::Type
2
2
  class CloudwatchEvent < Base
3
- def initialize(id)
4
- super
5
- @resource_via_client = find_cloudwatch_event(id)
6
- @id = @resource_via_client.arn if @resource_via_client
3
+ def resource_via_client
4
+ @resource_via_client ||= find_cloudwatch_event(@display_name)
5
+ end
6
+
7
+ def id
8
+ @id ||= resource_via_client.arn if resource_via_client
7
9
  end
8
10
 
9
11
  def enable?
10
- @resource_via_client.state == 'ENABLED'
12
+ resource_via_client.state == 'ENABLED'
11
13
  end
12
14
 
13
15
  def scheduled?(schedule)
14
- @resource_via_client.schedule_expression == schedule
16
+ resource_via_client.schedule_expression == schedule
15
17
  end
16
18
  end
17
19
  end
@@ -1,9 +1,16 @@
1
1
  module Awspec::Type
2
2
  class DirectconnectVirtualInterface < Base
3
- def initialize(id)
3
+ def initialize(name)
4
4
  super
5
- @resource_via_client = find_virtual_interface(id)
6
- @id = @resource_via_client.virtual_interface_id if @resource_via_client
5
+ @display_name = name
6
+ end
7
+
8
+ def resource_via_client
9
+ @resource_via_client ||= find_virtual_interface(@display_name)
10
+ end
11
+
12
+ def id
13
+ @id ||= resource_via_client.virtual_interface_id if resource_via_client
7
14
  end
8
15
 
9
16
  STATES = %w(
@@ -13,7 +20,7 @@ module Awspec::Type
13
20
 
14
21
  STATES.each do |state|
15
22
  define_method state + '?' do
16
- @resource_via_client.virtual_interface_state == state
23
+ resource_via_client.virtual_interface_state == state
17
24
  end
18
25
  end
19
26
  end
@@ -3,10 +3,17 @@ module Awspec::Type
3
3
  aws_resource Aws::EC2::Volume
4
4
  tags_allowed
5
5
 
6
- def initialize(id)
6
+ def initialize(name)
7
7
  super
8
- @resource_via_client = find_ebs(id)
9
- @id = @resource_via_client.volume_id if @resource_via_client
8
+ @display_name = name
9
+ end
10
+
11
+ def resource_via_client
12
+ @resource_via_client ||= find_ebs(@display_name)
13
+ end
14
+
15
+ def id
16
+ @id ||= resource_via_client.volume_id if resource_via_client
10
17
  end
11
18
 
12
19
  STATES = %w(
@@ -15,16 +22,16 @@ module Awspec::Type
15
22
 
16
23
  STATES.each do |state|
17
24
  define_method state.tr('-', '_') + '?' do
18
- @resource_via_client.state == state
25
+ resource_via_client.state == state
19
26
  end
20
27
  end
21
28
 
22
29
  def attached_to?(instance_id)
23
30
  instance = find_ec2(instance_id)
24
31
  return false unless instance
25
- return false unless @resource_via_client.attachments
26
- @resource_via_client.attachments.first.instance_id == instance.instance_id && \
27
- @resource_via_client.attachments.first.state == 'attached'
32
+ return false unless resource_via_client.attachments
33
+ resource_via_client.attachments.first.instance_id == instance.instance_id && \
34
+ resource_via_client.attachments.first.state == 'attached'
28
35
  end
29
36
  end
30
37
  end
@@ -3,10 +3,17 @@ module Awspec::Type
3
3
  aws_resource Aws::EC2::Instance
4
4
  tags_allowed
5
5
 
6
- def initialize(id)
6
+ def initialize(name)
7
7
  super
8
- @resource_via_client = find_ec2(id)
9
- @id = @resource_via_client.instance_id if @resource_via_client
8
+ @display_name = name
9
+ end
10
+
11
+ def resource_via_client
12
+ @resource_via_client ||= find_ec2(@display_name)
13
+ end
14
+
15
+ def id
16
+ @id ||= resource_via_client.instance_id if resource_via_client
10
17
  end
11
18
 
12
19
  STATES = %w(
@@ -16,18 +23,18 @@ module Awspec::Type
16
23
 
17
24
  STATES.each do |state|
18
25
  define_method state.tr('-', '_') + '?' do
19
- @resource_via_client.state.name == state
26
+ resource_via_client.state.name == state
20
27
  end
21
28
  end
22
29
 
23
30
  def disabled_api_termination?
24
- ret = find_ec2_attribute(@id, 'disableApiTermination')
31
+ ret = find_ec2_attribute(id, 'disableApiTermination')
25
32
  ret.disable_api_termination.value
26
33
  end
27
34
 
28
35
  def has_eip?(ip_address = nil)
29
36
  option = {
30
- filters: [{ name: 'instance-id', values: [@id] }]
37
+ filters: [{ name: 'instance-id', values: [id] }]
31
38
  }
32
39
  option[:public_ips] = [ip_address] if ip_address
33
40
  ret = ec2_client.describe_addresses(option)
@@ -36,7 +43,7 @@ module Awspec::Type
36
43
  end
37
44
 
38
45
  def has_security_group?(sg_id)
39
- sgs = @resource_via_client.security_groups
46
+ sgs = resource_via_client.security_groups
40
47
  ret = sgs.find do |sg|
41
48
  sg.group_id == sg_id || sg.group_name == sg_id
42
49
  end
@@ -49,7 +56,7 @@ module Awspec::Type
49
56
  end
50
57
 
51
58
  def has_ebs?(volume_id)
52
- blocks = @resource_via_client.block_device_mappings
59
+ blocks = resource_via_client.block_device_mappings
53
60
  ret = blocks.find do |block|
54
61
  next false unless block.ebs
55
62
  block.ebs.volume_id == volume_id
@@ -57,26 +64,26 @@ module Awspec::Type
57
64
  return true if ret
58
65
  blocks2 = find_ebs(volume_id)
59
66
  blocks2.attachments.find do |attachment|
60
- attachment.instance_id == @id
67
+ attachment.instance_id == id
61
68
  end
62
69
  end
63
70
 
64
71
  def has_event?(event_code)
65
- status = find_ec2_status(@id)
72
+ status = find_ec2_status(id)
66
73
  ret = status.events.find do |event|
67
74
  event.code == event_code
68
75
  end
69
76
  end
70
77
 
71
78
  def has_events?
72
- status = find_ec2_status(@id)
79
+ status = find_ec2_status(id)
73
80
  return false if status.nil?
74
81
  status.events.count > 0
75
82
  end
76
83
 
77
84
  def has_classiclink?(vpc_id = nil)
78
85
  option = {
79
- instance_ids: [@id]
86
+ instance_ids: [id]
80
87
  }
81
88
  option[:filters] = [{ name: 'vpc-id', values: [vpc_id] }] if vpc_id
82
89
  ret = ec2_client.describe_classic_link_instances(option)
@@ -85,7 +92,7 @@ module Awspec::Type
85
92
 
86
93
  def has_classiclink_security_group?(sg_id)
87
94
  option = {
88
- instance_ids: [@id]
95
+ instance_ids: [id]
89
96
  }
90
97
  classic_link_instances = ec2_client.describe_classic_link_instances(option)
91
98
  return false if classic_link_instances.instances.count == 0