awspec 1.24.1 → 1.24.2

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
  SHA256:
3
- metadata.gz: ccbb248dd9ff83f422a5d62d6463be302ee629861e3a29ebfb3b062313ccca4f
4
- data.tar.gz: 14fb693105dafceb27095c0ec2af853422f5ed92ee877a69df66a4679a6acad1
3
+ metadata.gz: 846285926375fd9f812d6110b9b6f82918a1cd217dde0b51e3e87694fa39861c
4
+ data.tar.gz: b9b0d5c955add005d788b35ace982d75a74843cb8bb0c4cc86cbf931bb6cb68e
5
5
  SHA512:
6
- metadata.gz: 4d580f1de54fd8a7b5106d83f4b5b7320f2679d5eb58ef6d73009fb340bc7a0193b78f4f10d16601d9dacb5658a94936efd0af40699ef781229eef54c645e7f3
7
- data.tar.gz: bf0f3fa1ab69f5945307284f1b3460bfadb9571c892601418dbfaee6536cd4269fdbc4b1c1631b438098dace53aeb49bdaa59773bc03d759ee3c709970c5b235
6
+ metadata.gz: 6d2af549c10d9e3634e6e7ff809b6bb3a5518dc3a9ae52e70963718a19aa2731cd274b9bbbba614989b49253eb85e4f806487692c7a7f72c7135dda58162fb5b
7
+ data.tar.gz: 0aa25037fc049461e9558c57af0b7f6ab02b70cb43b4637496edfb7715704d8abd821b2f52bebc7a4a2ea3bf6ba95d5d9034102084667d249dce7f8584ee8a97
data/.travis.yml CHANGED
@@ -1,4 +1,8 @@
1
+ ---
1
2
  language: ruby
3
+ env:
4
+ global:
5
+ DISABLE_AWS_CLIENT_CHECK: true
2
6
  matrix:
3
7
  include:
4
8
  - rvm: 2.7.3
data/README.md CHANGED
@@ -32,7 +32,7 @@ If you're starting on a fresh RSpec project, you can use awspec to generate your
32
32
 
33
33
  $ awspec init
34
34
 
35
- If you're working on an exisitng RSpec project, you will need to add the following lines to your `spec_helper.rb` file:
35
+ If you're working on an existing RSpec project, you will need to add the following lines to your `spec_helper.rb` file:
36
36
 
37
37
  ```ruby
38
38
  require 'awspec'
@@ -273,7 +273,7 @@ end
273
273
 
274
274
  ### have_tag
275
275
 
276
- ### its(:architecture), its(:creation_date), its(:image_id), its(:image_location), its(:image_type), its(:public), its(:kernel_id), its(:owner_id), its(:platform), its(:platform_details), its(:usage_operation), its(:ramdisk_id), its(:state), its(:description), its(:ena_support), its(:hypervisor), its(:image_owner_alias), its(:name), its(:root_device_name), its(:root_device_type), its(:sriov_net_support), its(:state_reason), its(:virtualization_type), its(:boot_mode)
276
+ ### its(:architecture), its(:creation_date), its(:image_id), its(:image_location), its(:image_type), its(:public), its(:kernel_id), its(:owner_id), its(:platform), its(:platform_details), its(:usage_operation), its(:ramdisk_id), its(:state), its(:description), its(:ena_support), its(:hypervisor), its(:image_owner_alias), its(:name), its(:root_device_name), its(:root_device_type), its(:sriov_net_support), its(:state_reason), its(:virtualization_type), its(:boot_mode), its(:deprecation_time)
277
277
  ### :unlock: Advanced use
278
278
 
279
279
  `ami` can use `Aws::EC2::Image` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Image.html).
@@ -360,7 +360,7 @@ describe autoscaling_group('my-auto-scaling-group') do
360
360
  end
361
361
  ```
362
362
 
363
- ### its(:auto_scaling_group_name), its(:auto_scaling_group_arn), its(:launch_configuration_name), its(:launch_template), its(:mixed_instances_policy), its(:min_size), its(:max_size), its(:desired_capacity), its(:default_cooldown), its(:availability_zones), its(:load_balancer_names), its(:target_group_arns), its(:health_check_type), its(:health_check_grace_period), its(:created_time), its(:placement_group), its(:vpc_zone_identifier), its(:enabled_metrics), its(:status), its(:termination_policies), its(:new_instances_protected_from_scale_in), its(:service_linked_role_arn), its(:max_instance_lifetime), its(:capacity_rebalance), its(:warm_pool_configuration), its(:warm_pool_size)
363
+ ### its(:auto_scaling_group_name), its(:auto_scaling_group_arn), its(:launch_configuration_name), its(:launch_template), its(:mixed_instances_policy), its(:min_size), its(:max_size), its(:desired_capacity), its(:predicted_capacity), its(:default_cooldown), its(:availability_zones), its(:load_balancer_names), its(:target_group_arns), its(:health_check_type), its(:health_check_grace_period), its(:created_time), its(:placement_group), its(:vpc_zone_identifier), its(:enabled_metrics), its(:status), its(:termination_policies), its(:new_instances_protected_from_scale_in), its(:service_linked_role_arn), its(:max_instance_lifetime), its(:capacity_rebalance), its(:warm_pool_configuration), its(:warm_pool_size), its(:context)
364
364
  ## <a name="batch_compute_environment">batch_compute_environment</a>
365
365
 
366
366
  BatchComputeEnvironment resource type.
@@ -1372,7 +1372,7 @@ end
1372
1372
 
1373
1373
  ### be_active, be_inactive
1374
1374
 
1375
- ### its(:nodegroup_name), its(:nodegroup_arn), its(:cluster_name), its(:version), its(:release_version), its(:created_at), its(:modified_at), its(:status), its(:capacity_type), its(:scaling_config), its(:instance_types), its(:subnets), its(:remote_access), its(:ami_type), its(:node_role), its(:labels), its(:resources), its(:disk_size), its(:health), its(:launch_template), its(:tags)
1375
+ ### its(:nodegroup_name), its(:nodegroup_arn), its(:cluster_name), its(:version), its(:release_version), its(:created_at), its(:modified_at), its(:status), its(:capacity_type), its(:scaling_config), its(:instance_types), its(:subnets), its(:remote_access), its(:ami_type), its(:node_role), its(:labels), its(:taints), its(:resources), its(:disk_size), its(:health), its(:update_config), its(:launch_template), its(:tags)
1376
1376
  ## <a name="elasticache">elasticache</a>
1377
1377
 
1378
1378
  Elasticache resource type.
@@ -2178,7 +2178,7 @@ DOC
2178
2178
  end
2179
2179
  ```
2180
2180
 
2181
- ### its(:aws_account_id), its(:key_id), its(:arn), its(:creation_date), its(:enabled), its(:description), its(:key_usage), its(:key_state), its(:deletion_date), its(:valid_to), its(:origin), its(:custom_key_store_id), its(:cloud_hsm_cluster_id), its(:expiration_model), its(:key_manager), its(:customer_master_key_spec), its(:encryption_algorithms), its(:signing_algorithms)
2181
+ ### its(:aws_account_id), its(:key_id), its(:arn), its(:creation_date), its(:enabled), its(:description), its(:key_usage), its(:key_state), its(:deletion_date), its(:valid_to), its(:origin), its(:custom_key_store_id), its(:cloud_hsm_cluster_id), its(:expiration_model), its(:key_manager), its(:customer_master_key_spec), its(:encryption_algorithms), its(:signing_algorithms), its(:multi_region), its(:multi_region_configuration), its(:pending_deletion_window_in_days)
2182
2182
  ## <a name="lambda">lambda</a>
2183
2183
 
2184
2184
  Lambda resource type.
@@ -2422,7 +2422,7 @@ end
2422
2422
  ```
2423
2423
 
2424
2424
 
2425
- ### its(:create_time), its(:delete_time), its(:failure_code), its(:failure_message), its(:nat_gateway_id), its(:provisioned_bandwidth), its(:state), its(:subnet_id), its(:vpc_id)
2425
+ ### its(:create_time), its(:delete_time), its(:failure_code), its(:failure_message), its(:nat_gateway_id), its(:provisioned_bandwidth), its(:state), its(:subnet_id), its(:vpc_id), its(:connectivity_type)
2426
2426
  ## <a name="network_acl">network_acl</a>
2427
2427
 
2428
2428
  NetworkAcl resource type.
@@ -2801,7 +2801,7 @@ end
2801
2801
  ```
2802
2802
 
2803
2803
 
2804
- ### its(:vpc_id), its(:db_instance_identifier), its(:db_instance_class), its(:engine), its(:db_instance_status), its(:master_username), its(:db_name), its(:endpoint), its(:allocated_storage), its(:instance_create_time), its(:preferred_backup_window), its(:backup_retention_period), its(:db_security_groups), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:latest_restorable_time), its(:multi_az), its(:engine_version), its(:auto_minor_version_upgrade), its(:read_replica_source_db_instance_identifier), its(:read_replica_db_instance_identifiers), its(:read_replica_db_cluster_identifiers), its(:replica_mode), its(:license_model), its(:iops), its(:character_set_name), its(:nchar_character_set_name), its(:secondary_availability_zone), its(:publicly_accessible), its(:status_infos), its(:storage_type), its(:tde_credential_arn), its(:db_instance_port), its(:db_cluster_identifier), its(:storage_encrypted), its(:kms_key_id), its(:dbi_resource_id), its(:ca_certificate_identifier), its(:domain_memberships), its(:copy_tags_to_snapshot), its(:monitoring_interval), its(:enhanced_monitoring_resource_arn), its(:monitoring_role_arn), its(:promotion_tier), its(:db_instance_arn), its(:timezone), its(:iam_database_authentication_enabled), its(:performance_insights_enabled), its(:performance_insights_kms_key_id), its(:performance_insights_retention_period), its(:enabled_cloudwatch_logs_exports), its(:processor_features), its(:deletion_protection), its(:associated_roles), its(:listener_endpoint), its(:max_allocated_storage), its(:tag_list), its(:db_instance_automated_backups_replications), its(:customer_owned_ip_enabled), its(:aws_backup_recovery_point_arn)
2804
+ ### its(:vpc_id), its(:db_instance_identifier), its(:db_instance_class), its(:engine), its(:db_instance_status), its(:master_username), its(:db_name), its(:endpoint), its(:allocated_storage), its(:instance_create_time), its(:preferred_backup_window), its(:backup_retention_period), its(:db_security_groups), its(:availability_zone), its(:preferred_maintenance_window), its(:pending_modified_values), its(:latest_restorable_time), its(:multi_az), its(:engine_version), its(:auto_minor_version_upgrade), its(:read_replica_source_db_instance_identifier), its(:read_replica_db_instance_identifiers), its(:read_replica_db_cluster_identifiers), its(:replica_mode), its(:license_model), its(:iops), its(:character_set_name), its(:nchar_character_set_name), its(:secondary_availability_zone), its(:publicly_accessible), its(:status_infos), its(:storage_type), its(:tde_credential_arn), its(:db_instance_port), its(:db_cluster_identifier), its(:storage_encrypted), its(:kms_key_id), its(:dbi_resource_id), its(:ca_certificate_identifier), its(:domain_memberships), its(:copy_tags_to_snapshot), its(:monitoring_interval), its(:enhanced_monitoring_resource_arn), its(:monitoring_role_arn), its(:promotion_tier), its(:db_instance_arn), its(:timezone), its(:iam_database_authentication_enabled), its(:performance_insights_enabled), its(:performance_insights_kms_key_id), its(:performance_insights_retention_period), its(:enabled_cloudwatch_logs_exports), its(:processor_features), its(:deletion_protection), its(:associated_roles), its(:listener_endpoint), its(:max_allocated_storage), its(:tag_list), its(:db_instance_automated_backups_replications), its(:customer_owned_ip_enabled), its(:aws_backup_recovery_point_arn), its(:activity_stream_status), its(:activity_stream_kms_key_id), its(:activity_stream_kinesis_stream_name), its(:activity_stream_mode), its(:activity_stream_engine_native_audit_fields_included)
2805
2805
  ### :unlock: Advanced use
2806
2806
 
2807
2807
  `rds` can use `Aws::RDS::DBInstance` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/RDS/DBInstance.html).
@@ -166,6 +166,12 @@ module Awspec::Helper
166
166
  http_wire_trace: ENV['http_wire_trace'] || false
167
167
  }
168
168
 
169
+ check_configuration = ENV['DISABLE_AWS_CLIENT_CHECK'] != 'true' if ENV.key?('DISABLE_AWS_CLIENT_CHECK')
170
+
171
+ # define_method below will "hide" any exception that comes from bad
172
+ # setup of AWS client, so let's try first to create a instance
173
+ Awsecrets.load if check_configuration
174
+
169
175
  CLIENTS.each do |method_name, client|
170
176
  define_method method_name do
171
177
  unless self.methods.include? "@#{method_name}"
@@ -7,15 +7,16 @@ module Awspec::Helper
7
7
  res = ec2_client.describe_instances({
8
8
  instance_ids: [id]
9
9
  })
10
- rescue
11
- # Aws::EC2::Errors::InvalidInstanceIDMalformed
12
- # Aws::EC2::Errors::InvalidInstanceIDNotFound
10
+ rescue Aws::EC2::Errors::InvalidInstanceIDNotFound, Aws::EC2::Errors::InvalidInstanceIDMalformed => e
13
11
  res = ec2_client.describe_instances({
14
12
  filters: [{ name: 'tag:Name', values: [id] }]
15
13
  })
16
14
  end
17
15
  # rubocop:enable Style/GuardClause
18
- if res.reservations.count == 1
16
+
17
+ if res.reservations.count == 0
18
+ nil
19
+ elsif res.reservations.count == 1
19
20
  res.reservations.first.instances.single_resource(id)
20
21
  elsif res.reservations.count > 1
21
22
  raise Awspec::DuplicatedResourceTypeError, "Duplicate instances matching id or tag #{id}"
@@ -0,0 +1,16 @@
1
+ module Awspec::Helper
2
+ module States
3
+ EC2_STATES = %w(pending running shutting-down terminated stopping stopped)
4
+
5
+ def self.ec2_states_checks
6
+ Enumerator.new do |yielder|
7
+ n = 0
8
+ while n < EC2_STATES.size
9
+ method_name = EC2_STATES[n].tr('-', '_') + '?'
10
+ yielder.yield(method_name, EC2_STATES[n])
11
+ n += 1
12
+ end
13
+ end.lazy
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ Aws.config[:ec2] = {
2
+ stub_responses: {
3
+ describe_instances: {
4
+ reservations: []
5
+ }
6
+ }
7
+ }
@@ -1,3 +1,5 @@
1
+ require 'awspec/helper/states'
2
+
1
3
  module Awspec::Type
2
4
  class Ec2 < ResourceBase
3
5
  aws_resource Aws::EC2::Instance
@@ -8,6 +10,16 @@ module Awspec::Type
8
10
  @display_name = name
9
11
  end
10
12
 
13
+ # required by Awspec::Generator::Doc::Type
14
+ STATES = Awspec::Helper::States::EC2_STATES
15
+
16
+ Awspec::Helper::States.ec2_states_checks.each do |method_name, state|
17
+ define_method method_name do
18
+ check_existence
19
+ resource_via_client.state.name == state
20
+ end
21
+ end
22
+
11
23
  def resource_via_client
12
24
  @resource_via_client ||= find_ec2(@display_name)
13
25
  end
@@ -17,20 +29,10 @@ module Awspec::Type
17
29
  end
18
30
 
19
31
  def security_group_count
32
+ check_existence
20
33
  resource_via_client.security_groups.count
21
34
  end
22
35
 
23
- STATES = %w(
24
- pending running shutting-down
25
- terminated stopping stopped
26
- )
27
-
28
- STATES.each do |state|
29
- define_method state.tr('-', '_') + '?' do
30
- resource_via_client.state.name == state
31
- end
32
- end
33
-
34
36
  def disabled_api_termination?
35
37
  ret = find_ec2_attribute(id, 'disableApiTermination')
36
38
  ret.disable_api_termination.value
@@ -48,7 +50,6 @@ module Awspec::Type
48
50
 
49
51
  def has_security_groups?(sg_ids)
50
52
  return true if match_group_ids?(sg_ids) || match_group_names?(sg_ids)
51
-
52
53
  group_ids = resource_security_groups.map { |sg| sg.group_id }
53
54
  tags = select_security_group_by_group_id(group_ids).map { |sg| sg.tags }.flatten
54
55
  group_names = tags.select { |tag| tag.key == 'Name' }.map { |tag| tag.value }
@@ -56,6 +57,7 @@ module Awspec::Type
56
57
  end
57
58
 
58
59
  def has_security_group?(sg_id)
60
+ check_existence
59
61
  sgs = resource_via_client.security_groups
60
62
  ret = sgs.find do |sg|
61
63
  sg.group_id == sg_id || sg.group_name == sg_id
@@ -69,12 +71,14 @@ module Awspec::Type
69
71
  end
70
72
 
71
73
  def has_iam_instance_profile?(iam_instance_profile_name)
74
+ check_existence
72
75
  iam = resource_via_client.iam_instance_profile
73
76
  ret = iam.arn.split('/').last == iam_instance_profile_name
74
77
  return true if ret
75
78
  end
76
79
 
77
80
  def has_ebs?(volume_id)
81
+ check_existence
78
82
  blocks = resource_via_client.block_device_mappings
79
83
  ret = blocks.find do |block|
80
84
  next false unless block.ebs
@@ -89,8 +93,9 @@ module Awspec::Type
89
93
 
90
94
  def has_network_interface?(network_interface_id, device_index = nil)
91
95
  res = find_network_interface(network_interface_id)
96
+ check_existence
92
97
  interfaces = resource_via_client.network_interfaces
93
- interfaces.find do |interface|
98
+ ret = interfaces.find do |interface|
94
99
  next false if device_index && interface.attachment.device_index != device_index
95
100
  interface.network_interface_id == res.network_interface_id
96
101
  end
@@ -98,7 +103,7 @@ module Awspec::Type
98
103
 
99
104
  def has_event?(event_code)
100
105
  status = find_ec2_status(id)
101
- status.events.find do |event|
106
+ ret = status.events.find do |event|
102
107
  event.code == event_code
103
108
  end
104
109
  end
@@ -133,8 +138,7 @@ module Awspec::Type
133
138
  end
134
139
 
135
140
  def has_credit_specification?(cpu_credits)
136
- ret = find_ec2_credit_specifications(id)
137
- ret.cpu_credits == cpu_credits
141
+ find_ec2_credit_specifications(id).cpu_credits == cpu_credits
138
142
  end
139
143
 
140
144
  private
@@ -148,6 +152,7 @@ module Awspec::Type
148
152
  end
149
153
 
150
154
  def resource_security_groups
155
+ check_existence
151
156
  resource_via_client.security_groups
152
157
  end
153
158
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '1.24.1'
2
+ VERSION = '1.24.2'
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: 1.24.1
4
+ version: 1.24.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-08 00:00:00.000000000 Z
11
+ date: 2021-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -518,6 +518,7 @@ files:
518
518
  - lib/awspec/helper/finder/vpc_endpoints.rb
519
519
  - lib/awspec/helper/finder/waf.rb
520
520
  - lib/awspec/helper/finder/wafregional.rb
521
+ - lib/awspec/helper/states.rb
521
522
  - lib/awspec/helper/type.rb
522
523
  - lib/awspec/matcher.rb
523
524
  - lib/awspec/matcher/be_allowed.rb
@@ -593,6 +594,7 @@ files:
593
594
  - lib/awspec/stub/ebs.rb
594
595
  - lib/awspec/stub/ec2.rb
595
596
  - lib/awspec/stub/ec2_has_multi_security_groups.rb
597
+ - lib/awspec/stub/ec2_non_existing.rb
596
598
  - lib/awspec/stub/ecr_repository.rb
597
599
  - lib/awspec/stub/ecs.rb
598
600
  - lib/awspec/stub/ecs_cluster.rb