Module: Enscalator::Plugins::RDS
- Defined in:
- lib/enscalator/plugins/rds.rb
Overview
Amazon RDS instance
Class Method Summary collapse
-
.included(klass) ⇒ Object
Ensure that plugin using this template is a subclass of EnAppTemplateDSL.
Instance Method Summary collapse
-
#rds_init(db_name, use_snapshot: false, allocated_storage: 5, backup_retention_period: 5, storage_type: 'gp2', multizone: 'false', engine: 'MySQL', engine_version: '5.6', parameter_group: 'default.mysql5.6', instance_type: 'db.t2.small', properties: {}) ⇒ Object
Create new Amazon RDS instance.
Class Method Details
.included(klass) ⇒ Object
Ensure that plugin using this template is a subclass of EnAppTemplateDSL
136 137 138 139 140 |
# File 'lib/enscalator/plugins/rds.rb', line 136 def self.included(klass) if klass.superclass != Enscalator::EnAppTemplateDSL fail("Plugin #{name.to_s.demodulize} requires template to be subclass of #{EnAppTemplateDSL}") end end |
Instance Method Details
#rds_init(db_name, use_snapshot: false, allocated_storage: 5, backup_retention_period: 5, storage_type: 'gp2', multizone: 'false', engine: 'MySQL', engine_version: '5.6', parameter_group: 'default.mysql5.6', instance_type: 'db.t2.small', properties: {}) ⇒ Object
Create new Amazon RDS instance
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/enscalator/plugins/rds.rb', line 15 def rds_init(db_name, use_snapshot: false, allocated_storage: 5, backup_retention_period: 5, storage_type: 'gp2', multizone: 'false', engine: 'MySQL', engine_version: '5.6', parameter_group: 'default.mysql5.6', instance_type: 'db.t2.small', properties: {}) parameter_name "RDS#{db_name}" parameter_rds_instance_type "RDS#{db_name}", type: instance_type parameter_allocated_storage "RDS#{db_name}", default: allocated_storage, min: 5, max: 1024 parameter "RDS#{db_name}Engine", Default: engine, Description: 'DB engine type of the DB instance', Type: 'String' parameter "RDS#{db_name}EngineVersion", Default: engine_version, Description: 'DB engine version of the DB instance', Type: 'String' parameter "RDS#{db_name}StorageType", Default: storage_type, Description: 'Storage type to be associated with the DB instance', Type: 'String', AllowedValues: %w( gp2 standard io1 ) parameter "RDS#{db_name}Multizone", Default: multizone, Description: 'Multizone deployment', Type: 'String' parameter "RDS#{db_name}ParameterGroup", Default: parameter_group, Description: 'Custom parameter group for an RDS database family', Type: 'String' parameter_username "RDS#{db_name}" parameter_password "RDS#{db_name}" resource "RDS#{db_name}SubnetGroup", Type: 'AWS::RDS::DBSubnetGroup', Properties: { DBSubnetGroupDescription: 'Subnet group within VPC', SubnetIds: ref_resource_subnets, Tags: [ { Key: 'Name', Value: "RDS#{db_name}SubnetGroup" } ] } # DBName and DBSnapshotIdentifier are mutually exclusive, thus # when snapshot_id is given DBName won't be included to resource parameters props = properties.deep_dup if use_snapshot parameter "RDS#{db_name}SnapshotId", Description: 'Identifier for the DB snapshot to restore from', Type: 'String', MinLength: '1', MaxLength: '64' props[:DBSnapshotIdentifier] = ref("RDS#{db_name}SnapshotId") else props[:DBName] = ref("RDS#{db_name}Name") end = [ { Key: 'Name', Value: "RDS#{db_name}Instance" } ] # Set instance tags if props.key?(:Tags) && !props[:Tags].empty? props[:Tags].concat() else props[:Tags] = end rds_props = { PubliclyAccessible: 'false', MultiAZ: ref("RDS#{db_name}Multizone"), Engine: ref("RDS#{db_name}Engine"), EngineVersion: ref("RDS#{db_name}EngineVersion"), MasterUsername: ref("RDS#{db_name}Username"), MasterUserPassword: ref("RDS#{db_name}Password"), DBInstanceClass: ref("RDS#{db_name}InstanceType"), VPCSecurityGroups: [ref_resource_security_group, ref_private_security_group], DBSubnetGroupName: ref("RDS#{db_name}SubnetGroup"), DBParameterGroupName: ref("RDS#{db_name}ParameterGroup"), AllocatedStorage: ref("RDS#{db_name}AllocatedStorage"), BackupRetentionPeriod: backup_retention_period, StorageType: ref("RDS#{db_name}StorageType") } rds_instance_resource_name = "RDS#{db_name}Instance" resource rds_instance_resource_name, Type: 'AWS::RDS::DBInstance', Properties: rds_props.merge(props) output "RDS#{db_name}EndpointAddress", Description: "#{db_name} Endpoint Address", Value: get_att("RDS#{db_name}Instance", 'Endpoint.Address') rds_instance_resource_name end |