Class: Serverspec::Type::AWS::RDS::DBInstance

Inherits:
Base
  • Object
show all
Defined in:
lib/resources/rds/db_instance.rb

Overview

The DBInstance class exposes the RDS::DBInstance resources

Instance Method Summary collapse

Constructor Details

#initialize(dbi_name, instance = nil, ec2 = nil) ⇒ DBInstance

AWS SDK for Ruby v2 Aws::RDS::Client wrapper for initializing a DBInstance resource

Parameters:

  • dbi_name (String)

    The name of the DBInstance

  • instance (Class) (defaults to: nil)

    Aws::RDS::Client instance

  • ec2 (Class) (defaults to: nil)

    Aws::EC2::Client ec2

Raises:

  • (RuntimeError)

    if dbis.nil?

  • (RuntimeError)

    if dbis.length == 0

  • (RuntimeError)

    if dbis.length > 1



18
19
20
21
22
23
24
# File 'lib/resources/rds/db_instance.rb', line 18

def initialize(dbi_name, instance = nil, ec2 = nil)
  check_init_arg 'dbi_name', 'RDS::DBInstance', dbi_name
  @dbi_name = dbi_name
  @aws = instance.nil? ? Aws::RDS::Client.new : instance
  @ec2 = ec2.nil? ? Aws::EC2::Client.new : ec2
  get_dbi dbi_name
end

Instance Method Details

#accessible_from?(cidr) ⇒ Boolean

Tests whether the database should allow connections from the given CIDR range. Inspects each of the security groups associated with the instance and associated inbound rules to check for a rule matching the given CIDR range. For external CIDR ranges, it is verified that the database is publicly accessible.

Even if this method returns true, it does not necessarily mean that actual connections made to the RDS instance will succeed.

Examples that may prevent actual connection are:

  • NACL entries

  • Enabled ports

  • Security Group Egress rules

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
# File 'lib/resources/rds/db_instance.rb', line 75

def accessible_from?(cidr)
  return false if public_cidr?(cidr) && !publicly_accessible?

  vpc_security_groups.each do |sg|
    security_group = AWS::EC2::SecurityGroup.new(sg, @ec2)
    return true if security_group.accessible_from?(cidr)
  end

  false
end

#allocated_storageInteger

Specifies the allocated storage size specified in gigabytes

Returns:

  • (Integer)


127
128
129
# File 'lib/resources/rds/db_instance.rb', line 127

def allocated_storage
  @dbi.allocated_storage
end

#auto_minor_version_upgradeable?Boolean

Indicates that minor version patches are applied automatically

Returns:

  • (Boolean)


43
44
45
# File 'lib/resources/rds/db_instance.rb', line 43

def auto_minor_version_upgradeable?
  @dbi.auto_minor_version_upgrade
end

#availability_zoneString

Specifies the name of the Availability Zone the DB instance is located in

Returns:

  • (String)


176
177
178
# File 'lib/resources/rds/db_instance.rb', line 176

def availability_zone
  @dbi.availability_zone
end

#available?Boolean

Indicates whether instance status is available

Returns:

  • (Boolean)


33
34
35
# File 'lib/resources/rds/db_instance.rb', line 33

def available?
  @dbi.db_instance_status == 'available'
end

#backup_retention_periodInteger

Specifies the number of days for which automatic DB snapshots are retained

Returns:

  • (Integer)


142
143
144
# File 'lib/resources/rds/db_instance.rb', line 142

def backup_retention_period
  @dbi.backup_retention_period
end

#ca_certificate_identifierString

The identifier of the CA certificate for this DB instance

Returns:

  • (String)


293
294
295
# File 'lib/resources/rds/db_instance.rb', line 293

def ca_certificate_identifier
  @dbi.ca_certificate_identifier
end

#character_set_nameString

If present, specifies the name of the character set that this instance is associated with

Returns:

  • (String)


244
245
246
# File 'lib/resources/rds/db_instance.rb', line 244

def character_set_name
  @dbi.character_set_name
end

#database_nameString

The meaning of this parameter differs according to the database engine you use

Returns:

  • (String)


109
110
111
# File 'lib/resources/rds/db_instance.rb', line 109

def database_name
  @dbi.db_name
end

#dbi_resource_idString

If StorageEncrypted is true, the region-unique, immutable identifier for the encrypted DB instance. This identifier is found in AWS CloudTrail log entries whenever the KMS key for the DB instance is accessed

Returns:

  • (String)


287
288
289
# File 'lib/resources/rds/db_instance.rb', line 287

def dbi_resource_id
  @dbi.dbi_resource_id
end

#endpointString

Specifies the connection endpoint DNS address of the DB instance

Returns:

  • (String)


115
116
117
# File 'lib/resources/rds/db_instance.rb', line 115

def endpoint
  @dbi.endpoint.address
end

#engineString

Provides the name of the database engine to be used for this DB instance

Returns:

  • (String)


96
97
98
# File 'lib/resources/rds/db_instance.rb', line 96

def engine
  @dbi.engine
end

#engine_versionString

Indicates the database engine version

Returns:

  • (String)


205
206
207
# File 'lib/resources/rds/db_instance.rb', line 205

def engine_version
  @dbi.engine_version
end

#instance_classString

Contains the name of the compute and memory capacity class of the DB instance

Returns:

  • (String)


89
90
91
# File 'lib/resources/rds/db_instance.rb', line 89

def instance_class
  @dbi.db_instance_class
end

#iopsInteger

Specifies the Provisioned IOPS (I/O operations per second) value

Returns:

  • (Integer)


231
232
233
# File 'lib/resources/rds/db_instance.rb', line 231

def iops
  @dbi.iops
end

#kms_key_idString

If StorageEncrypted is true, the KMS key identifier for the encrypted DB instance

Returns:

  • (String)


278
279
280
# File 'lib/resources/rds/db_instance.rb', line 278

def kms_key_id
  @dbi.kms_key_id
end

#license_modelString

License model information for this DB instance

Returns:

  • (String)


225
226
227
# File 'lib/resources/rds/db_instance.rb', line 225

def license_model
  @dbi.license_model
end

#listening_portInteger

Specifies the port that the database engine is listening on

Returns:

  • (Integer)


121
122
123
# File 'lib/resources/rds/db_instance.rb', line 121

def listening_port
  @dbi.endpoint.port
end

#master_usernameString

Contains the master username for the DB instance

Returns:

  • (String)


102
103
104
# File 'lib/resources/rds/db_instance.rb', line 102

def master_username
  @dbi.master_username
end

#multi_az?Boolean

Specifies if the DB instance is a Multi-AZ deployment

Returns:

  • (Boolean)


38
39
40
# File 'lib/resources/rds/db_instance.rb', line 38

def multi_az?
  @dbi.multi_az
end

#option_group_membershipsArray(Hash)

Provides the list of option group memberships for this DB instance

Returns:

  • (Array(Hash))


237
238
239
# File 'lib/resources/rds/db_instance.rb', line 237

def option_group_memberships
  @dbi.option_group_memberships
end

#parameter_groupsArray(Hash)

Provides the list of DB parameter groups applied to this DB instance

Returns:

  • (Array(Hash))


169
170
171
# File 'lib/resources/rds/db_instance.rb', line 169

def parameter_groups
  @dbi.db_parameter_groups
end

#pending_modified_valuesHash

Specifies that changes to the DB instance are pending. This element is only included when changes are pending. Specific changes are identified by subelements

Returns:

  • (Hash)


199
200
201
# File 'lib/resources/rds/db_instance.rb', line 199

def pending_modified_values
  @dbi.pending_modified_values
end

#preferred_backup_windowString

Specifies the daily time range during which automated backups are created if automated backups are enabled, as determined by the BackupRetentionPeriod

Returns:

  • (String)


135
136
137
# File 'lib/resources/rds/db_instance.rb', line 135

def preferred_backup_window
  @dbi.preferred_backup_window
end

#preferred_maintenance_windowString

Specifies the weekly time range (in UTC) during which system maintenance can occur

Returns:

  • (String)


191
192
193
# File 'lib/resources/rds/db_instance.rb', line 191

def preferred_maintenance_window
  @dbi.preferred_maintenance_window
end

#publicly_accessible?Boolean

Specifies the accessibility options for the DB instance. A value of true specifies an Internet-facing instance with a publicly resolvable DNS name, which resolves to a public IP address. A value of false specifies an internal instance with a DNS name that resolves to a private IP address

Returns:

  • (Boolean)


52
53
54
# File 'lib/resources/rds/db_instance.rb', line 52

def publicly_accessible?
  @dbi.publicly_accessible
end

#read_replica_db_instance_identifiersArray(String)

Contains one or more identifiers of the Read Replicas associated with this DB instance

Returns:

  • (Array(String))


219
220
221
# File 'lib/resources/rds/db_instance.rb', line 219

def read_replica_db_instance_identifiers
  @dbi.read_replica_db_instance_identifiers
end

#read_replica_source_db_instance_identifierString

Contains the identifier of the source DB instance if this DB instance is a Read Replica

Returns:

  • (String)


212
213
214
# File 'lib/resources/rds/db_instance.rb', line 212

def read_replica_source_db_instance_identifier
  @dbi.read_replica_source_db_instance_identifier
end

#secondary_availability_zoneString

If present, specifies the name of the secondary Availability Zone for a DB instance with multi-AZ support

Returns:

  • (String)


251
252
253
# File 'lib/resources/rds/db_instance.rb', line 251

def secondary_availability_zone
  @dbi.secondary_availability_zone
end

#security_groupsArray(String)

Provides List of active DB security group names

Returns:

  • (Array(String))


148
149
150
151
152
153
154
# File 'lib/resources/rds/db_instance.rb', line 148

def security_groups
  sgs = []
  @dbi.db_security_groups.each do |sg|
    sgs << sg.db_security_group_name if sg.status == 'active'
  end
  sgs
end

#status_infosArray(Hash)

The status of a Read Replica. If the instance is not a Read Replica, this will be blank

Returns:

  • (Array(Hash))


258
259
260
# File 'lib/resources/rds/db_instance.rb', line 258

def status_infos
  @dbi.status_infos
end

#storage_typeString

Specifies the storage type associated with DB instance

Returns:

  • (String)


264
265
266
# File 'lib/resources/rds/db_instance.rb', line 264

def storage_type
  @dbi.storage_type
end

#subnet_groupHash

Specifies information on the subnet group associated with the DB instance, including the name, description, and subnets in the subnet group

Returns:

  • (Hash)


184
185
186
# File 'lib/resources/rds/db_instance.rb', line 184

def subnet_group
  @dbi.db_subnet_group
end

#tde_credential_arnString

The ARN from the Key Store with which the instance is associated for TDE encryption

Returns:

  • (String)


271
272
273
# File 'lib/resources/rds/db_instance.rb', line 271

def tde_credential_arn
  @dbi.tde_credential_arn
end

#to_sString

Returns the string representation of RDS::DBInstance

Returns:

  • (String)


28
29
30
# File 'lib/resources/rds/db_instance.rb', line 28

def to_s
  "RDS DBInstance: #{@dbi_name}"
end

#vpc_security_groupsArray(String)

Provides List of VPC security group elements that the DB instance belongs to

Returns:

  • (Array(String))


159
160
161
162
163
164
165
# File 'lib/resources/rds/db_instance.rb', line 159

def vpc_security_groups
  vsgs = []
  @dbi.vpc_security_groups.each do |vsg|
    vsgs << vsg.vpc_security_group_id if vsg.status == 'active'
  end
  vsgs
end

#with_encrypted_storage?Boolean

Specifies whether the DB instance is encrypted

Returns:

  • (Boolean)


57
58
59
# File 'lib/resources/rds/db_instance.rb', line 57

def with_encrypted_storage?
  @dbi.storage_encrypted
end