~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to etc/heat/templates/AWS_RDS_DBInstance.yaml

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-03 09:43:04 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20131003094304-k2c4qcsfn7cv6eos
Tags: 2013.2~rc1-0ubuntu1
* New upstream release.
* debian/control: Dropped python-d2to1 build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
HeatTemplateFormatVersion: '2012-12-12'
 
2
Description: 'Builtin AWS::RDS::DBInstance'
 
3
Parameters:
 
4
  AllocatedStorage:
 
5
    Type: String
 
6
  DBInstanceClass:
 
7
    Type: String
 
8
  DBName:
 
9
    Type: String
 
10
  DBSecurityGroups:
 
11
    Type: CommaDelimitedList
 
12
    Default: ''
 
13
  Engine:
 
14
    Type: String
 
15
    AllowedValues: ['MySQL']
 
16
  MasterUsername:
 
17
    Type: String
 
18
  MasterUserPassword:
 
19
    Type: String
 
20
  Port:
 
21
    Type: String
 
22
    Default: '3306'
 
23
  KeyName:
 
24
    Type: String
 
25
    Default: ''
 
26
 
 
27
Mappings:
 
28
  DBInstanceToInstance:
 
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}
 
35
 
 
36
Resources:
 
37
  ServerSecurityGroup:
 
38
    Type: AWS::EC2::SecurityGroup
 
39
    Properties:
 
40
      GroupDescription: 'Enable SSH access'
 
41
      SecurityGroupIngress:
 
42
      - IpProtocol: icmp
 
43
        FromPort: '-1'
 
44
        ToPort: '-1'
 
45
        CidrIp: '0.0.0.0/0'
 
46
      - IpProtocol: tcp
 
47
        FromPort: '22'
 
48
        ToPort : '22'
 
49
        CidrIp : '0.0.0.0/0'
 
50
      - IpProtocol: tcp
 
51
        FromPort: {Ref: Port}
 
52
        ToPort : {Ref: Port}
 
53
        CidrIp : '0.0.0.0/0'
 
54
  DatabaseInstance:
 
55
    Type: AWS::EC2::Instance
 
56
    Metadata:
 
57
      AWS::CloudFormation::Init:
 
58
        config:
 
59
          files:
 
60
            /tmp/db_setup.sql:
 
61
              content:
 
62
                'Fn::Replace':
 
63
                - DBName: {Ref: DBName}
 
64
                  MasterUserPassword: {Ref: MasterUserPassword}
 
65
                  MasterUsername: {Ref: MasterUsername}
 
66
                - |
 
67
                  CREATE DATABASE DBName;
 
68
                  GRANT ALL PRIVILEGES ON DBName.* TO "MasterUsername"@"%"
 
69
                  IDENTIFIED BY "MasterUserPassword";
 
70
                  FLUSH PRIVILEGES;
 
71
                  EXIT
 
72
              mode: '000644'
 
73
              owner: root
 
74
              group: root
 
75
          packages:
 
76
            yum:
 
77
              mariadb: []
 
78
              mariadb-server: []
 
79
          services:
 
80
            systemd:
 
81
              mysqld:
 
82
                enabled: true
 
83
                ensureRunning: true
 
84
    Properties:
 
85
      ImageId: F19-x86_64-cfntools
 
86
      InstanceType: {'Fn::FindInMap': [DBInstanceToInstance,
 
87
                                       {Ref: DBInstanceClass}, Instance]}
 
88
      KeyName: {Ref: KeyName}
 
89
      SecurityGroups: [{"Ref" : "ServerSecurityGroup"}]
 
90
      UserData:
 
91
        Fn::Base64:
 
92
          Fn::Replace:
 
93
          - 'AWS::StackName': {Ref: 'AWS::StackName'}
 
94
            'AWS::Region': {Ref: 'AWS::Region'}
 
95
            MasterUserPassword: {Ref: MasterUserPassword}
 
96
            WaitHandle: {Ref: WaitHandle}
 
97
          - |
 
98
            #!/bin/bash -v
 
99
            #
 
100
            iptables -F
 
101
 
 
102
            # Helper function
 
103
            function error_exit
 
104
            {
 
105
              /opt/aws/bin/cfn-signal -e 1 -r \"$1\" 'WaitHandle'
 
106
              exit 1
 
107
            }
 
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'
 
112
 
 
113
            # Database setup completed, signal success
 
114
            /opt/aws/bin/cfn-signal -e 0 -r "MySQL server setup complete" 'WaitHandle'
 
115
 
 
116
  WaitHandle:
 
117
    Type: AWS::CloudFormation::WaitConditionHandle
 
118
  WaitCondition:
 
119
    Type: AWS::CloudFormation::WaitCondition
 
120
    DependsOn: DatabaseInstance
 
121
    Properties:
 
122
      Handle: {Ref: WaitHandle}
 
123
      Timeout: "600"
 
124
 
 
125
Outputs:
 
126
  Endpoint.Address: {'Fn::GetAtt': [DatabaseInstance, PublicIp]}
 
127
  Endpoint.Port: {Ref: Port}