Class: Akashi::Rds::DbInstance

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

Class Method Summary collapse

Methods inherited from Base

service_class

Methods inherited from Base

all, base_class, collection, find, find_by, #initialize, where

Constructor Details

This class inherits a constructor from Akashi::Base

Class Method Details

.create(security_group:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/akashi/rds/db_instance.rb', line 8

def create(security_group:)
  password = Akashi.manifest.rds.password || random_password(length: 10)
  options  = {
    db_name:                    Akashi.name(separator: "_"),
    db_instance_identifier:     Akashi.name,
    allocated_storage:          Akashi.manifest.rds.allocated_storage,
    db_instance_class:          Akashi.manifest.rds.instance_class,
    engine:                     "mysql",
    master_username:            Akashi.application,
    master_user_password:       password,
    multi_az:                   !!Akashi.manifest.rds.multi_az,
    vpc_security_group_ids:     [ security_group.id ],
    db_subnet_group_name:       Akashi.name,
    engine_version:             Akashi.manifest.rds.engine_version,
    auto_minor_version_upgrade: true,
    publicly_accessible:        false,
  }
  if !!Akashi.manifest.rds.parameter_group_name
    options.merge!(db_parameter_group_name: Akashi.manifest.rds.parameter_group_name)
  end
  unless !!Akashi.manifest.rds.multi_az
    options.merge!(availability_zone: Akashi.manifest.rds.availability_zone)
  end

  response = Akashi::Aws.rds.client.create_db_instance(options)

  new(response[:db_instance_identifier]).tap do |instance|
    puts "Created a RDS (#{instance.id}). Password is \"#{password}\"."
  end
end

.object_classObject



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

def object_class
  @object_class ||= "DBInstance"
end

.random_password(length:) ⇒ Object



39
40
41
# File 'lib/akashi/rds/db_instance.rb', line 39

def random_password(length:)
  [*0..9, *"a".."z", *"A".."Z"].sample(length).join
end