1
HeatTemplateFormatVersion: '2012-12-12'
2
Description: 'Builtin AWS::RDS::DBInstance'
11
Type: CommaDelimitedList
15
AllowedValues: ['MySQL']
29
db.m1.small: {Instance: m1.small}
30
db.m1.large: {Instance: m1.large}
31
db.m1.xlarge: {Instance: m1.xlarge}
32
db.m2.xlarge: {Instance: m2.xlarge}
33
db.m2.2xlarge: {Instance: m2.2xlarge}
34
db.m2.4xlarge: {Instance: m2.4xlarge}
38
Type: AWS::EC2::SecurityGroup
40
GroupDescription: 'Enable SSH access'
55
Type: AWS::EC2::Instance
57
AWS::CloudFormation::Init:
63
- DBName: {Ref: DBName}
64
MasterUserPassword: {Ref: MasterUserPassword}
65
MasterUsername: {Ref: MasterUsername}
67
CREATE DATABASE DBName;
68
GRANT ALL PRIVILEGES ON DBName.* TO "MasterUsername"@"%"
69
IDENTIFIED BY "MasterUserPassword";
85
ImageId: F19-x86_64-cfntools
86
InstanceType: {'Fn::FindInMap': [DBInstanceToInstance,
87
{Ref: DBInstanceClass}, Instance]}
88
KeyName: {Ref: KeyName}
89
SecurityGroups: [{"Ref" : "ServerSecurityGroup"}]
93
- 'AWS::StackName': {Ref: 'AWS::StackName'}
94
'AWS::Region': {Ref: 'AWS::Region'}
95
MasterUserPassword: {Ref: MasterUserPassword}
96
WaitHandle: {Ref: WaitHandle}
105
/opt/aws/bin/cfn-signal -e 1 -r \"$1\" 'WaitHandle'
108
/opt/aws/bin/cfn-init -s AWS::StackName -r DatabaseInstance --region AWS::Region || error_exit 'Failed to run cfn-init'
109
# Setup MySQL root password and create a user
110
mysqladmin -u root password 'MasterUserPassword'
111
mysql -u root --password='MasterUserPassword' < /tmp/db_setup.sql || error_exit 'Failed to setup mysql'
113
# Database setup completed, signal success
114
/opt/aws/bin/cfn-signal -e 0 -r "MySQL server setup complete" 'WaitHandle'
117
Type: AWS::CloudFormation::WaitConditionHandle
119
Type: AWS::CloudFormation::WaitCondition
120
DependsOn: DatabaseInstance
122
Handle: {Ref: WaitHandle}
126
Endpoint.Address: {'Fn::GetAtt': [DatabaseInstance, PublicIp]}
127
Endpoint.Port: {Ref: Port}