]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add a simple single instance wordpress template
authorAngus Salkeld <asalkeld@redhat.com>
Wed, 14 Mar 2012 23:40:02 +0000 (10:40 +1100)
committerAngus Salkeld <asalkeld@redhat.com>
Wed, 14 Mar 2012 23:40:02 +0000 (10:40 +1100)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
templates/WordPress_Single_Instance.template [new file with mode: 0644]

diff --git a/templates/WordPress_Single_Instance.template b/templates/WordPress_Single_Instance.template
new file mode 100644 (file)
index 0000000..f77c877
--- /dev/null
@@ -0,0 +1,253 @@
+{\r
+  "AWSTemplateFormatVersion" : "2010-09-09",\r
+\r
+  "Description" : "AWS CloudFormation Sample Template WordPress_Single_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs a single-instance WordPress deployment using a local MySQL database to store the data. It demonstrates using the AWS CloudFormation bootstrap scripts to install packages and files at instance launch time. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",\r
+\r
+  "Parameters" : {\r
+\r
+    "KeyName" : {\r
+      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",\r
+      "Type" : "String"\r
+    },\r
+\r
+    "InstanceType" : {\r
+      "Description" : "WebServer EC2 instance type",\r
+      "Type" : "String",\r
+      "Default" : "m1.small",\r
+      "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ],\r
+      "ConstraintDescription" : "must be a valid EC2 instance type."\r
+    },\r
+\r
+    "DBName": {\r
+      "Default": "wordpress",\r
+      "Description" : "The WordPress database name",\r
+      "Type": "String",\r
+      "MinLength": "1",\r
+      "MaxLength": "64",\r
+      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",\r
+      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."\r
+    },\r
+\r
+    "DBUsername": {\r
+      "Default": "admin",\r
+      "NoEcho": "true",\r
+      "Description" : "The WordPress database admin account username",\r
+      "Type": "String",\r
+      "MinLength": "1",\r
+      "MaxLength": "16",\r
+      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",\r
+      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."\r
+    },\r
+\r
+    "DBPassword": {\r
+      "Default": "admin",\r
+      "NoEcho": "true",\r
+      "Description" : "The WordPress database admin account password",\r
+      "Type": "String",\r
+      "MinLength": "1",\r
+      "MaxLength": "41",\r
+      "AllowedPattern" : "[a-zA-Z0-9]*",\r
+      "ConstraintDescription" : "must contain only alphanumeric characters."\r
+    },\r
+\r
+    "DBRootPassword": {\r
+      "NoEcho": "true",\r
+      "Description" : "Root password for MySQL",\r
+      "Type": "String",\r
+      "MinLength": "1",\r
+      "MaxLength": "41",\r
+      "AllowedPattern" : "[a-zA-Z0-9]*",\r
+      "ConstraintDescription" : "must contain only alphanumeric characters."\r
+    }\r
+  },\r
+\r
+  "Mappings" : {\r
+    "AWSInstanceType2Arch" : {\r
+      "t1.micro"    : { "Arch" : "32" },\r
+      "m1.small"    : { "Arch" : "32" },\r
+      "m1.large"    : { "Arch" : "64" },\r
+      "m1.xlarge"   : { "Arch" : "64" },\r
+      "m2.xlarge"   : { "Arch" : "64" },\r
+      "m2.2xlarge"  : { "Arch" : "64" },\r
+      "m2.4xlarge"  : { "Arch" : "64" },\r
+      "c1.medium"   : { "Arch" : "32" },\r
+      "c1.xlarge"   : { "Arch" : "64" },\r
+      "cc1.4xlarge" : { "Arch" : "64" }\r
+    },\r
+    "AWSRegionArch2AMI" : {\r
+      "us-east-1"      : { "32" : "ami-7f418316", "64" : "ami-7341831a" },\r
+      "us-west-1"      : { "32" : "ami-951945d0", "64" : "ami-971945d2" },\r
+      "us-west-2"      : { "32" : "ami-16fd7026", "64" : "ami-10fd7020" },\r
+      "eu-west-1"      : { "32" : "ami-24506250", "64" : "ami-20506254" },\r
+      "sa-east-1"      : { "32" : "ami-3e3be423", "64" : "ami-3c3be421" },\r
+      "ap-southeast-1" : { "32" : "ami-74dda626", "64" : "ami-7edda62c" },\r
+      "ap-northeast-1" : { "32" : "ami-dcfa4edd", "64" : "ami-e8fa4ee9" }\r
+    }\r
+  },\r
+\r
+  "Resources" : {\r
+\r
+    "CfnUser" : {\r
+      "Type" : "AWS::IAM::User",\r
+      "Properties" : {\r
+        "Path": "/",\r
+        "Policies": [{\r
+          "PolicyName": "root",\r
+          "PolicyDocument": { "Statement":[{\r
+            "Effect":"Allow",\r
+            "Action":"cloudformation:DescribeStackResource",\r
+            "Resource":"*"\r
+          }]}\r
+        }]\r
+      }\r
+    },\r
+\r
+    "HostKeys" : {\r
+      "Type" : "AWS::IAM::AccessKey",\r
+      "Properties" : {\r
+        "UserName" : {"Ref": "CfnUser"}\r
+      }\r
+    },\r
+\r
+    "WebServer": {\r
+      "Type": "AWS::EC2::Instance",\r
+      "Metadata" : {\r
+        "AWS::CloudFormation::Init" : {\r
+          "config" : {\r
+            "packages" : {\r
+              "yum" : {\r
+                "httpd"        : [],\r
+                "php"          : [],\r
+                "php-mysql"    : [],\r
+                "mysql"        : [],\r
+                "mysql-server" : [],\r
+                "mysql-devel"  : [],\r
+                "mysql-libs"   : []\r
+              }\r
+            },\r
+\r
+            "sources" : {\r
+              "/var/www/html" : "http://wordpress.org/latest.tar.gz"\r
+            },\r
+\r
+            "files" : {\r
+              "/tmp/setup.mysql" : {\r
+                "content" : { "Fn::Join" : ["", [\r
+                  "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",\r
+                  "CREATE USER '", { "Ref" : "DBUsername" }, "'@'localhost' IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",\r
+                  "GRANT ALL ON ", { "Ref" : "DBName" }, ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost';\n",\r
+                  "FLUSH PRIVILEGES;\n"\r
+                  ]]},\r
+                "mode"  : "000644",\r
+                "owner" : "root",\r
+                "group" : "root"\r
+              },\r
+\r
+              "/var/www/html/wordpress/wp-config.php" : {\r
+                "content" : { "Fn::Join" : ["", [\r
+                  "<?php\n",\r
+                  "define('DB_NAME',          '", {"Ref" : "DBName"}, "');\n",\r
+                  "define('DB_USER',          '", {"Ref" : "DBUsername"}, "');\n",\r
+                  "define('DB_PASSWORD',      '", {"Ref" : "DBPassword" }, "');\n",\r
+                  "define('DB_HOST',          'localhost');\n",\r
+                  "define('DB_CHARSET',       'utf8');\n",\r
+                  "define('DB_COLLATE',       '');\n",\r
+                  "define('AUTH_KEY',         'f@A17vs{ mO0}:&I,6SB.QzV`E?!`/tN5:~GZX%=@ZA%!_T0-]9>g]4ll6~,6G|R');\n",\r
+                  "define('SECURE_AUTH_KEY',  'gTFTI|~rYHY)|mlu:Cv7RN]GQ^3ngyUbw;L0o!12]0c-ispR<-yt3qj]xjquz^&9');\n",\r
+                  "define('LOGGED_IN_KEY',    'Jd:HG9M)1p5t2<v~+R-vd{p-Q*|*RB^&PUI{vIrydAEEiV!{HS{jN:nErCmLv`p}');\n",\r
+                  "define('NONCE_KEY',        '4aMj4KZV;,Gu7(B|qOCve[c5?*J5x1+x93i:Ey6hh/6jXh+V_{V4+hw!qE^d*U,-');\n",\r
+                  "define('AUTH_SALT',        '_Y_&8m)FH)Cns)8}Yb8b88KDSn:p1#p(qBa<~VW&Y1v}P.*9/8S8@P`{mkNxV lC');\n",\r
+                  "define('SECURE_AUTH_SALT', '%nG3Ag41^Lew5c86,#zbN:yPFs.GA5a)z5*:Oce1>v6uF~D`,.o1pzS)F8[bM9i[');\n",\r
+                  "define('LOGGED_IN_SALT',   '~K<y+Ly+_Ww1~dtq>;rSQ^+{P5/k|=!]k%RXAF-Y@XMY6GSp+wJ5{(|rCzaWjZ%/');\n",\r
+                  "define('NONCE_SALT',       ',Bs_*Y9:b/1Z:apVLHtz35uim|okkA,b|Jt[-&Nla=T{<l_#D?~6Tj-.2.]FonI~');\n",\r
+                  "define('WPLANG'            , '');\n",\r
+                  "define('WP_DEBUG'          , false);\n",\r
+                  "$table_prefix  = 'wp_';\n",\r
+                  "if ( !defined('ABSPATH') )\n",\r
+                  "    define('ABSPATH', dirname(__FILE__) . '/');\n",\r
+                  "require_once(ABSPATH . 'wp-settings.php');\n"\r
+                ]] },\r
+                "mode" : "000644",\r
+                "owner" : "root",\r
+                "group" : "root"\r
+              }\r
+            },\r
+            "services" : {\r
+              "sysvinit" : {\r
+                "httpd"    : { "enabled" : "true", "ensureRunning" : "true" },\r
+                "mysqld"   : { "enabled" : "true", "ensureRunning" : "true" },\r
+                "sendmail" : { "enabled" : "false", "ensureRunning" : "false" }\r
+              }\r
+            }\r
+          }\r
+        }\r
+      },\r
+      "Properties": {\r
+        "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },\r
+                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },\r
+        "InstanceType"   : { "Ref" : "InstanceType" },\r
+        "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],\r
+        "KeyName"        : { "Ref" : "KeyName" },\r
+        "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [\r
+          "#!/bin/bash -v\n",\r
+          "yum update -y aws-cfn-bootstrap\n",\r
+\r
+          "# Helper function\n",\r
+          "function error_exit\n",\r
+          "{\n",\r
+          "  /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",\r
+          "  exit 1\n",\r
+          "}\n",\r
+\r
+          "# Install Apache Web Server, MySQL, PHP and WordPress\n",\r
+          "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r WebServer ",\r
+          "    --access-key ",  { "Ref" : "HostKeys" },\r
+          "    --secret-key ", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]},\r
+          "    --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",\r
+\r
+          "# Setup MySQL root password and create a user\n",\r
+          "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "' || error_exit 'Failed to initialize root password'\n",\r
+          "mysql -u root --password='", { "Ref" : "DBRootPassword" }, "' < /tmp/setup.mysql || error_exit 'Failed to create database user'\n",\r
+\r
+          "# Setup correct file ownership\n",\r
+          "chown -R apache:apache /var/www/html/wordpress\n",\r
+\r
+          "# All is well so signal success\n",\r
+          "/opt/aws/bin/cfn-signal -e 0 -r \"WordPress setup complete\" '", { "Ref" : "WaitHandle" }, "'\n"\r
+\r
+        ]]}}\r
+      }\r
+    },\r
+\r
+    "WaitHandle" : {\r
+      "Type" : "AWS::CloudFormation::WaitConditionHandle"\r
+    },\r
+\r
+    "WaitCondition" : {\r
+      "Type" : "AWS::CloudFormation::WaitCondition",\r
+      "DependsOn" : "WebServer",\r
+      "Properties" : {\r
+        "Handle" : {"Ref" : "WaitHandle"},\r
+        "Timeout" : "300"\r
+      }\r
+    },\r
+\r
+    "WebServerSecurityGroup" : {\r
+      "Type" : "AWS::EC2::SecurityGroup",\r
+      "Properties" : {\r
+        "GroupDescription" : "Enable HTTP access via port 80 and SSH access",\r
+        "SecurityGroupIngress" : [\r
+          {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"},\r
+          {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"}\r
+        ]\r
+      }\r
+    }\r
+  },\r
+\r
+  "Outputs" : {\r
+    "WebsiteURL" : {\r
+      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicDnsName" ]}, "/wordpress"]] },\r
+      "Description" : "WordPress Website"\r
+    }\r
+  }\r
+}\r