~ubuntu-branches/ubuntu/saucy/heat/saucy

« back to all changes in this revision

Viewing changes to templates/WordPress_Single_Instance_With_HA_AccessPolicy.template

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Yolanda Robla, Chuck Short
  • Date: 2013-07-22 16:22:29 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130722162229-zzvfu40id94ii0hc
Tags: 2013.2~b2-0ubuntu1
[ Yolanda Robla ]
* debian/tests: added autopkg tests

[ Chuck Short ]
* New upstream release
* debian/control:
  - Add python-pbr to build-depends.
  - Add python-d2to to build-depends.
  - Dropped python-argparse.
  - Add python-six to build-depends.
  - Dropped python-sendfile.
  - Dropped python-nose.
  - Added testrepository.
  - Added python-testtools.
* debian/rules: Run testrepository instead of nosetets.
* debian/patches/removes-lxml-version-limitation-from-pip-requires.patch: Dropped
  no longer needed.
* debian/patches/fix-package-version-detection-when-building-doc.patch: Dropped
  no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
  "AWSTemplateFormatVersion" : "2010-09-09",
3
 
 
4
 
  "Description" : "AWS CloudFormation Sample Template WordPress_Multi_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs two instances: one running a WordPress deployment and the other using a local MySQL database to store the data.",
5
 
 
6
 
  "Parameters" : {
7
 
 
8
 
    "KeyName" : {
9
 
      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
10
 
      "Type" : "String"
11
 
    },
12
 
 
13
 
    "InstanceType" : {
14
 
      "Description" : "WebServer EC2 instance type",
15
 
      "Type" : "String",
16
 
      "Default" : "m1.large",
17
 
      "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ],
18
 
      "ConstraintDescription" : "must be a valid EC2 instance type."
19
 
    },
20
 
 
21
 
    "DBName": {
22
 
      "Default": "wordpress",
23
 
      "Description" : "The WordPress database name",
24
 
      "Type": "String",
25
 
      "MinLength": "1",
26
 
      "MaxLength": "64",
27
 
      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
28
 
      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
29
 
    },
30
 
 
31
 
    "DBUsername": {
32
 
      "Default": "admin",
33
 
      "NoEcho": "true",
34
 
      "Description" : "The WordPress database admin account username",
35
 
      "Type": "String",
36
 
      "MinLength": "1",
37
 
      "MaxLength": "16",
38
 
      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
39
 
      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
40
 
    },
41
 
 
42
 
    "DBPassword": {
43
 
      "Default": "admin",
44
 
      "NoEcho": "true",
45
 
      "Description" : "The WordPress database admin account password",
46
 
      "Type": "String",
47
 
      "MinLength": "1",
48
 
      "MaxLength": "41",
49
 
      "AllowedPattern" : "[a-zA-Z0-9]*",
50
 
      "ConstraintDescription" : "must contain only alphanumeric characters."
51
 
    },
52
 
 
53
 
    "DBRootPassword": {
54
 
      "Default": "admin",
55
 
      "NoEcho": "true",
56
 
      "Description" : "Root password for MySQL",
57
 
      "Type": "String",
58
 
      "MinLength": "1",
59
 
      "MaxLength": "41",
60
 
      "AllowedPattern" : "[a-zA-Z0-9]*",
61
 
      "ConstraintDescription" : "must contain only alphanumeric characters."
62
 
    },
63
 
    "LinuxDistribution": {
64
 
      "Default": "F17",
65
 
      "Description" : "Distribution of choice",
66
 
      "Type": "String",
67
 
      "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ]
68
 
    },
69
 
    "HupPollInterval": {
70
 
      "Default": "1",
71
 
      "Description" : "Interval for cfn-hup",
72
 
      "Type": "String"
73
 
    }
74
 
  },
75
 
 
76
 
  "Mappings" : {
77
 
    "AWSInstanceType2Arch" : {
78
 
      "t1.micro"    : { "Arch" : "32" },
79
 
      "m1.small"    : { "Arch" : "32" },
80
 
      "m1.large"    : { "Arch" : "64" },
81
 
      "m1.xlarge"   : { "Arch" : "64" },
82
 
      "m2.xlarge"   : { "Arch" : "64" },
83
 
      "m2.2xlarge"  : { "Arch" : "64" },
84
 
      "m2.4xlarge"  : { "Arch" : "64" },
85
 
      "c1.medium"   : { "Arch" : "32" },
86
 
      "c1.xlarge"   : { "Arch" : "64" },
87
 
      "cc1.4xlarge" : { "Arch" : "64" }
88
 
    },
89
 
    "DistroArch2AMI": {
90
 
      "F18"      : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" },
91
 
      "F17"      : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" },
92
 
      "U10"      : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" },
93
 
      "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" },
94
 
      "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" },
95
 
      "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" }
96
 
    }
97
 
  },
98
 
 
99
 
  "Resources" : {
100
 
    "CfnUser" : {
101
 
      "Type" : "AWS::IAM::User",
102
 
      "Properties" : {
103
 
        "Policies" : [ { "Ref": "WebServerAccessPolicy"} ]
104
 
      }
105
 
    },
106
 
    "WebServerAccessPolicy" : {
107
 
      "Type" : "OS::Heat::AccessPolicy",
108
 
      "Properties" : {
109
 
        "AllowedResources" : [ "WikiDatabase" ]
110
 
      }
111
 
    },
112
 
    "WebServerKeys" : {
113
 
      "Type" : "AWS::IAM::AccessKey",
114
 
      "Properties" : {
115
 
        "UserName" : {"Ref": "CfnUser"}
116
 
      }
117
 
    },
118
 
    "WebServerRestartPolicy" : {
119
 
      "Type" : "OS::Heat::HARestarter",
120
 
      "Properties" : {
121
 
        "InstanceId" : { "Ref" : "WikiDatabase" }
122
 
      }
123
 
    },
124
 
    "HttpFailureAlarm": {
125
 
     "Type": "AWS::CloudWatch::Alarm",
126
 
     "Properties": {
127
 
        "AlarmDescription": "Restart the WikiDatabase if httpd fails > 3 times in 10 minutes",
128
 
        "MetricName": "ServiceFailure",
129
 
        "Namespace": "system/linux",
130
 
        "Statistic": "SampleCount",
131
 
        "Period": "300",
132
 
        "EvaluationPeriods": "1",
133
 
        "Threshold": "2",
134
 
        "AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ],
135
 
        "ComparisonOperator": "GreaterThanThreshold"
136
 
      }
137
 
    },
138
 
    "WikiDatabase": {
139
 
      "Type": "AWS::EC2::Instance",
140
 
      "Metadata" : {
141
 
        "AWS::CloudFormation::Init" : {
142
 
          "config" : {
143
 
            "files" : {
144
 
              "/etc/cfn/cfn-credentials" : {
145
 
                "content" : { "Fn::Join" : ["", [
146
 
                  "AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n",
147
 
                  "AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys",
148
 
                                    "SecretAccessKey"]}, "\n"
149
 
                ]]},
150
 
                "mode"    : "000400",
151
 
                "owner"   : "root",
152
 
                "group"   : "root"
153
 
              },
154
 
 
155
 
              "/etc/cfn/cfn-hup.conf" : {
156
 
                "content" : { "Fn::Join" : ["", [
157
 
                  "[main]\n",
158
 
                  "stack=", { "Ref" : "AWS::StackName" }, "\n",
159
 
                  "credential-file=/etc/cfn/cfn-credentials\n",
160
 
                  "region=", { "Ref" : "AWS::Region" }, "\n",
161
 
                  "interval=", { "Ref" : "HupPollInterval" }, "\n"
162
 
                ]]},
163
 
                "mode"    : "000400",
164
 
                "owner"   : "root",
165
 
                "group"   : "root"
166
 
              },
167
 
 
168
 
              "/etc/cfn/notify-on-httpd-restarted" : {
169
 
                "content" : { "Fn::Join" : ["", [
170
 
                "#!/bin/sh\n",
171
 
                "/opt/aws/bin/cfn-push-stats --watch ",
172
 
                { "Ref" : "HttpFailureAlarm" },
173
 
                " --service-failure\n"
174
 
                ]]},
175
 
                "mode"    : "000700",
176
 
                "owner"   : "root",
177
 
                "group"   : "root"
178
 
              },
179
 
 
180
 
              "/tmp/cfn-hup-crontab.txt" : {
181
 
                "content" : { "Fn::Join" : ["", [
182
 
                "MAIL=\"\"\n",
183
 
                "\n",
184
 
                "* * * * * /opt/aws/bin/cfn-hup -f\n"
185
 
                ]]},
186
 
                "mode"    : "000600",
187
 
                "owner"   : "root",
188
 
                "group"   : "root"
189
 
              },
190
 
 
191
 
              "/tmp/setup.mysql" : {
192
 
                "content" : { "Fn::Join" : ["", [
193
 
                "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
194
 
                "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
195
 
                ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n",
196
 
                "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
197
 
                "FLUSH PRIVILEGES;\n",
198
 
                "EXIT\n"
199
 
                  ]]},
200
 
                "mode"  : "000644",
201
 
                "owner" : "root",
202
 
                "group" : "root"
203
 
              },
204
 
 
205
 
              "/etc/cfn/hooks.conf" : {
206
 
                "content": { "Fn::Join" : ["", [
207
 
                  "[cfn-http-restarted]\n",
208
 
                  "triggers=service.restarted\n",
209
 
                  "path=Resources.WikiDatabase.Metadata\n",
210
 
                  "action=/etc/cfn/notify-on-httpd-restarted\n",
211
 
                  "runas=root\n"
212
 
                ]]},
213
 
                "mode"    : "000400",
214
 
                "owner"   : "root",
215
 
                "group"   : "root"
216
 
              }
217
 
            },
218
 
            "packages" : {
219
 
              "yum" : {
220
 
                "cronie"       : [],
221
 
                "mysql"        : [],
222
 
                "mysql-server" : [],
223
 
                "httpd"        : [],
224
 
                "wordpress"    : []
225
 
              }
226
 
            },
227
 
            "services" : {
228
 
              "systemd" : {
229
 
                "mysqld"   : { "enabled" : "true", "ensureRunning" : "true" },
230
 
                "httpd"    : { "enabled" : "true", "ensureRunning" : "true" },
231
 
                "crond"    : { "enabled" : "true", "ensureRunning" : "true" }
232
 
              }
233
 
            }
234
 
          }
235
 
        }
236
 
      },
237
 
      "Properties": {
238
 
        "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" },
239
 
                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
240
 
        "InstanceType"   : { "Ref" : "InstanceType" },
241
 
        "KeyName"        : { "Ref" : "KeyName" },
242
 
        "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
243
 
          "#!/bin/bash -v\n",
244
 
          "# Helper function\n",
245
 
          "function error_exit\n",
246
 
          "{\n",
247
 
          "  /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
248
 
          "  exit 1\n",
249
 
          "}\n",
250
 
 
251
 
          "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
252
 
          " -r WikiDatabase ",
253
 
          " --access-key ", { "Ref" : "WebServerKeys" },
254
 
          " --secret-key ", {"Fn::GetAtt": ["WebServerKeys", "SecretAccessKey"]},
255
 
          " --region ", { "Ref" : "AWS::Region" },
256
 
          " || error_exit 'Failed to run cfn-init'\n",
257
 
 
258
 
          "# Setup MySQL root password and create a user\n",
259
 
          "mysqladmin -u root password '", { "Ref" : "DBRootPassword" },
260
 
          "' || error_exit 'Failed to initialize root password'\n",
261
 
 
262
 
          "mysql -u root --password='", { "Ref" : "DBRootPassword" },
263
 
          "' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n",
264
 
 
265
 
          "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n",
266
 
          "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" },
267
 
          "/ --e s/username_here/", { "Ref" : "DBUsername" },
268
 
          "/ --e s/password_here/", { "Ref" : "DBPassword" },
269
 
          "/ /usr/share/wordpress/wp-config.php\n",
270
 
 
271
 
          "systemctl restart httpd.service\n",
272
 
 
273
 
          "# install cfn-hup crontab\n",
274
 
          "crontab /tmp/cfn-hup-crontab.txt\n",
275
 
 
276
 
          "# All is well so signal success\n",
277
 
          "/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '",
278
 
          { "Ref" : "WaitHandle" }, "'\n"
279
 
        ]]}}
280
 
      }
281
 
    },
282
 
 
283
 
    "WaitHandle" : {
284
 
      "Type" : "AWS::CloudFormation::WaitConditionHandle"
285
 
    },
286
 
 
287
 
    "WaitCondition" : {
288
 
      "Type" : "AWS::CloudFormation::WaitCondition",
289
 
      "DependsOn" : "WikiDatabase",
290
 
      "Properties" : {
291
 
        "Handle" : {"Ref" : "WaitHandle"},
292
 
        "Count" : "1",
293
 
        "Timeout" : "600"
294
 
      }
295
 
    }
296
 
  },
297
 
 
298
 
  "Outputs" : {
299
 
    "WebsiteURL" : {
300
 
      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] },
301
 
      "Description" : "URL for Wordpress wiki"
302
 
    }
303
 
  }
304
 
}