modules/mu/clouds/aws/database.rb in cloud-mu-2.0.0.pre.alpha9 vs modules/mu/clouds/aws/database.rb in cloud-mu-2.0.0.pre.beta1
- old
+ new
@@ -362,22 +362,20 @@
read_replica_struct.delete(:db_subnet_group_name)
resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_instance_read_replica(read_replica_struct)
end
elsif @config["creation_style"] == "new"
MU.log "Creating pristine database instance #{@config['identifier']} (#{@config['name']}) in #{@config['region']}"
-puts @config['credentials']
-pp config
resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_instance(config)
end
rescue Aws::RDS::Errors::InvalidParameterValue => e
if attempts < 5
- MU.log "Got #{e.inspect} creating #{@config['identifier']}, will retry a few times in case of transient errors.", MU::WARN
+ MU.log "Got #{e.inspect} creating #{@config['identifier']}, will retry a few times in case of transient errors.", MU::WARN, details: config
attempts += 1
sleep 10
retry
else
- raise MuError, "Exhausted retries trying to create database instance #{@config['identifier']}: e.inspect"
+ raise MuError, "Exhausted retries trying to create database instance #{@config['identifier']}: #{e.inspect}"
end
end
wait_start_time = Time.now
retries = 0
@@ -495,10 +493,22 @@
vpc_security_group_ids: @config["vpc_security_group_ids"],
tags: allTags
}
cluster_config_struct[:port] = @config["port"] if @config["port"]
+ if @config['cluster_mode']
+ cluster_config_struct[:engine_mode] = @config['cluster_mode']
+ if @config['cluster_mode'] == "serverless"
+ cluster_config_struct[:scaling_configuration] = {
+ :auto_pause => @config['serverless_scaling']['auto_pause'],
+ :min_capacity => @config['serverless_scaling']['min_capacity'],
+ :max_capacity => @config['serverless_scaling']['max_capacity'],
+ :seconds_until_auto_pause => @config['serverless_scaling']['seconds_until_auto_pause']
+ }
+ end
+ end
+
if %w{existing_snapshot new_snapshot}.include?(@config["creation_style"])
cluster_config_struct[:snapshot_identifier] = @config["snapshot_id"]
cluster_config_struct[:engine] = @config["engine"]
cluster_config_struct[:engine_version] = @config["engine_version"]
cluster_config_struct[:database_name] = @config["db_name"]
@@ -535,16 +545,17 @@
MU.log "Creating new database cluster #{@config['identifier']} from point in time backup #{@config["restore_time"]} of #{@config["source_identifier"]}"
MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).restore_db_cluster_to_point_in_time(cluster_config_struct)
end
rescue Aws::RDS::Errors::InvalidParameterValue => e
if attempts < 5
- MU.log "Got #{e.inspect} while creating database cluster #{@config['identifier']}, will retry a few times in case of transient errors.", MU::WARN
+ MU.log "Got #{e.inspect} while creating database cluster #{@config['identifier']}, will retry a few times in case of transient errors.", MU::WARN, details: cluster_config_struct
attempts += 1
sleep 10
retry
else
- raise MuError, "Exhausted retries trying to create database cluster #{@config['identifier']}", MU::ERR, details: e.inspect
+ MU.log "Exhausted retries trying to create database cluster #{@config['identifier']}", MU::ERR, details: e.inspect
+ raise MuError, "Exhausted retries trying to create database cluster #{@config['identifier']}"
end
end
attempts = 0
loop do
@@ -1412,10 +1423,49 @@
}
schema = {
"db_parameter_group_parameters" => rds_parameters_primitive,
"cluster_parameter_group_parameters" => rds_parameters_primitive,
+ "cluster_mode" => {
+ "type" => "string",
+ "description" => "The DB engine mode of the DB cluster",
+ "enum" => ["provisioned", "serverless", "parallelquery", "global"],
+ "default" => "provisioned"
+ },
+ "serverless_scaling" => {
+ "type" => "object",
+ "descriptions" => "Scaling configuration for a +serverless+ Aurora cluster",
+ "default" => {
+ "auto_pause" => false,
+ "min_capacity" => 2,
+ "max_capacity" => 2
+ },
+ "properties" => {
+ "auto_pause" => {
+ "type" => "boolean",
+ "description" => "A value that specifies whether to allow or disallow automatic pause for an Aurora DB cluster in serverless DB engine mode",
+ "default" => false
+ },
+ "min_capacity" => {
+ "type" => "integer",
+ "description" => "The minimum capacity for an Aurora DB cluster in serverless DB engine mode.",
+ "default" => 2,
+ "enum" => [2, 4, 8, 16, 32, 64, 128, 256]
+ },
+ "max_capacity" => {
+ "type" => "integer",
+ "description" => "The maximum capacity for an Aurora DB cluster in serverless DB engine mode.",
+ "default" => 2,
+ "enum" => [2, 4, 8, 16, 32, 64, 128, 256]
+ },
+ "seconds_until_auto_pause" => {
+ "type" => "integer",
+ "description" => "A DB cluster can be paused only when it's idle (it has no connections). If a DB cluster is paused for more than seven days, the DB cluster might be backed up with a snapshot. In this case, the DB cluster is restored when there is a request to connect to it.",
+ "default" => 86400
+ }
+ }
+ },
"license_model" => {
"type" => "string",
"enum" => ["license-included", "bring-your-own-license", "general-public-license", "postgresql-license"]
},
"ingress_rules" => {
@@ -1450,11 +1500,15 @@
ok = true
if db['create_cluster'] or db['engine'] == "aurora" or db["member_of_cluster"]
case db['engine']
when "mysql", "aurora", "aurora-mysql"
- db["engine"] = "aurora-mysql"
+ if db["engine_version"] == "5.6" or db["cluster_mode"] == "serverless"
+ db["engine"] = "aurora"
+ else
+ db["engine"] = "aurora-mysql"
+ end
when "postgres", "postgresql", "postgresql-mysql"
db["engine"] = "aurora-postgresql"
else
ok = false
MU.log "Requested a clustered database, but engine #{db['engine']} is not supported for clustering", MU::ERR
@@ -1669,18 +1723,18 @@
rescue Aws::RDS::Errors::DBSecurityGroupNotFound
MU.log "RDS Security Group #{sg} disappeared before we could remove it", MU::WARN
end
# Cleanup the database vault
- grommer =
+ groomer =
if database_obj
database_obj.config.has_key?("groomer") ? database_obj.config["groomer"] : MU::Config.defaultGroomer
else
MU::Config.defaultGroomer
end
- groomclass = MU::Groomer.loadGroomer(grommer)
+ groomclass = MU::Groomer.loadGroomer(groomer)
groomclass.deleteSecret(vault: db_id.upcase) if !noop
MU.log "#{db_id} has been terminated"
end
# Remove an RDS database cluster and associated artifacts
@@ -1759,17 +1813,17 @@
break unless cluster
sleep 30
end
# Cleanup the cluster vault
- grommer =
+ groomer =
if cluster_obj
cluster_obj.config.has_key?("groomer") ? cluster_obj.config["groomer"] : MU::Config.defaultGroomer
else
MU::Config.defaultGroomer
end
- groomclass = MU::Groomer.loadGroomer(grommer)
+ groomclass = MU::Groomer.loadGroomer(groomer)
groomclass.deleteSecret(vault: cluster_id.upcase) if !noop
MU.log "#{cluster_id} has been terminated"
end