From de67cecf926d660057ad9f72f87ae159829e54bf Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Sat, 27 Apr 2013 13:51:55 +0100 Subject: [PATCH] Initial import of heat repo content Initial import of content which currently exists in the main heat repo Change-Id: I326801f7e7274a1f8b41d4e0be733da0f80ebbcc --- LICENSE | 176 +++++++++ README.rst | 11 + cfn/AutoScalingMultiAZSample.template | 296 +++++++++++++++ cfn/AutoScalingMultiAZSample.yaml | 283 +++++++++++++++ cfn/EC2WithEBSSample.template | 114 ++++++ cfn/HAProxy_Single_Instance.template | 130 +++++++ cfn/InstanceGroup.template | 56 +++ cfn/MySQL_Single_Instance.template | 166 +++++++++ cfn/OpenShift.template | 291 +++++++++++++++ cfn/PuppetMaster_Single_Instance.template | 227 ++++++++++++ cfn/Quantum.template | 100 ++++++ cfn/Quantum.yaml | 72 ++++ cfn/Quantum_floating.template | 52 +++ cfn/README | 93 +++++ cfn/Rails_Single_Instance.template | 254 +++++++++++++ cfn/S3_Single_Instance.template | 36 ++ cfn/Swift.template | 35 ++ cfn/WordPress_2_Instances.template | 179 ++++++++++ cfn/WordPress_2_Instances_With_EBS.template | 221 ++++++++++++ ...ordPress_2_Instances_With_EBS_EIP.template | 257 ++++++++++++++ cfn/WordPress_And_Http.template | 138 +++++++ cfn/WordPress_Composed_Instances.template | 155 ++++++++ cfn/WordPress_NoKey.template | 144 ++++++++ cfn/WordPress_Single_Instance.template | 149 ++++++++ cfn/WordPress_Single_Instance.yaml | 161 +++++++++ ...ordPress_Single_Instance_With_EBS.template | 192 ++++++++++ ...ress_Single_Instance_With_EBS_EIP.template | 217 +++++++++++ ...ordPress_Single_Instance_With_EIP.template | 177 +++++++++ ...WordPress_Single_Instance_With_HA.template | 296 +++++++++++++++ cfn/WordPress_Single_Instance_With_HA.yaml | 336 ++++++++++++++++++ ...gle_Instance_With_HA_AccessPolicy.template | 305 ++++++++++++++++ ...ordPress_Single_Instance_With_IHA.template | 270 ++++++++++++++ ...ress_Single_Instance_With_Quantum.template | 192 ++++++++++ cfn/WordPress_Single_Instance_deb.template | 138 +++++++ cfn/WordPress_Single_Instance_gold.template | 150 ++++++++ cfn/WordPress_Single_Instance_puppet.template | 234 ++++++++++++ cfn/WordPress_With_LB.template | 171 +++++++++ cfn/WordPress_With_RDS.template | 170 +++++++++ cfn/getting_started.template | 29 ++ tools/cfn-json2yaml | 50 +++ tools/fetch-cloudformation-examples | 48 +++ 41 files changed, 6771 insertions(+) create mode 100644 LICENSE create mode 100644 README.rst create mode 100644 cfn/AutoScalingMultiAZSample.template create mode 100644 cfn/AutoScalingMultiAZSample.yaml create mode 100644 cfn/EC2WithEBSSample.template create mode 100644 cfn/HAProxy_Single_Instance.template create mode 100644 cfn/InstanceGroup.template create mode 100644 cfn/MySQL_Single_Instance.template create mode 100644 cfn/OpenShift.template create mode 100644 cfn/PuppetMaster_Single_Instance.template create mode 100644 cfn/Quantum.template create mode 100644 cfn/Quantum.yaml create mode 100644 cfn/Quantum_floating.template create mode 100644 cfn/README create mode 100644 cfn/Rails_Single_Instance.template create mode 100644 cfn/S3_Single_Instance.template create mode 100644 cfn/Swift.template create mode 100644 cfn/WordPress_2_Instances.template create mode 100644 cfn/WordPress_2_Instances_With_EBS.template create mode 100644 cfn/WordPress_2_Instances_With_EBS_EIP.template create mode 100644 cfn/WordPress_And_Http.template create mode 100644 cfn/WordPress_Composed_Instances.template create mode 100644 cfn/WordPress_NoKey.template create mode 100644 cfn/WordPress_Single_Instance.template create mode 100644 cfn/WordPress_Single_Instance.yaml create mode 100644 cfn/WordPress_Single_Instance_With_EBS.template create mode 100644 cfn/WordPress_Single_Instance_With_EBS_EIP.template create mode 100644 cfn/WordPress_Single_Instance_With_EIP.template create mode 100644 cfn/WordPress_Single_Instance_With_HA.template create mode 100644 cfn/WordPress_Single_Instance_With_HA.yaml create mode 100644 cfn/WordPress_Single_Instance_With_HA_AccessPolicy.template create mode 100644 cfn/WordPress_Single_Instance_With_IHA.template create mode 100644 cfn/WordPress_Single_Instance_With_Quantum.template create mode 100644 cfn/WordPress_Single_Instance_deb.template create mode 100644 cfn/WordPress_Single_Instance_gold.template create mode 100644 cfn/WordPress_Single_Instance_puppet.template create mode 100644 cfn/WordPress_With_LB.template create mode 100644 cfn/WordPress_With_RDS.template create mode 100644 cfn/getting_started.template create mode 100755 tools/cfn-json2yaml create mode 100755 tools/fetch-cloudformation-examples diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..68c771a0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..c46635d1 --- /dev/null +++ b/README.rst @@ -0,0 +1,11 @@ +============== +Heat Templates +============== + +Heat is a service to orchestrate multiple composite cloud applications using +templates + +This repository provides: +* Example templates which demonstrate core Heat functionality +* Related image-building templates +* Template-related scripts and conversion tools diff --git a/cfn/AutoScalingMultiAZSample.template b/cfn/AutoScalingMultiAZSample.template new file mode 100644 index 00000000..cd9fb051 --- /dev/null +++ b/cfn/AutoScalingMultiAZSample.template @@ -0,0 +1,296 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "AWS CloudFormation Sample Template", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.small", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "64" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "CfnUser" : { + "Type" : "AWS::IAM::User" + }, + "WebServerKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "CfnUser"} + } + }, + "WebServerGroup" : { + "Type" : "AWS::AutoScaling::AutoScalingGroup", + "Properties" : { + "AvailabilityZones" : { "Fn::GetAZs" : ""}, + "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, + "MinSize" : "1", + "MaxSize" : "3", + "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ] + } + }, + + "WebServerScaleUpPolicy" : { + "Type" : "AWS::AutoScaling::ScalingPolicy", + "Properties" : { + "AdjustmentType" : "ChangeInCapacity", + "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, + "Cooldown" : "60", + "ScalingAdjustment" : "1" + } + }, + + "WebServerScaleDownPolicy" : { + "Type" : "AWS::AutoScaling::ScalingPolicy", + "Properties" : { + "AdjustmentType" : "ChangeInCapacity", + "AutoScalingGroupName" : { "Ref" : "WebServerGroup" }, + "Cooldown" : "60", + "ScalingAdjustment" : "-1" + } + }, + + "MEMAlarmHigh": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "AlarmDescription": "Scale-up if MEM > 50% for 1 minute", + "MetricName": "MemoryUtilization", + "Namespace": "system/linux", + "Statistic": "Average", + "Period": "60", + "EvaluationPeriods": "1", + "Threshold": "50", + "AlarmActions": [ { "Ref": "WebServerScaleUpPolicy" } ], + "Dimensions": [ + { + "Name": "AutoScalingGroupName", + "Value": { "Ref": "WebServerGroup" } + } + ], + "ComparisonOperator": "GreaterThanThreshold" + } + }, + "MEMAlarmLow": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "AlarmDescription": "Scale-down if MEM < 15% for 1 minute", + "MetricName": "MemoryUtilization", + "Namespace": "system/linux", + "Statistic": "Average", + "Period": "60", + "EvaluationPeriods": "1", + "Threshold": "15", + "AlarmActions": [ { "Ref": "WebServerScaleDownPolicy" } ], + "Dimensions": [ + { + "Name": "AutoScalingGroupName", + "Value": { "Ref": "WebServerGroup" } + } + ], + "ComparisonOperator": "LessThanThreshold" + } + }, + + "ElasticLoadBalancer" : { + "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", + "Properties" : { + "AvailabilityZones" : { "Fn::GetAZs" : "" }, + "Listeners" : [ { + "LoadBalancerPort" : "80", + "InstancePort" : "80", + "Protocol" : "HTTP" + } ], + "HealthCheck" : { + "Target" : "HTTP:80/", + "HealthyThreshold" : "3", + "UnhealthyThreshold" : "5", + "Interval" : "30", + "Timeout" : "5" + } + } + }, + + "LaunchConfig" : { + "Type" : "AWS::AutoScaling::LaunchConfiguration", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "files" : { + "/etc/cfn/cfn-credentials" : { + "content" : { "Fn::Join" : ["", [ + "AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n", + "AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys", + "SecretAccessKey"]}, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + "/tmp/setup.mysql" : { + "content" : { "Fn::Join" : ["", [ + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, + ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n", + "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + "/tmp/stats-crontab.txt" : { + "content" : { "Fn::Join" : ["", [ + "MAIL=\"\"\n", + "\n", + "* * * * * /opt/aws/bin/cfn-push-stats --watch ", + { "Ref" : "MEMAlarmHigh" }, " --mem-util\n", + "* * * * * /opt/aws/bin/cfn-push-stats --watch ", + { "Ref" : "MEMAlarmLow" }, " --mem-util\n" + ]]}, + "mode" : "000600", + "owner" : "root", + "group" : "root" + } + }, + "packages" : { + "yum" : { + "python-psutil": [], + "cronie" : [], + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "crond" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r LaunchConfig ", + " --region ", { "Ref" : "AWS::Region" }, "\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + + "mysql -u root --password='", { "Ref" : "DBRootPassword" }, + "' < /tmp/setup.mysql\n", + + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, + "/ --e s/username_here/", { "Ref" : "DBUsername" }, + "/ --e s/password_here/", { "Ref" : "DBPassword" }, + "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n", + + "# install crontab\n", + "crontab /tmp/stats-crontab.txt\n" + ]]}} + } + } + }, + + "Outputs" : { + "URL" : { + "Description" : "The URL of the website", + "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}, "/wordpress"]] } + } + } +} diff --git a/cfn/AutoScalingMultiAZSample.yaml b/cfn/AutoScalingMultiAZSample.yaml new file mode 100644 index 00000000..9be35ded --- /dev/null +++ b/cfn/AutoScalingMultiAZSample.yaml @@ -0,0 +1,283 @@ +HeatTemplateFormatVersion: '2012-12-12' +Description: AWS CloudFormation Sample Template +Parameters: + KeyName: {Description: Name of an existing EC2 KeyPair + to enable SSH access to the instances, Type: String} + InstanceType: + Description: WebServer EC2 instance type + Type: String + Default: m1.small + AllowedValues: [t1.micro, m1.small, m1.large, m1.xlarge, m2.xlarge, + m2.2xlarge, m2.4xlarge, c1.medium, c1.xlarge, cc1.4xlarge] + ConstraintDescription: must be a valid EC2 instance type. + DBName: {Default: wordpress, Description: The + WordPress database name, Type: String, MinLength: '1', + MaxLength: '64', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBUsername: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account username, Type: String, + MinLength: '1', MaxLength: '16', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBPassword: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account password, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + DBRootPassword: {Default: admin, NoEcho: 'true', + Description: Root password for MySQL, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + LinuxDistribution: + Default: F17 + Description: Distribution of choice + Type: String + AllowedValues: [F18, F17, U10, RHEL-6.1, RHEL-6.2, RHEL-6.3] +Mappings: + AWSInstanceType2Arch: + t1.micro: {Arch: '32'} + m1.small: {Arch: '64'} + m1.large: {Arch: '64'} + m1.xlarge: {Arch: '64'} + m2.xlarge: {Arch: '64'} + m2.2xlarge: {Arch: '64'} + m2.4xlarge: {Arch: '64'} + c1.medium: {Arch: '32'} + c1.xlarge: {Arch: '64'} + cc1.4xlarge: {Arch: '64'} + DistroArch2AMI: + F18: {'32': F18-i386-cfntools, '64': F18-x86_64-cfntools} + F17: {'32': F17-i386-cfntools, '64': F17-x86_64-cfntools} + U10: {'32': U10-i386-cfntools, '64': U10-x86_64-cfntools} + RHEL-6.1: {'32': rhel61-i386-cfntools, '64': rhel61-x86_64-cfntools} + RHEL-6.2: {'32': rhel62-i386-cfntools, '64': rhel62-x86_64-cfntools} + RHEL-6.3: {'32': rhel63-i386-cfntools, '64': rhel63-x86_64-cfntools} +Resources: + CfnUser: {Type: 'AWS::IAM::User'} + WebServerKeys: + Type: AWS::IAM::AccessKey + Properties: + UserName: {Ref: CfnUser} + WebServerGroup: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + AvailabilityZones: {'Fn::GetAZs': ''} + LaunchConfigurationName: {Ref: LaunchConfig} + MinSize: '1' + MaxSize: '3' + LoadBalancerNames: + - {Ref: ElasticLoadBalancer} + WebServerScaleUpPolicy: + Type: AWS::AutoScaling::ScalingPolicy + Properties: + AdjustmentType: ChangeInCapacity + AutoScalingGroupName: {Ref: WebServerGroup} + Cooldown: '60' + ScalingAdjustment: '1' + WebServerScaleDownPolicy: + Type: AWS::AutoScaling::ScalingPolicy + Properties: + AdjustmentType: ChangeInCapacity + AutoScalingGroupName: {Ref: WebServerGroup} + Cooldown: '60' + ScalingAdjustment: '-1' + MEMAlarmHigh: + Type: AWS::CloudWatch::Alarm + Properties: + AlarmDescription: Scale-up if MEM > 50% for 1 minute + MetricName: MemoryUtilization + Namespace: system/linux + Statistic: Average + Period: '60' + EvaluationPeriods: '1' + Threshold: '50' + AlarmActions: + - {Ref: WebServerScaleUpPolicy} + Dimensions: + - Name: AutoScalingGroupName + Value: {Ref: WebServerGroup} + ComparisonOperator: GreaterThanThreshold + MEMAlarmLow: + Type: AWS::CloudWatch::Alarm + Properties: + AlarmDescription: Scale-down if MEM < 15% for 1 minute + MetricName: MemoryUtilization + Namespace: system/linux + Statistic: Average + Period: '60' + EvaluationPeriods: '1' + Threshold: '15' + AlarmActions: + - {Ref: WebServerScaleDownPolicy} + Dimensions: + - Name: AutoScalingGroupName + Value: {Ref: WebServerGroup} + ComparisonOperator: LessThanThreshold + ElasticLoadBalancer: + Type: AWS::ElasticLoadBalancing::LoadBalancer + Properties: + AvailabilityZones: {'Fn::GetAZs': ''} + Listeners: + - {LoadBalancerPort: '80', InstancePort: '80', + Protocol: HTTP} + HealthCheck: {Target: 'HTTP:80/', HealthyThreshold: '3', + UnhealthyThreshold: '5', Interval: '30', Timeout: '5'} + LaunchConfig: + Type: AWS::AutoScaling::LaunchConfiguration + Metadata: + AWS::CloudFormation::Init: + config: + files: + /etc/cfn/cfn-credentials: + content: + Fn::Join: + - '' + - - AWSAccessKeyId= + - {Ref: WebServerKeys} + - ' + + ' + - AWSSecretKey= + - Fn::GetAtt: [WebServerKeys, SecretAccessKey] + - ' + + ' + mode: '000400' + owner: root + group: root + /tmp/setup.mysql: + content: + Fn::Join: + - '' + - - 'CREATE DATABASE ' + - {Ref: DBName} + - '; + + ' + - 'GRANT ALL PRIVILEGES ON ' + - {Ref: DBName} + - .* TO ' + - {Ref: DBUsername} + - '''@''localhost'' + + ' + - IDENTIFIED BY ' + - {Ref: DBPassword} + - '''; + + ' + - 'FLUSH PRIVILEGES; + + ' + - 'EXIT + + ' + mode: '000644' + owner: root + group: root + /tmp/stats-crontab.txt: + content: + Fn::Join: + - '' + - - 'MAIL="" + + ' + - ' + + ' + - '* * * * * /opt/aws/bin/cfn-push-stats --watch ' + - {Ref: MEMAlarmHigh} + - ' --mem-util + + ' + - '* * * * * /opt/aws/bin/cfn-push-stats --watch ' + - {Ref: MEMAlarmLow} + - ' --mem-util + + ' + mode: '000600' + owner: root + group: root + packages: + yum: + python-psutil: [] + cronie: [] + mysql: [] + mysql-server: [] + httpd: [] + wordpress: [] + services: + systemd: + mysqld: {enabled: 'true', ensureRunning: 'true'} + httpd: {enabled: 'true', ensureRunning: 'true'} + crond: {enabled: 'true', ensureRunning: 'true'} + Properties: + ImageId: + Fn::FindInMap: + - DistroArch2AMI + - {Ref: LinuxDistribution} + - Fn::FindInMap: + - AWSInstanceType2Arch + - {Ref: InstanceType} + - Arch + InstanceType: {Ref: InstanceType} + KeyName: {Ref: KeyName} + UserData: + Fn::Base64: + Fn::Join: + - '' + - - '#!/bin/bash -v + + ' + - '/opt/aws/bin/cfn-init -s ' + - {Ref: 'AWS::StackName'} + - ' -r LaunchConfig ' + - ' --region ' + - {Ref: 'AWS::Region'} + - ' + + ' + - '# Setup MySQL root password and create a user + + ' + - mysqladmin -u root password ' + - {Ref: DBRootPassword} + - ''' + + ' + - mysql -u root --password=' + - {Ref: DBRootPassword} + - ''' < /tmp/setup.mysql + + ' + - 'sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf + + ' + - sed --in-place --e s/database_name_here/ + - {Ref: DBName} + - / --e s/username_here/ + - {Ref: DBUsername} + - / --e s/password_here/ + - {Ref: DBPassword} + - '/ /usr/share/wordpress/wp-config.php + + ' + - 'systemctl restart httpd.service + + ' + - '# install crontab + + ' + - 'crontab /tmp/stats-crontab.txt + + ' +Outputs: + URL: + Description: The URL of the website + Value: + Fn::Join: + - '' + - - http:// + - Fn::GetAtt: [ElasticLoadBalancer, DNSName] + - /wordpress + diff --git a/cfn/EC2WithEBSSample.template b/cfn/EC2WithEBSSample.template new file mode 100644 index 00000000..120bc5f4 --- /dev/null +++ b/cfn/EC2WithEBSSample.template @@ -0,0 +1,114 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "This template creates an instance and an EBS Volume.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "VolumeSize" : { + "Description" : "WikiDatabase Volume size", + "Type" : "Number", + "Default" : "1", + "MinValue" : "1", + "MaxValue" : "1024", + "ConstraintDescription" : "must be between 1 and 1024 Gb." + }, + + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "Ec2Instance" : { + "Type" : "AWS::EC2::Instance", + "Properties" : { + "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ], + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "Volumes" : [ + { "VolumeId" : { "Ref" : "NewVolume" }, + "Device" : "/dev/vdc1" + } + ] + } + }, + + "InstanceSecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable SSH access via port 22", + "SecurityGroupIngress" : [ { + "IpProtocol" : "tcp", + "FromPort" : "22", + "ToPort" : "22", + "CidrIp" : "0.0.0.0/0" + }] + } + }, + + "NewVolume" : { + "Type" : "AWS::EC2::Volume", + "Properties" : { + "Size" : { "Ref" : "VolumeSize" }, + "AvailabilityZone" : { "Fn::GetAtt" : [ "Ec2Instance", "AvailabilityZone" ]} + } + } + }, + + "Outputs" : { + "InstanceId" : { + "Description" : "InstanceId of the newly created EC2 instance", + "Value" : { "Ref" : "Ec2Instance" } + }, + "PublicIP" : { + "Description" : "Public IP address of the newly created EC2 instance", + "Value" : { "Fn::GetAtt" : [ "Ec2Instance", "PublicIp" ] } + }, + "PublicDNS" : { + "Description" : "Public DNSName of the newly created EC2 instance", + "Value" : { "Fn::GetAtt" : [ "Ec2Instance", "PublicDnsName" ] } + } + } +} diff --git a/cfn/HAProxy_Single_Instance.template b/cfn/HAProxy_Single_Instance.template new file mode 100644 index 00000000..b9564ee9 --- /dev/null +++ b/cfn/HAProxy_Single_Instance.template @@ -0,0 +1,130 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + + "Description": "A load balancer instance running a local HAproxy", + + "Parameters": { + + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type": "String" + }, + + "Server1": { + "Description": "Server1 to load balance ", + "Type": "String" + }, + + "InstanceType": { + "Description": "HAProxy server EC2 instance type", + "Default": "m1.small", + "Type": "String", + "AllowedValues": [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription": "must be a valid EC2 instance type." + }, + + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources": { + "LoadBalancerInstance": { + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "config": { + "packages": { + "yum": { + "haproxy" : [] + } + }, + "services": { + "systemd": { + "haproxy" : { "enabled": "true", "ensureRunning": "true" } + } + }, + "files": { + "/etc/haproxy/haproxy.cfg": { + "content": { "Fn::Join": ["", [ + " global\n", + " daemon\n", + " maxconn 256\n", + "\n", + " defaults\n", + " mode http\n", + " timeout connect 5000ms\n", + " timeout client 50000ms\n", + " timeout server 50000ms\n", + "\n", + " frontend http-in\n", + " bind *:80\n", + " default_backend servers\n", + "\n", + " backend servers\n", + " balance roundrobin\n", + " option http-server-close\n", + " option forwardfor\n", + " server server1 ", { "Ref" : "Server1" }, "\n" + ]]}, + "mode": "000644", + "owner": "root", + "group": "root" + } + } + } + } + }, + "Properties": { + "ImageId" : { + "Fn::FindInMap" : [ "DistroArch2AMI", + { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", + { "Ref" : "InstanceType" }, + "Arch" ] } ] + }, + "InstanceType": { "Ref": "InstanceType" }, + "KeyName": { "Ref": "KeyName" }, + "UserData": { "Fn::Base64": { "Fn::Join": ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init -s ", + { "Ref": "AWS::StackName" }, + " --region ", { "Ref": "AWS::Region" }, "\n" + ]]}} + } + } + }, + + "Outputs": { + "PublicIp": { + "Value": { "Fn::GetAtt": [ "LoadBalancerInstance", "PublicIp" ] }, + "Description": "instance IP" + } + } +} diff --git a/cfn/InstanceGroup.template b/cfn/InstanceGroup.template new file mode 100644 index 00000000..9148b8cb --- /dev/null +++ b/cfn/InstanceGroup.template @@ -0,0 +1,56 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "Template to create multiple instances.", + + "Parameters" : { + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + "InstanceType" : { + "Description" : "Instance type", + "Type" : "String", + "Default" : "m1.small", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + "ImageId" : { + "Description" : "Name of the image to use", + "Type" : "String", + "Default" : "F17-x86_64-cfntools" + }, + "NumInstances": { + "Default": "1", + "MinValue": "1", + "MaxValue": "100", + "Description" : "Number of instances to create", + "Type": "Number" + } + }, + + "Resources" : { + "JobServerGroup" : { + "Type" : "OS::Heat::InstanceGroup", + "Properties" : { + "LaunchConfigurationName" : { "Ref" : "JobServerConfig" }, + "Size" : {"Ref": "NumInstances"}, + "AvailabilityZones" : { "Fn::GetAZs" : "" } + } + }, + + "JobServerConfig" : { + "Type" : "AWS::AutoScaling::LaunchConfiguration", + "Properties": { + "ImageId" : { "Ref" : "ImageId" }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "NovaSchedulerHints": [ {"Key": "part", "Value": "long"}, + {"Key": "ready", "Value": "short"} ], + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n" + ]]}} + } + } + } +} diff --git a/cfn/MySQL_Single_Instance.template b/cfn/MySQL_Single_Instance.template new file mode 100644 index 00000000..24e9b9ed --- /dev/null +++ b/cfn/MySQL_Single_Instance.template @@ -0,0 +1,166 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "A Database instance running a local MySQL server", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "Database server EC2 instance type", + "Type" : "String", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Description" : "The database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "NoEcho": "true", + "Description" : "The database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "NoEcho": "true", + "Description" : "The database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ], + "Default": "F17" + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "MySqlDatabaseServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "MySqlWaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r MySqlDatabaseServer ", + " --region ", { "Ref" : "AWS::Region" }, + " || error_exit 'Failed to run cfn-init'\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"%\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"MySQL Database setup complete\" '", + { "Ref" : "MySqlWaitHandle" }, "'\n" + ]]}} + } + }, + + "MySqlWaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "MySqlWaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "MySqlDatabaseServer", + "Properties" : { + "Handle" : {"Ref" : "MySqlWaitHandle"}, + "Timeout" : "600" + } + } + + }, + + "Outputs" : { + "PublicIp": { + "Value": { "Fn::GetAtt" : [ "MySqlDatabaseServer", "PublicIp" ] }, + "Description": "Database server IP" + } + } +} diff --git a/cfn/OpenShift.template b/cfn/OpenShift.template new file mode 100644 index 00000000..45e4ab91 --- /dev/null +++ b/cfn/OpenShift.template @@ -0,0 +1,291 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Template for setting up an OpenShift Origin environment", + "Parameters": { + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern": "[-_ a-zA-Z0-9]*" + }, + "Prefix": { + "Description": "Your DNS Prefix", + "Type": "String", + "Default": "example.com" + }, + "DnsSecKey": { + "Description": "Bind DNS-Sec TSIG key", + "Type": "String", + "NoEcho": "TRUE" + }, + "UpstreamDNS": { + "Description": "Upstream DNS server", + "Type": "String", + "Default": "8.8.8.8" + } + }, + "Mappings": { + "JeosImages": { + "Broker": { + "Image": "F18-x86_64-openshift-origin-broker-cfntools" + }, + "Node": { + "Image": "F18-x86_64-openshift-origin-node-cfntools" + } + } + }, + "Resources": { + "OpenShiftOriginSecurityGroup": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Standard firewall rules", + "SecurityGroupIngress": [ + { + "IpProtocol": "udp", + "FromPort": "53", + "ToPort": "53", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "53", + "ToPort": "53", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "22", + "ToPort": "22", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "80", + "ToPort": "80", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "443", + "ToPort": "443", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "8000", + "ToPort": "8000", + "CidrIp": "0.0.0.0/0" + }, + { + "IpProtocol": "tcp", + "FromPort": "8443", + "ToPort": "8443", + "CidrIp": "0.0.0.0/0" + } + ] + } + }, + "brokerWaitHandle": { + "Type": "AWS::CloudFormation::WaitConditionHandle" + }, + "brokerWaitCondition": { + "Type": "AWS::CloudFormation::WaitCondition", + "DependsOn": "BrokerInstance", + "Properties": { + "Handle": { + "Ref": "brokerWaitHandle" + }, + "Timeout": "6000" + } + }, + "BrokerInstance": { + "Type": "AWS::EC2::Instance", + "Properties": { + "ImageId": { + "Fn::FindInMap": [ "JeosImages", "Broker", "Image" ] + }, + "InstanceType": "m1.medium", + "KeyName": { + "Ref": "KeyName" + }, + "SecurityGroups": [ + { + "Ref": "OpenShiftOriginSecurityGroup" + } + ], + "Tags": [ + { + "Key": "Name", + "Value": { + "Fn::Join": [ "-", [ "openshift", { "Ref": "Prefix" }, "broker" ] ] + } + } + ], + "UserData": { + "Fn::Base64": { + "Fn::Join": [ + "", + [ + "#!/bin/bash -x", "\n", + "cat << EOF > /root/configure.pp\n", + "\\$my_hostname=\"\\${ec2_instance_id}.", { "Ref": "Prefix" }, "\"\n", + "file { \"update network settings - hostname\":", "\n", + " path => \"/etc/sysconfig/network\",\n", + " content => \"NETWORKING=yes\\nNETWORKING_IPV6=no\\nHOSTNAME=\\${my_hostname}\"\n", + "}\n", + "exec { \"set hostname\":\n", + " command => \"/bin/hostname \\${my_hostname} ; echo \\${my_hostname} > /etc/hostname\"\n", + "}\n", + "augeas{ \"etc hosts setup\" :\n", + " context => \"/files/etc/hosts\",\n", + " changes => [\n", + " \"set 01/ipaddr \\${ipaddress}\",\n", + " \"set 01/canonical \\${my_hostname}\",\n", + " ],\n", + "}\n", + "augeas{ \"network peerdns setup\" :\n", + " context => \"/files/etc/sysconfig/network-scripts/ifcfg-eth0\",\n", + " changes => [\n", + " \"set PEERDNS no\",\n", + " ],\n", + "}\n", + "class { \"openshift_origin\" :\n", + " node_fqdn => \\$my_hostname,\n", + " cloud_domain => \"", { "Ref": "Prefix" }, "\",", "\n", + " named_tsig_priv_key => \"", { "Ref": "DnsSecKey" }, "\",", "\n", + " dns_servers => [\"", { "Ref": "UpstreamDNS" }, "\"],\n", + " os_unmanaged_users => [\"ec2-user\"],\n", + " enable_network_services => true,\n", + " configure_firewall => false,\n", + " configure_ntp => true,\n", + " configure_activemq => true,\n", + " configure_qpid => false,\n", + " configure_mongodb => true,\n", + " configure_named => true,\n", + " configure_broker => true,\n", + " configure_console => true,\n", + " configure_node => false,\n", + " development_mode => true,\n", + " named_ipaddress => \\$ipaddress,\n", + " mongodb_fqdn => \\$my_hostname,\n", + " mq_fqdn => \\$my_hostname,\n", + " broker_fqdn => \\$my_hostname,\n", + "}\n", + "EOF\n", + "puppet module install openshift/openshift_origin", "\n", + "puppet apply --verbose /root/configure.pp | tee /var/log/configure_openshift.log", "\n", + "service network restart | tee /var/log/configure_openshift.log;\n", + "service mongod restart | tee /var/log/configure_openshift.log;\n", + "service activemq restart | tee /var/log/configure_openshift.log;\n", + "service httpd restart | tee /var/log/configure_openshift.log;\n", + "service openshift-broker restart | tee /var/log/configure_openshift.log;\n", + "service openshift-console restart | tee /var/log/configure_openshift.log;\n", + "service named restart | tee /var/log/configure_openshift.log;\n", + "export EC2_INSTANCE_ID=\"`facter ec2_instance_id`\"\n", + "export IP_ADDRESS=\"`facter ipaddress`\"\n", + "cat << _EOF > /root/nsupdate.cmd\n", + "key ", { "Ref": "Prefix" }," ",{ "Ref": "DnsSecKey" },"\n", + "server ${IP_ADDRESS} 53\n", + "update delete ${EC2_INSTANCE_ID}.",{ "Ref": "Prefix" }," A\n", + "update add ${EC2_INSTANCE_ID}.",{ "Ref": "Prefix" }," 180 A ${IP_ADDRESS}\n", + "send\n", + "_EOF\n", + "cat /root/nsupdate.cmd | nsupdate\n", + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"Broker setup complete\" \"", { "Ref": "brokerWaitHandle" }, "\"\n" + ] + ] + } + } + } + }, + "NodeInstance": { + "Type": "AWS::EC2::Instance", + "DependsOn": "brokerWaitCondition", + "Properties": { + "ImageId": { + "Fn::FindInMap": [ "JeosImages", "Node", "Image" ] + }, + "InstanceType": "m1.medium", + "KeyName": { "Ref": "KeyName" }, + "SecurityGroups": [ { "Ref": "OpenShiftOriginSecurityGroup" } ], + "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "-", [ "openshift", { "Ref": "Prefix" }, "node" ] ] } } ], + "UserData": { + "Fn::Base64": { + "Fn::Join": [ + "", + [ + "#!/bin/bash -x", "\n", + "cat << EOF > /root/configure.pp\n", + "\\$my_hostname=\"\\${ec2_instance_id}.", { "Ref": "Prefix" }, "\"\n", + "file { \"update network settings - hostname\":", "\n", + " path => \"/etc/sysconfig/network\",\n", + " content => \"NETWORKING=yes\\nNETWORKING_IPV6=no\\nHOSTNAME=\\${my_hostname}\"\n", + "}\n", + "exec { \"set hostname\":\n", + " command => \"/bin/hostname \\${my_hostname} ; echo \\${my_hostname} > /etc/hostname\"\n", + "}\n", + "augeas{ \"etc hosts setup\" :\n", + " context => \"/files/etc/hosts\",\n", + " changes => [\n", + " \"set 01/ipaddr \\${ipaddress}\",\n", + " \"set 01/canonical \\${my_hostname}\",\n", + " ],\n", + "}\n", + "augeas{ \"network peerdns setup\" :\n", + " context => \"/files/etc/sysconfig/network-scripts/ifcfg-eth0\",\n", + " changes => [\n", + " \"set PEERDNS no\",\n", + " ],\n", + "}\n", + "class { \"openshift_origin\" :\n", + " node_fqdn => \\$my_hostname,\n", + " cloud_domain => \"", { "Ref": "Prefix" }, "\",", "\n", + " named_tsig_priv_key => \"", { "Ref": "DnsSecKey" }, "\",", "\n", + " dns_servers => [\"", { "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }, "\"],\n", + " os_unmanaged_users => [\"ec2-user\"],\n", + " enable_network_services => true,\n", + " configure_firewall => false,\n", + " configure_ntp => true,\n", + " configure_activemq => false,\n", + " configure_qpid => false,\n", + " configure_mongodb => false,\n", + " configure_named => false,\n", + " configure_broker => false,\n", + " configure_console => false,\n", + " configure_node => true,\n", + " development_mode => true,\n", + " named_ipaddress => \"", { "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }, "\",\n", + " mongodb_fqdn => \"", { "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }, "\",\n", + " mq_fqdn => \"", { "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }, "\",\n", + " broker_fqdn => \"", { "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }, "\",\n", + "}\n", + "EOF\n", + "puppet apply --verbose /root/configure.pp | tee /var/log/configure_openshift.log;", "\n", + "service network restart | tee /var/log/configure_openshift.log;\n", + "service cgconfig restart | tee /var/log/configure_openshift.log;\n", + "service cgred restart | tee /var/log/configure_openshift.log;\n", + "service openshift-cgroups restart | tee /var/log/configure_openshift.log;\n", + "service openshift-node-web-proxy restart | tee /var/log/configure_openshift.log;\n", + "service mcollective restart | tee /var/log/configure_openshift.log;\n", + "service httpd restart | tee /var/log/configure_openshift.log;\n", + "service sshd restart | tee /var/log/configure_openshift.log;\n", + "export EC2_INSTANCE_ID=\"`facter ec2_instance_id`\"\n", + "export IP_ADDRESS=\"`facter ipaddress`\"\n", + "cat << _EOF > /root/nsupdate.cmd\n", + "key ", { "Ref": "Prefix" }," ",{ "Ref": "DnsSecKey" },"\n", + "server ",{ "Fn::GetAtt": [ "BrokerInstance", "PublicIp" ] }," 53\n", + "update delete ${EC2_INSTANCE_ID}.",{ "Ref": "Prefix" }," A\n", + "update add ${EC2_INSTANCE_ID}.",{ "Ref": "Prefix" }," 180 A ${IP_ADDRESS}\n", + "send\n", + "_EOF\n", + "cat /root/nsupdate.cmd | nsupdate\n" + ] + ] + } + } + } + } + } +} diff --git a/cfn/PuppetMaster_Single_Instance.template b/cfn/PuppetMaster_Single_Instance.template new file mode 100644 index 00000000..32d9d35d --- /dev/null +++ b/cfn/PuppetMaster_Single_Instance.template @@ -0,0 +1,227 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description": "Sample template to bring up Puppet Master instance that can be used to bootstrap and manage Puppet Clients. The Puppet Master is populated from an embedded template that defines the set of applications to load. **WARNING** This template creates one or more Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template.", + + "Parameters" : { + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the PuppetMaster", + "Type" : "String" + }, + "ContentManifest" : { + "Default" : "/wordpress/: { include wordpress }", + "Description" : "Manifest of roles to add to nodes.pp", + "Type" : "String" + }, + "ContentLocation" : { + "Default" : "https://s3.amazonaws.com/cloudformation-examples/wordpress-puppet-config.tar.gz", + "Description" : "Location of package (Zip, GZIP or Git repository URL) that includes the PuppetMaster content", + "Type" : "String" + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + "Resources" : { + "CFNInitUser" : { + "Type" : "AWS::IAM::User" + }, + + "CFNKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : { "Ref": "CFNInitUser" } + } + }, + + "PuppetMasterInstance" : { + "Type" : "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "puppet" : [], + "puppet-server" : [], + "ruby-devel" : [], + "gcc" : [], + "make" : [], + "rubygems" : [] + }, + "rubygems" : { + "json" : [] + } + }, + "sources" : { + "/etc/puppet" : { "Ref" : "ContentLocation" } + }, + "files" : { + "/etc/yum.repos.d/epel.repo" : { + "source" : "https://s3.amazonaws.com/cloudformation-examples/enable-epel-on-amazon-linux-ami", + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + "/etc/puppet/autosign.conf" : { + "content" : "*.internal\n", + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + }, + "/etc/puppet/fileserver.conf" : { + "content" : "[modules]\n allow *.internal\n", + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + }, + "/etc/puppet/puppet.conf" : { + "content" : { "Fn::Join" : ["", [ + "[main]\n", + " logdir=/var/log/puppet\n", + " rundir=/var/run/puppet\n", + " ssldir=$vardir/ssl\n", + " pluginsync=true\n", + "[agent]\n", + " classfile=$vardir/classes.txt\n", + " localconfig=$vardir/localconfig\n"]] }, + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + "/etc/puppet/modules/cfn/manifests/init.pp" : { + "content" : "class cfn {}", + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + }, + "/etc/puppet/modules/cfn/lib/facter/cfn.rb" : { + "source" : "https://s3.amazonaws.com/cloudformation-examples/cfn-facter-plugin.rb", + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + }, + "/etc/puppet/manifests/nodes.pp" : { + "content" : {"Fn::Join" : ["", [ + "node basenode {\n", + " include cfn\n", + "}\n", + "node /^.*internal$/ inherits basenode {\n", + " case $cfn_roles {\n", + " ", { "Ref" : "ContentManifest" }, "\n", + " }\n", + "}\n"]]}, + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + }, + "/etc/puppet/manifests/site.pp" : { + "content" : "import \"nodes\"\n", + "mode" : "100644", + "owner" : "root", + "group" : "wheel" + } + }, + "services" : { + "sysvinit" : { + "puppetmaster" : { + "enabled" : "true", + "ensureRunning" : "true" + } + } + } + } + } + }, + "Properties" : { + "InstanceType" : { "Ref" : "InstanceType" }, + "SecurityGroups" : [ { "Ref" : "PuppetGroup" } ], + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash\n", + "yum update -y aws-cfn-bootstrap\n", + + "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, + " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetMasterInstance ", + " --access-key ", { "Ref" : "CFNKeys" }, + " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", + "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetMasterWaitHandle" }, "'\n"]]}} + } + }, + + "EC2SecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Group for clients to communicate with Puppet Master" + } + }, + + "PuppetGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Group for puppet communication", + "SecurityGroupIngress" : [ + { "IpProtocol" : "tcp", "FromPort" : "8140", "ToPort" : "8140", "CidrIp": "0.0.0.0/0"}, + { "IpProtocol" : "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": "0.0.0.0/0" } + ] + } + }, + + "PuppetMasterWaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "PuppetMasterWaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "PuppetMasterInstance", + "Properties" : { + "Handle" : { "Ref" : "PuppetMasterWaitHandle" }, + "Timeout" : "600" + } + } + }, + + "Outputs" : { + "PuppetMasterDNSName" : { + "Value" : { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] }, + "Description" : "DNS Name of PuppetMaster" + }, + "PuppetClientSecurityGroup" : { + "Value" : { "Ref" : "EC2SecurityGroup" }, + "Description" : "Clients of the Puppet Master should be part of this security group" + } + } +} diff --git a/cfn/Quantum.template b/cfn/Quantum.template new file mode 100644 index 00000000..1fd32985 --- /dev/null +++ b/cfn/Quantum.template @@ -0,0 +1,100 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "Template to test Quantum resources", + + "Parameters" : { + + }, + + "Resources" : { + "network": { + "Type": "OS::Quantum::Net", + "Properties": { + "name": "the_network" + } + }, + "unnamed_network": { + "Type": "OS::Quantum::Net" + }, + "admin_down_network": { + "Type": "OS::Quantum::Net", + "Properties": { + "admin_state_up": false + } + }, + + "subnet": { + "Type": "OS::Quantum::Subnet", + "Properties": { + "network_id": { "Ref" : "network" }, + "ip_version": 4, + "cidr": "10.0.3.0/24", + "allocation_pools": [{"start": "10.0.3.20", "end": "10.0.3.150"}] + } + }, + + "port": { + "Type": "OS::Quantum::Port", + "Properties": { + "device_id": "d6b4d3a5-c700-476f-b609-1493dd9dadc0", + "name": "port1", + "network_id": { "Ref" : "network" }, + "fixed_ips": [{ + "subnet_id": { "Ref" : "subnet" }, + "ip_address": "10.0.3.21" + }] + } + }, + + "router": { + "Type": "OS::Quantum::Router" + }, + + "router_interface": { + "Type": "OS::Quantum::RouterInterface", + "Properties": { + "router_id": { "Ref" : "router" }, + "subnet_id": { "Ref" : "subnet" } + } + } + }, + "Outputs" : { + "the_network_status" : { + "Value" : { "Fn::GetAtt" : [ "network", "status" ]}, + "Description" : "Status of network" + }, + "port_device_owner" : { + "Value" : { "Fn::GetAtt" : [ "port", "device_owner" ]}, + "Description" : "Device owner of the port" + }, + "port_fixed_ips" : { + "Value" : { "Fn::GetAtt" : [ "port", "fixed_ips" ]}, + "Description" : "Fixed IPs of the port" + }, + "port_mac_address" : { + "Value" : { "Fn::GetAtt" : [ "port", "mac_address" ]}, + "Description" : "MAC address of the port" + }, + "port_status" : { + "Value" : { "Fn::GetAtt" : [ "port", "status" ]}, + "Description" : "Status of the port" + }, + "port_show" : { + "Value" : { "Fn::GetAtt" : [ "port", "show" ]}, + "Description" : "All attributes for port" + }, + "subnet_show" : { + "Value" : { "Fn::GetAtt" : [ "subnet", "show" ]}, + "Description" : "All attributes for subnet" + }, + "network_show" : { + "Value" : { "Fn::GetAtt" : [ "network", "show" ]}, + "Description" : "All attributes for network" + }, + "router_show" : { + "Value" : { "Fn::GetAtt" : [ "router", "show" ]}, + "Description" : "All attributes for router" + } + } +} \ No newline at end of file diff --git a/cfn/Quantum.yaml b/cfn/Quantum.yaml new file mode 100644 index 00000000..3015a4f5 --- /dev/null +++ b/cfn/Quantum.yaml @@ -0,0 +1,72 @@ +HeatTemplateFormatVersion: '2012-12-12' +Description: Template to test Quantum resources +Resources: + network: + Type: OS::Quantum::Net + Properties: {name: the_network} + unnamed_network: + Type: 'OS::Quantum::Net' + admin_down_network: + Type: OS::Quantum::Net + Properties: {admin_state_up: false} + subnet: + Type: OS::Quantum::Subnet + Properties: + network_id: {Ref: network} + ip_version: 4 + cidr: 10.0.3.0/24 + allocation_pools: + - {end: 10.0.3.150, start: 10.0.3.20} + port: + Type: OS::Quantum::Port + Properties: + device_id: d6b4d3a5-c700-476f-b609-1493dd9dadc0 + name: port1 + network_id: {Ref: network} + fixed_ips: + - subnet_id: {Ref: subnet} + ip_address: 10.0.3.21 + router: + Type: 'OS::Quantum::Router' + router_interface: + Type: OS::Quantum::RouterInterface + Properties: + router_id: {Ref: router} + subnet_id: {Ref: subnet} +Outputs: + the_network_status: + Value: + Fn::GetAtt: [network, status] + Description: Status of network + port_device_owner: + Value: + Fn::GetAtt: [port, device_owner] + Description: Device owner of the port + port_fixed_ips: + Value: + Fn::GetAtt: [port, fixed_ips] + Description: Fixed IPs of the port + port_mac_address: + Value: + Fn::GetAtt: [port, mac_address] + Description: MAC address of the port + port_status: + Value: + Fn::GetAtt: [port, status] + Description: Status of the port + port_show: + Value: + Fn::GetAtt: [port, show] + Description: All attributes for port + subnet_show: + Value: + Fn::GetAtt: [subnet, show] + Description: All attributes for subnet + network_show: + Value: + Fn::GetAtt: [network, show] + Description: All attributes for network + router_show: + Value: + Fn::GetAtt: [router, show] + Description: All attributes for router diff --git a/cfn/Quantum_floating.template b/cfn/Quantum_floating.template new file mode 100644 index 00000000..3aedbbc5 --- /dev/null +++ b/cfn/Quantum_floating.template @@ -0,0 +1,52 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "Template to test Quantum resources", + + "Parameters" : { + + "external_network" : { + "Description" : "UUID of an existing external network", + "Type" : "String" + }, + "internal_network" : { + "Description" : "UUID of an existing internal network", + "Type" : "String" + }, + "internal_subnet" : { + "Description" : "UUID of an existing internal subnet", + "Type" : "String" + } + }, + + "Resources" : { + + "port_floating": { + "Type": "OS::Quantum::Port", + "Properties": { + "network_id": { "Ref" : "internal_network" }, + "fixed_ips": [{ + "subnet_id": { "Ref" : "internal_subnet" }, + "ip_address": "10.0.0.10" + }] + } + }, + + "floating_ip": { + "Type": "OS::Quantum::FloatingIP", + "Properties": { + "floating_network_id": { "Ref" : "external_network" } + } + }, + + "floating_ip_assoc": { + "Type": "OS::Quantum::FloatingIPAssociation", + "Properties": { + "floatingip_id": { "Ref" : "floating_ip" }, + "port_id": { "Ref" : "port_floating" } + } + } + }, + "Outputs" : { + } +} diff --git a/cfn/README b/cfn/README new file mode 100644 index 00000000..e8a0f2d5 --- /dev/null +++ b/cfn/README @@ -0,0 +1,93 @@ +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +- The gold templates: - +- The gold images contain no cfntools - +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- + +WordPress_Single_Instance_gold.template + - Creates a gold image wordpress single instance - not working + +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +- The cfntools templates: - +- The CFNTOOLS images contain analogs of AWS cfn tools for full orchestration - +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- + +******************************************************************************* +* INSECURE TEMPLATES * +* The following templates do not properly secure the mysql server and allow * +* any user to connect to the wordpress database. * +******************************************************************************* + +WordPress_2_Instances.template + - Creates a two instance wordpress/mysql server + Note: There is an instance for mysql and instance for wordpress + +WordPress_2_Instances_With_EBS.template + - Creates a two instance wordpress/mysql server with persistent volume + Note: There is an instance for mysql and instance for wordpress + +WordPress_Composed_Instances.template + - Creates a two instance wordpress/mysql server. + - The MySQL server is loaded as a nested template from the URL of the latest + MySQL_Single_Instance template on GitHub. + Note: There is an instance for mysql and instance for wordpress + +MySQL_Single_Instance.template + - Creates a single instance MySQL server, for use in template composition + +******************************************************************************* +* SECURE TEMPLATES * +* These templates either are single vm or use EIP and security groups to * +* secure the servers * +******************************************************************************* + +WordPress_Single_Instance.template + - Creates a single instance wordpress/mysql server + +WordPress_Single_Instance_With_EBS.template + - Creates a single instance wordpress/mysql server with EBS Volume + +WordPress_Single_Instance_With_EIP.template + - Creates a single instance wordpress/mysql server with EIP with full security + +WordPress_Single_Instance_With_EBS_EIP.template + - Creates a single instance wordpress/mysql server with EIP with full security + and EBS Volume + +WordPress_Single_Instance_deb.template + - Creates a single instance wordpress/mysql server, ubuntu based template + +WordPress_Single_Instance_puppet.template + - Creates a single instance wordpress/mysql server + - Uses the Puppet client to install server roles + +WordPress_Single_Instance_With_HA.template + - Creates a single instance wordpress/mysql server + - Includes configuration to use heat HA features + +PuppetMaster_Single_Instance.template + - Sample template to bring up a Puppet Master instance + +WordPress_2_Instances_With_EBS_EIP.template + - Creates a two instance wordpress/mysql server with persistent volume + - EIP with full security + Note: There is an instance for mysql and instance for wordpress + +Rails_Single_Instance.template +- Create a Ruby on Rails stack + +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +- Other templates: - +------------------------------------------------------------------------------- +------------------------------------------------------------------------------- + +getting_started.template + - Skeleton example template + +------------------------------------------------------------------------------- +- END OF TEMPLATES - +------------------------------------------------------------------------------- diff --git a/cfn/Rails_Single_Instance.template b/cfn/Rails_Single_Instance.template new file mode 100644 index 00000000..54ebebc2 --- /dev/null +++ b/cfn/Rails_Single_Instance.template @@ -0,0 +1,254 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "AWS CloudFormation Sample Template Rails_Single_Instance: Create a Ruby on Rails stack using a single EC2 instance with a local MySQL database for storage. This template demonstrates using the AWS CloudFormation bootstrap scripts to install the packages and files necessary to deploy the 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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[-_ a-zA-Z0-9]*", + "ConstraintDescription" : "can contain only alphanumeric characters, spaces, dashes and underscores." + }, + + "DBName": { + "Default": "MyDatabase", + "Description" : "MySQL database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "NoEcho": "true", + "Description" : "Username for MySQL database access", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "NoEcho": "true", + "Description" : "Password MySQL database access", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.small", + "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"], + "ConstraintDescription" : "must be a valid EC2 instance type." + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "64" }, + "m1.small" : { "Arch" : "64" }, + "m1.medium" : { "Arch" : "64" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "64" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64HVM" }, + "cc2.8xlarge" : { "Arch" : "64HVM" }, + "cg1.4xlarge" : { "Arch" : "64HVM" } + }, + + "AWSRegionArch2AMI" : { + "us-east-1" : { "32" : "ami-31814f58", "64" : "ami-1b814f72", "64HVM" : "ami-0da96764" }, + "us-west-2" : { "32" : "ami-38fe7308", "64" : "ami-30fe7300", "64HVM" : "NOT_YET_SUPPORTED" }, + "us-west-1" : { "32" : "ami-11d68a54", "64" : "ami-1bd68a5e", "64HVM" : "NOT_YET_SUPPORTED" }, + "eu-west-1" : { "32" : "ami-973b06e3", "64" : "ami-953b06e1", "64HVM" : "NOT_YET_SUPPORTED" }, + "ap-southeast-1" : { "32" : "ami-b4b0cae6", "64" : "F17-x86_64-cfntools", "64HVM" : "NOT_YET_SUPPORTED" }, + "ap-northeast-1" : { "32" : "ami-0644f007", "64" : "ami-0a44f00b", "64HVM" : "NOT_YET_SUPPORTED" }, + "sa-east-1" : { "32" : "ami-3e3be423", "64" : "ami-3c3be421", "64HVM" : "NOT_YET_SUPPORTED" } + } + }, + + "Resources" : { + + "CfnUser" : { + "Type" : "AWS::IAM::User" + }, + + "HostKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "CfnUser"} + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "gcc-c++" : [], + "make" : [], + "ruby-devel" : [], + "rubygems" : [], + "mysql" : [], + "mysql-server" : [], + "mysql-devel" : [], + "mysql-libs" : [] + }, + + "rubygems" : { + "rack" : ["1.3.6"], + "execjs" : [], + "therubyracer" : [], + "rails" : [] + } + }, + + "sources" : { + "/home/ec2-user/sample" : "https://s3.amazonaws.com/cloudformation-examples/CloudFormationRailsSample.zip" + }, + + "files" : { + "/tmp/setup.mysql" : { + "content" : { "Fn::Join" : ["", [ + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n", + "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + + "/home/ec2-user/sample/config/database.yml" : { + "content" : { "Fn::Join" : ["", [ + "development:\n", + " adapter: mysql2\n", + " encoding: utf8\n", + " reconnect: false\n", + " pool: 5\n", + " database: ", { "Ref" : "DBName" }, "\n", + " username: ", { "Ref" : "DBUsername" }, "\n", + " password: ", { "Ref" : "DBPassword" }, "\n", + " socket: /var/lib/mysql/mysql.sock\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + } + }, + + "services" : { + "sysvinit" : { + "mysqld" : { + "enabled" : "true", + "ensureRunning" : "true" + } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "SecurityGroups" : [ {"Ref" : "FrontendGroup"} ], + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "yum update -y aws-cfn-bootstrap\n", + + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "# Install Rails packages\n", + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r WebServer ", + " --access-key Ref_HostKeys", + " --secret-key Fn_GetAtt_HostKeys_SecretAccessKey", + " --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "' || error_exit 'Failed to initialize root password'\n", + "mysql -u root --password='", { "Ref" : "DBRootPassword" }, "' < /tmp/setup.mysql || error_exit 'Failed to create database user'\n", + + "# Install anu other Gems, create the database and run a migration\n", + "cd /home/ec2-user/sample\n", + "bundle install || error_exit 'Failed to install bundle'\n", + "rake db:create || error_exit 'Failed to create database'\n", + "rake db:migrate || error_exit 'Failed to execute database migration'\n", + + "# Startup the rails server\n", + "rails server -d\n", + "echo \"cd /home/ec2-user/sample\" >> /etc/rc.local\n", + "echo \"rails server -d\" >> /etc/rc.local\n", + + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"Rails application setup complete\" '", { "Ref" : "WaitHandle" }, "'\n" + ]]}} + } + }, + + "WaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "WaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "WebServer", + "Properties" : { + "Handle" : {"Ref" : "WaitHandle"}, + "Timeout" : "1500" + } + }, + + "FrontendGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access via port 3000 plus SSH access", + "SecurityGroupIngress" : [ + {"IpProtocol" : "tcp", "FromPort" : "3000", "ToPort" : "3000", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} + ] + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, ":3000" ]] }, + "Description" : "URL for newly created Rails application" + } + } +} diff --git a/cfn/S3_Single_Instance.template b/cfn/S3_Single_Instance.template new file mode 100644 index 00000000..0c58ab6f --- /dev/null +++ b/cfn/S3_Single_Instance.template @@ -0,0 +1,36 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "Template to test S3 Bucket resources", + + "Resources" : { + "S3BucketWebsite" : { + "Type" : "AWS::S3::Bucket", + "Properties" : { + "AccessControl" : "PublicRead", + "WebsiteConfiguration" : { + "IndexDocument" : "index.html", + "ErrorDocument" : "error.html" + }, + "DeletionPolicy" : "Delete" + } + }, + "S3Bucket" : { + "Type" : "AWS::S3::Bucket", + "Properties" : { + "AccessControl" : "Private" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::GetAtt" : [ "S3Bucket", "WebsiteURL" ] }, + "Description" : "URL for website hosted on S3" + }, + "DomainName" : { + "Value" : { "Fn::GetAtt" : [ "S3Bucket", "DomainName" ] }, + "Description" : "Domain of S3 host" + } + } +} diff --git a/cfn/Swift.template b/cfn/Swift.template new file mode 100644 index 00000000..2ec17aed --- /dev/null +++ b/cfn/Swift.template @@ -0,0 +1,35 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "Template to test OS::Swift::Container resources", + + "Resources" : { + "SwiftContainerWebsite" : { + "Type" : "OS::Swift::Container", + "Properties" : { + "X-Container-Read" : ".r:*", + "X-Container-Meta" : { + "Web-Index" : "index.html", + "Web-Error" : "error.html" + }, + "DeletionPolicy" : "Delete" + } + }, + "SwiftContainer" : { + "Type" : "OS::Swift::Container", + "Properties" : { + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::GetAtt" : [ "SwiftContainer", "WebsiteURL" ] }, + "Description" : "URL for website hosted on S3" + }, + "DomainName" : { + "Value" : { "Fn::GetAtt" : [ "SwiftContainer", "DomainName" ] }, + "Description" : "Domain of Swift host" + } + } +} diff --git a/cfn/WordPress_2_Instances.template b/cfn/WordPress_2_Instances.template new file mode 100644 index 00000000..195401a2 --- /dev/null +++ b/cfn/WordPress_2_Instances.template @@ -0,0 +1,179 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "DatabaseServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"%\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n" + ]]}} + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "DependsOn": "DatabaseServer", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ --e s/localhost/", { "Fn::GetAtt" : [ "DatabaseServer", "PublicIp" ]}, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_2_Instances_With_EBS.template b/cfn/WordPress_2_Instances_With_EBS.template new file mode 100644 index 00000000..5d3c93d0 --- /dev/null +++ b/cfn/WordPress_2_Instances_With_EBS.template @@ -0,0 +1,221 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "VolumeSize" : { + "Description" : "WikiDatabase Volume size", + "Type" : "Number", + "Default" : "1", + "MinValue" : "1", + "MaxValue" : "1024", + "ConstraintDescription" : "must be between 1 and 1024 Gb." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + + "# Wait for the volume to appear\n", + "while [ ! -e /dev/vdc ]; do echo Waiting for volume to attach; sleep 1; done\n", + "parted -s /dev/vdc mklabel msdos\n", + "parted -s /dev/vdc mkpart primary ext3 1 1000\n", + "# Format the EBS volume and mount it\n", + "systemctl stop mysqld.service\n", + "sleep 1\n", + "mv /var/lib/mysql /var/lib/mysql.data\n", + "/sbin/mkfs -t ext3 /dev/vdc1\n", + "mkdir /var/lib/mysql\n", + "mount /dev/vdc1 /var/lib/mysql\n", + "chown mysql.mysql /var/lib/mysql\n", + "mv -n /var/lib/mysql.data/* /var/lib/mysql\n", + "systemctl start mysqld.service\n", + "sleep 1\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"%\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n" + ]]}} + } + }, + + "DataVolume" : { + "Type" : "AWS::EC2::Volume", + "Properties" : { + "Size" : { "Ref" : "VolumeSize" }, + "AvailabilityZone" : { "Fn::GetAtt" : [ "WikiDatabase", "AvailabilityZone" ]}, + "Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }] + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "DependsOn": "WikiDatabase", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ --e s/localhost/", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + }, + + "MountPoint" : { + "Type" : "AWS::EC2::VolumeAttachment", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" }, + "VolumeId" : { "Ref" : "DataVolume" }, + "Device" : "/dev/vdc" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_2_Instances_With_EBS_EIP.template b/cfn/WordPress_2_Instances_With_EBS_EIP.template new file mode 100644 index 00000000..bf3533d9 --- /dev/null +++ b/cfn/WordPress_2_Instances_With_EBS_EIP.template @@ -0,0 +1,257 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "VolumeSize" : { + "Description" : "WikiDatabase Volume size", + "Type" : "Number", + "Default" : "1", + "MinValue" : "1", + "MaxValue" : "1024", + "ConstraintDescription" : "must be between 1 and 1024 Gb." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "DatabaseIPAddress" : { + "Type" : "AWS::EC2::EIP" + }, + + "DatabaseIPAssoc" : { + "Type" : "AWS::EC2::EIPAssociation", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" }, + "EIP" : { "Ref" : "DatabaseIPAddress" } + } + }, + + "WebServerIPAddress" : { + "Type" : "AWS::EC2::EIP" + }, + + "WebServerIPAssoc" : { + "Type" : "AWS::EC2::EIPAssociation", + "Properties" : { + "InstanceId" : { "Ref" : "WebServer" }, + "EIP" : { "Ref" : "WebServerIPAddress" } + } + }, + + "WikiDatabaseSecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access via port 80 plus SSH access", + "SecurityGroupIngress" : [ + {"IpProtocol" : "icmp", "FromPort" : "-1", "ToPort" : "-1", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} + ] + } + }, + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "SecurityGroups" : [ {"Ref" : "WikiDatabaseSecurityGroup"} ], + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + + "# Wait for the volume to appear\n", + "while [ ! -e /dev/vdc ]; do echo Waiting for volume to attach; sleep 1; done\n", + "parted -s /dev/vdc mklabel msdos\n", + "parted -s /dev/vdc mkpart primary ext3 1 1000\n", + "# Format the EBS volume and mount it\n", + "systemctl stop mysqld.service\n", + "sleep 1\n", + "mv /var/lib/mysql /var/lib/mysql.data\n", + "/sbin/mkfs -t ext3 /dev/vdc1\n", + "mkdir /var/lib/mysql\n", + "mount /dev/vdc1 /var/lib/mysql\n", + "chown mysql.mysql /var/lib/mysql\n", + "mv -n /var/lib/mysql.data/* /var/lib/mysql\n", + "systemctl start mysqld.service\n", + "sleep 1\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"", { "Ref" : "WebServerIPAddress" }, "\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n" + ]]}} + } + }, + + "DataVolume" : { + "Type" : "AWS::EC2::Volume", + "Properties" : { + "Size" : { "Ref" : "VolumeSize" }, + "AvailabilityZone" : { "Fn::GetAtt" : [ "WikiDatabase", "AvailabilityZone" ]}, + "Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }] + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "DependsOn": "WikiDatabase", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ --e s/localhost/", { "Ref" : "DatabaseIPAddress" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + }, + + "MountPoint" : { + "Type" : "AWS::EC2::VolumeAttachment", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" }, + "VolumeId" : { "Ref" : "DataVolume" }, + "Device" : "/dev/vdc" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_And_Http.template b/cfn/WordPress_And_Http.template new file mode 100644 index 00000000..9a1adca8 --- /dev/null +++ b/cfn/WordPress_And_Http.template @@ -0,0 +1,138 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + + "Description": "This template installs one instance running a WordPress deployment", + + "Parameters": { + + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type": "String" + }, + + "InstanceType": { + "Description": "WebServer EC2 instance type", + "Type": "String", + "Default": "m1.large", + "AllowedValues": ["t1.micro", "m1.small", "m1.large", "m1.xlarge", + "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", + "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription": "must be a valid EC2 instance type." + }, + + "DBIpaddress": { + "Description": "The IP address of the database", + "Type": "String" + }, + + "DBName": { + "Default": "wordpress", + "Description": "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description": "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description": "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern": "[a-zA-Z0-9]*", + "ConstraintDescription": "must contain only alphanumeric characters." + }, + + "LinuxDistribution": { + "Default": "F17", + "Description": "Distribution of choice", + "Type": "String", + "AllowedValues": [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings": { + "AWSInstanceType2Arch": { + "t1.micro" : { "Arch": "32" }, + "m1.small" : { "Arch": "32" }, + "m1.large" : { "Arch": "64" }, + "m1.xlarge" : { "Arch": "64" }, + "m2.xlarge" : { "Arch": "64" }, + "m2.2xlarge" : { "Arch": "64" }, + "m2.4xlarge" : { "Arch": "64" }, + "c1.medium" : { "Arch": "32" }, + "c1.xlarge" : { "Arch": "64" }, + "cc1.4xlarge": { "Arch": "64" } + }, + "DistroArch2AMI": { + "F18" : { "32": "F18-i386-cfntools", "64": "F18-x86_64-cfntools" }, + "F17" : { "32": "F17-i386-cfntools", "64": "F17-x86_64-cfntools" }, + "U10" : { "32": "U10-i386-cfntools", "64": "U10-x86_64-cfntools" }, + "RHEL-6.1": { "32": "rhel61-i386-cfntools", "64": "rhel61-x86_64-cfntools" }, + "RHEL-6.2": { "32": "rhel62-i386-cfntools", "64": "rhel62-x86_64-cfntools" }, + "RHEL-6.3": { "32": "rhel63-i386-cfntools", "64": "rhel63-x86_64-cfntools" } + } + }, + + "Resources": { + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata": { + "AWS::CloudFormation::Init": { + "config": { + "packages": { + "yum": { + "httpd" : [], + "wordpress" : [] + } + }, + "services": { + "systemd": { + "httpd" : { "enabled": "true", "ensureRunning": "true" } + } + } + } + } + }, + "Properties": { + "ImageId": { "Fn::FindInMap": [ "DistroArch2AMI", { "Ref": "LinuxDistribution" }, + { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref": "InstanceType" }, + "KeyName" : { "Ref": "KeyName" }, + "UserData" : { "Fn::Base64": { "Fn::Join": ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref": "DBName" }, + "/ --e s/username_here/", { "Ref": "DBUsername" }, + "/ --e s/password_here/", { "Ref": "DBPassword" }, + "/ --e s/localhost/", { "Ref": "DBIpaddress"}, + "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + }, + + "Outputs": { + "PublicIp": { + "Value": {"Fn::GetAtt": [ "WebServer", "PublicIp"]}, + "Description": "IP address of WebServer instance" + } + } +} diff --git a/cfn/WordPress_Composed_Instances.template b/cfn/WordPress_Composed_Instances.template new file mode 100644 index 00000000..b8519317 --- /dev/null +++ b/cfn/WordPress_Composed_Instances.template @@ -0,0 +1,155 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "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, created within a separate stack embedded in this one with template composition, using a local MySQL database to store the data.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "DatabaseTemplate": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://raw.github.com/openstack/heat/master/templates/MySQL_Single_Instance.template", + "Parameters": { + "KeyName" : { "Ref" : "KeyName" }, + "InstanceType" : { "Ref" : "InstanceType" }, + "DBName" : { "Ref" : "DBName" }, + "DBUsername" : { "Ref" : "DBUsername" }, + "DBPassword" : { "Ref" : "DBPassword" }, + "DBRootPassword" : { "Ref" : "DBRootPassword" }, + "LinuxDistribution" : { "Ref" : "LinuxDistribution" } + } + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "DependsOn": "DatabaseTemplate", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ --e s/localhost/", { "Fn::GetAtt" : [ "DatabaseTemplate", "Outputs.PublicIp" ]}, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_NoKey.template b/cfn/WordPress_NoKey.template new file mode 100644 index 00000000..f836c14b --- /dev/null +++ b/cfn/WordPress_NoKey.template @@ -0,0 +1,144 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-gold", "64" : "F18-x86_64-gold" }, + "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" }, + "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" }, + "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" }, + "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" }, + "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" } + } + }, + + "Resources" : { + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "mysql" : [], + "mysql-server" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat >> /tmp/mysql-wordpress-config << EOF\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "cat /tmp/mysql-wordpress-config | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "' < /tmp/mysql-wordpress-config\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "cp /usr/share/wordpress/wp-config.php /usr/share/wordpress/wp-config.orig\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance.template b/cfn/WordPress_Single_Instance.template new file mode 100644 index 00000000..3d794302 --- /dev/null +++ b/cfn/WordPress_Single_Instance.template @@ -0,0 +1,149 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance.yaml b/cfn/WordPress_Single_Instance.yaml new file mode 100644 index 00000000..eed4fcf0 --- /dev/null +++ b/cfn/WordPress_Single_Instance.yaml @@ -0,0 +1,161 @@ +HeatTemplateFormatVersion: '2012-12-12' +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.' +Parameters: + KeyName: {Description: Name of an existing EC2 KeyPair + to enable SSH access to the instances, Type: String} + InstanceType: + Description: WebServer EC2 instance type + Type: String + Default: m1.large + AllowedValues: [t1.micro, m1.small, m1.large, m1.xlarge, m2.xlarge, + m2.2xlarge, m2.4xlarge, c1.medium, c1.xlarge, cc1.4xlarge] + ConstraintDescription: must be a valid EC2 instance type. + DBName: {Default: wordpress, Description: The + WordPress database name, Type: String, MinLength: '1', + MaxLength: '64', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBUsername: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account username, Type: String, + MinLength: '1', MaxLength: '16', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBPassword: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account password, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + DBRootPassword: {Default: admin, NoEcho: 'true', + Description: Root password for MySQL, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + LinuxDistribution: + Default: F17 + Description: Distribution of choice + Type: String + AllowedValues: [F18, F17, U10, RHEL-6.1, RHEL-6.2, RHEL-6.3] +Mappings: + AWSInstanceType2Arch: + t1.micro: {Arch: '32'} + m1.small: {Arch: '32'} + m1.large: {Arch: '64'} + m1.xlarge: {Arch: '64'} + m2.xlarge: {Arch: '64'} + m2.2xlarge: {Arch: '64'} + m2.4xlarge: {Arch: '64'} + c1.medium: {Arch: '32'} + c1.xlarge: {Arch: '64'} + cc1.4xlarge: {Arch: '64'} + DistroArch2AMI: + F18: {'32': F18-i386-cfntools, '64': F18-x86_64-cfntools} + F17: {'32': F17-i386-cfntools, '64': F17-x86_64-cfntools} + U10: {'32': U10-i386-cfntools, '64': U10-x86_64-cfntools} + RHEL-6.1: {'32': rhel61-i386-cfntools, '64': rhel61-x86_64-cfntools} + RHEL-6.2: {'32': rhel62-i386-cfntools, '64': rhel62-x86_64-cfntools} + RHEL-6.3: {'32': rhel63-i386-cfntools, '64': rhel63-x86_64-cfntools} +Resources: + WikiDatabase: + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + config: + packages: + yum: + mysql: [] + mysql-server: [] + httpd: [] + wordpress: [] + services: + systemd: + mysqld: {enabled: 'true', ensureRunning: 'true'} + httpd: {enabled: 'true', ensureRunning: 'true'} + Properties: + ImageId: + Fn::FindInMap: + - DistroArch2AMI + - {Ref: LinuxDistribution} + - Fn::FindInMap: + - AWSInstanceType2Arch + - {Ref: InstanceType} + - Arch + InstanceType: {Ref: InstanceType} + KeyName: {Ref: KeyName} + UserData: + Fn::Base64: + Fn::Join: + - '' + - - '#!/bin/bash -v + + ' + - '/opt/aws/bin/cfn-init + + ' + - '# Setup MySQL root password and create a user + + ' + - mysqladmin -u root password ' + - {Ref: DBRootPassword} + - ''' + + ' + - cat << EOF | mysql -u root --password=' + - {Ref: DBRootPassword} + - ''' + + ' + - 'CREATE DATABASE ' + - {Ref: DBName} + - '; + + ' + - 'GRANT ALL PRIVILEGES ON ' + - {Ref: DBName} + - .* TO " + - {Ref: DBUsername} + - '"@"localhost" + + ' + - IDENTIFIED BY " + - {Ref: DBPassword} + - '"; + + ' + - 'FLUSH PRIVILEGES; + + ' + - 'EXIT + + ' + - 'EOF + + ' + - 'sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf + + ' + - 'sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf + + ' + - sed --in-place --e s/database_name_here/ + - {Ref: DBName} + - / --e s/username_here/ + - {Ref: DBUsername} + - / --e s/password_here/ + - {Ref: DBPassword} + - '/ /usr/share/wordpress/wp-config.php + + ' + - 'systemctl restart httpd.service + + ' +Outputs: + WebsiteURL: + Value: + Fn::Join: + - '' + - - http:// + - Fn::GetAtt: [WikiDatabase, PublicIp] + - /wordpress + Description: URL for Wordpress wiki + diff --git a/cfn/WordPress_Single_Instance_With_EBS.template b/cfn/WordPress_Single_Instance_With_EBS.template new file mode 100644 index 00000000..dbb51132 --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_EBS.template @@ -0,0 +1,192 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "VolumeSize" : { + "Description" : "WikiDatabase Volume size", + "Type" : "Number", + "Default" : "1", + "MinValue" : "1", + "MaxValue" : "1024", + "ConstraintDescription" : "must be between 1 and 1024 Gb." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + + "# Wait for the volume to appear\n", + "while [ ! -e /dev/vdc ]; do echo Waiting for volume to attach; sleep 1; done\n", + "parted -s /dev/vdc mklabel msdos\n", + "parted -s /dev/vdc mkpart primary ext3 1 1000\n", + "# Format the EBS volume and mount it\n", + "systemctl stop mysqld.service\n", + "sleep 1\n", + "mv /var/lib/mysql /var/lib/mysql.data\n", + "/sbin/mkfs -t ext3 /dev/vdc1\n", + "mkdir /var/lib/mysql\n", + "mount /dev/vdc1 /var/lib/mysql\n", + "chown mysql.mysql /var/lib/mysql\n", + "mv -n /var/lib/mysql.data/* /var/lib/mysql\n", + "systemctl start mysqld.service\n", + "sleep 1\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + }, + + "DataVolume" : { + "Type" : "AWS::EC2::Volume", + "Properties" : { + "Size" : { "Ref" : "VolumeSize" }, + "AvailabilityZone" : { "Fn::GetAtt" : [ "WikiDatabase", "AvailabilityZone" ]}, + "Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }] + } + }, + + "MountPoint" : { + "Type" : "AWS::EC2::VolumeAttachment", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" }, + "VolumeId" : { "Ref" : "DataVolume" }, + "Device" : "/dev/vdc" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_EBS_EIP.template b/cfn/WordPress_Single_Instance_With_EBS_EIP.template new file mode 100644 index 00000000..1cd3c468 --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_EBS_EIP.template @@ -0,0 +1,217 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WikiServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "VolumeSize" : { + "Description" : "WikiServer Volume size", + "Type" : "Number", + "Default" : "1", + "MinValue" : "1", + "MaxValue" : "1024", + "ConstraintDescription" : "must be between 1 and 1024 Gb." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + + "IPAddress" : { + "Type" : "AWS::EC2::EIP" + }, + + "IPAssoc" : { + "Type" : "AWS::EC2::EIPAssociation", + "Properties" : { + "InstanceId" : { "Ref" : "WikiServer" }, + "EIP" : { "Ref" : "IPAddress" } + } + }, + "WikiServerSecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access via port 80 plus SSH access", + "SecurityGroupIngress" : [ + {"IpProtocol" : "icmp", "FromPort" : "-1", "ToPort" : "-1", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} + ] + } + }, + + "WikiServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "mysql" : [], + "mysql-server" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "SecurityGroups" : [ {"Ref" : "WikiServerSecurityGroup"} ], + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Wait for the volume to appear\n", + "while [ ! -e /dev/vdc ]; do echo Waiting for volume to attach; sleep 1; done\n", + "parted -s /dev/vdc mklabel msdos\n", + "parted -s /dev/vdc mkpart primary ext3 1 1000\n", + "# Format the EBS volume and mount it\n", + "systemctl stop mysqld.service\n", + "sleep 1\n", + "mv /var/lib/mysql /var/lib/mysql.data\n", + "/sbin/mkfs -t ext3 /dev/vdc1\n", + "mkdir /var/lib/mysql\n", + "mount /dev/vdc1 /var/lib/mysql\n", + "chown mysql.mysql /var/lib/mysql\n", + "mv -n /var/lib/mysql.data/* /var/lib/mysql\n", + "systemctl start mysqld.service\n", + "sleep 1\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + }, + "DataVolume" : { + "Type" : "AWS::EC2::Volume", + "Properties" : { + "Size" : { "Ref" : "VolumeSize" }, + "AvailabilityZone" : { "Fn::GetAtt" : [ "WikiServer", "AvailabilityZone" ]}, + "Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }] + } + }, + "MountPoint" : { + "Type" : "AWS::EC2::VolumeAttachment", + "Properties" : { + "InstanceId" : { "Ref" : "WikiServer" }, + "VolumeId" : { "Ref" : "DataVolume" }, + "Device" : "/dev/vdc" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + }, + "InstanceIPAddress" : { + "Value" : { "Ref" : "IPAddress" } + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_EIP.template b/cfn/WordPress_Single_Instance_With_EIP.template new file mode 100644 index 00000000..bfe1d68b --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_EIP.template @@ -0,0 +1,177 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + + "IPAddress" : { + "Type" : "AWS::EC2::EIP" + }, + + "IPAssoc" : { + "Type" : "AWS::EC2::EIPAssociation", + "Properties" : { + "InstanceId" : { "Ref" : "WebServer" }, + "EIP" : { "Ref" : "IPAddress" } + } + }, + "WebServerSecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access via port 80 plus SSH access", + "SecurityGroupIngress" : [ + {"IpProtocol" : "icmp", "FromPort" : "-1", "ToPort" : "-1", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} + ] + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "mysql" : [], + "mysql-server" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ], + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + }, + "InstanceIPAddress" : { + "Value" : { "Ref" : "IPAddress" } + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_HA.template b/cfn/WordPress_Single_Instance_With_HA.template new file mode 100644 index 00000000..b3a96bfb --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_HA.template @@ -0,0 +1,296 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + }, + "HupPollInterval": { + "Default": "1", + "Description" : "Interval for cfn-hup", + "Type": "String" + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "CfnUser" : { + "Type" : "AWS::IAM::User" + }, + "WebServerKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "CfnUser"} + } + }, + "WebServerRestartPolicy" : { + "Type" : "OS::Heat::HARestarter", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" } + } + }, + "HttpFailureAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "AlarmDescription": "Restart the WikiDatabase if httpd fails > 3 times in 10 minutes", + "MetricName": "ServiceFailure", + "Namespace": "system/linux", + "Statistic": "SampleCount", + "Period": "300", + "EvaluationPeriods": "1", + "Threshold": "2", + "AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ], + "ComparisonOperator": "GreaterThanThreshold" + } + }, + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "files" : { + "/etc/cfn/cfn-credentials" : { + "content" : { "Fn::Join" : ["", [ + "AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n", + "AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys", + "SecretAccessKey"]}, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/cfn-hup.conf" : { + "content" : { "Fn::Join" : ["", [ + "[main]\n", + "stack=", { "Ref" : "AWS::StackName" }, "\n", + "credential-file=/etc/cfn/cfn-credentials\n", + "region=", { "Ref" : "AWS::Region" }, "\n", + "interval=", { "Ref" : "HupPollInterval" }, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/notify-on-httpd-restarted" : { + "content" : { "Fn::Join" : ["", [ + "#!/bin/sh\n", + "/opt/aws/bin/cfn-push-stats --watch ", + { "Ref" : "HttpFailureAlarm" }, + " --service-failure\n" + ]]}, + "mode" : "000700", + "owner" : "root", + "group" : "root" + }, + + "/tmp/cfn-hup-crontab.txt" : { + "content" : { "Fn::Join" : ["", [ + "MAIL=\"\"\n", + "\n", + "* * * * * /opt/aws/bin/cfn-hup -f\n" + ]]}, + "mode" : "000600", + "owner" : "root", + "group" : "root" + }, + + "/tmp/setup.mysql" : { + "content" : { "Fn::Join" : ["", [ + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, + ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n", + "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/hooks.conf" : { + "content": { "Fn::Join" : ["", [ + "[cfn-http-restarted]\n", + "triggers=service.restarted\n", + "path=Resources.WikiDatabase.Metadata\n", + "action=/etc/cfn/notify-on-httpd-restarted\n", + "runas=root\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + } + }, + "packages" : { + "yum" : { + "cronie" : [], + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "crond" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r WikiDatabase ", + " --access-key ", { "Ref" : "WebServerKeys" }, + " --secret-key ", {"Fn::GetAtt": ["WebServerKeys", "SecretAccessKey"]}, + " --region ", { "Ref" : "AWS::Region" }, + " || error_exit 'Failed to run cfn-init'\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, + "' || error_exit 'Failed to initialize root password'\n", + + "mysql -u root --password='", { "Ref" : "DBRootPassword" }, + "' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n", + + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, + "/ --e s/username_here/", { "Ref" : "DBUsername" }, + "/ --e s/password_here/", { "Ref" : "DBPassword" }, + "/ /usr/share/wordpress/wp-config.php\n", + + "systemctl restart httpd.service\n", + + "# install cfn-hup crontab\n", + "crontab /tmp/cfn-hup-crontab.txt\n", + + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '", + { "Ref" : "WaitHandle" }, "'\n" + ]]}} + } + }, + + "WaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "WaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "WikiDatabase", + "Properties" : { + "Handle" : {"Ref" : "WaitHandle"}, + "Count" : "1", + "Timeout" : "600" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_HA.yaml b/cfn/WordPress_Single_Instance_With_HA.yaml new file mode 100644 index 00000000..0dca5e58 --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_HA.yaml @@ -0,0 +1,336 @@ +HeatTemplateFormatVersion: '2012-12-12' +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.' +Parameters: + KeyName: {Description: Name of an existing EC2 KeyPair + to enable SSH access to the instances, Type: String} + InstanceType: + Description: WebServer EC2 instance type + Type: String + Default: m1.large + AllowedValues: [t1.micro, m1.small, m1.large, m1.xlarge, m2.xlarge, + m2.2xlarge, m2.4xlarge, c1.medium, c1.xlarge, cc1.4xlarge] + ConstraintDescription: must be a valid EC2 instance type. + DBName: {Default: wordpress, Description: The + WordPress database name, Type: String, MinLength: '1', + MaxLength: '64', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBUsername: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account username, Type: String, + MinLength: '1', MaxLength: '16', AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*', + ConstraintDescription: must begin with a letter and contain only + alphanumeric characters.} + DBPassword: {Default: admin, NoEcho: 'true', + Description: The WordPress database admin account password, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + DBRootPassword: {Default: admin, NoEcho: 'true', + Description: Root password for MySQL, Type: String, + MinLength: '1', MaxLength: '41', AllowedPattern: '[a-zA-Z0-9]*', + ConstraintDescription: must contain only alphanumeric characters.} + LinuxDistribution: + Default: F17 + Description: Distribution of choice + Type: String + AllowedValues: [F18, F17, U10, RHEL-6.1, RHEL-6.2, RHEL-6.3] + HupPollInterval: {Default: '1', Description: Interval + for cfn-hup, Type: String} +Mappings: + AWSInstanceType2Arch: + t1.micro: {Arch: '32'} + m1.small: {Arch: '32'} + m1.large: {Arch: '64'} + m1.xlarge: {Arch: '64'} + m2.xlarge: {Arch: '64'} + m2.2xlarge: {Arch: '64'} + m2.4xlarge: {Arch: '64'} + c1.medium: {Arch: '32'} + c1.xlarge: {Arch: '64'} + cc1.4xlarge: {Arch: '64'} + DistroArch2AMI: + F18: {'32': F18-i386-cfntools, '64': F18-x86_64-cfntools} + F17: {'32': F17-i386-cfntools, '64': F17-x86_64-cfntools} + U10: {'32': U10-i386-cfntools, '64': U10-x86_64-cfntools} + RHEL-6.1: {'32': rhel61-i386-cfntools, '64': rhel61-x86_64-cfntools} + RHEL-6.2: {'32': rhel62-i386-cfntools, '64': rhel62-x86_64-cfntools} + RHEL-6.3: {'32': rhel63-i386-cfntools, '64': rhel63-x86_64-cfntools} +Resources: + CfnUser: {Type: 'AWS::IAM::User'} + WebServerKeys: + Type: AWS::IAM::AccessKey + Properties: + UserName: {Ref: CfnUser} + WebServerRestartPolicy: + Type: OS::Heat::HARestarter + Properties: + InstanceId: {Ref: WikiDatabase} + HttpFailureAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + AlarmDescription: Restart the WikiDatabase if httpd fails > + 3 times in 10 minutes + MetricName: ServiceFailure + Namespace: system/linux + Statistic: SampleCount + Period: '300' + EvaluationPeriods: '1' + Threshold: '2' + AlarmActions: + - {Ref: WebServerRestartPolicy} + ComparisonOperator: GreaterThanThreshold + WikiDatabase: + Type: AWS::EC2::Instance + Metadata: + AWS::CloudFormation::Init: + config: + files: + /etc/cfn/cfn-credentials: + content: + Fn::Join: + - '' + - - AWSAccessKeyId= + - {Ref: WebServerKeys} + - ' + + ' + - AWSSecretKey= + - Fn::GetAtt: [WebServerKeys, SecretAccessKey] + - ' + + ' + mode: '000400' + owner: root + group: root + /etc/cfn/cfn-hup.conf: + content: + Fn::Join: + - '' + - - '[main] + + ' + - stack= + - {Ref: 'AWS::StackName'} + - ' + + ' + - 'credential-file=/etc/cfn/cfn-credentials + + ' + - region= + - {Ref: 'AWS::Region'} + - ' + + ' + - interval= + - {Ref: HupPollInterval} + - ' + + ' + mode: '000400' + owner: root + group: root + /etc/cfn/notify-on-httpd-restarted: + content: + Fn::Join: + - '' + - - '#!/bin/sh + + ' + - '/opt/aws/bin/cfn-push-stats --watch ' + - {Ref: HttpFailureAlarm} + - ' --service-failure + + ' + mode: '000700' + owner: root + group: root + /tmp/cfn-hup-crontab.txt: + content: + Fn::Join: + - '' + - ['MAIL="" + + ', ' + + ', '* * * * * /opt/aws/bin/cfn-hup -f + + '] + mode: '000600' + owner: root + group: root + /tmp/setup.mysql: + content: + Fn::Join: + - '' + - - 'CREATE DATABASE ' + - {Ref: DBName} + - '; + + ' + - 'GRANT ALL PRIVILEGES ON ' + - {Ref: DBName} + - .* TO ' + - {Ref: DBUsername} + - '''@''localhost'' + + ' + - IDENTIFIED BY ' + - {Ref: DBPassword} + - '''; + + ' + - 'FLUSH PRIVILEGES; + + ' + - 'EXIT + + ' + mode: '000644' + owner: root + group: root + /etc/cfn/hooks.conf: + content: + Fn::Join: + - '' + - ['[cfn-http-restarted] + + ', 'triggers=service.restarted + + ', 'path=Resources.WikiDatabase.Metadata + + ', 'action=/etc/cfn/notify-on-httpd-restarted + + ', 'runas=root + + '] + mode: '000400' + owner: root + group: root + packages: + yum: + cronie: [] + mysql: [] + mysql-server: [] + httpd: [] + wordpress: [] + services: + systemd: + mysqld: {enabled: 'true', ensureRunning: 'true'} + httpd: {enabled: 'true', ensureRunning: 'true'} + crond: {enabled: 'true', ensureRunning: 'true'} + Properties: + ImageId: + Fn::FindInMap: + - DistroArch2AMI + - {Ref: LinuxDistribution} + - Fn::FindInMap: + - AWSInstanceType2Arch + - {Ref: InstanceType} + - Arch + InstanceType: {Ref: InstanceType} + KeyName: {Ref: KeyName} + UserData: + Fn::Base64: + Fn::Join: + - '' + - - '#!/bin/bash -v + + ' + - '# Helper function + + ' + - 'function error_exit + + ' + - '{ + + ' + - ' /opt/aws/bin/cfn-signal -e 1 -r "$1" ''' + - {Ref: WaitHandle} + - ''' + + ' + - ' exit 1 + + ' + - '} + + ' + - '/opt/aws/bin/cfn-init -s ' + - {Ref: 'AWS::StackName'} + - ' -r WikiDatabase ' + - ' --access-key ' + - {Ref: WebServerKeys} + - ' --secret-key ' + - Fn::GetAtt: [WebServerKeys, SecretAccessKey] + - ' --region ' + - {Ref: 'AWS::Region'} + - ' || error_exit ''Failed to run cfn-init'' + + ' + - '# Setup MySQL root password and create a user + + ' + - mysqladmin -u root password ' + - {Ref: DBRootPassword} + - ''' || error_exit ''Failed to initialize root password'' + + ' + - mysql -u root --password=' + - {Ref: DBRootPassword} + - ''' < /tmp/setup.mysql || error_exit ''Failed to create database.'' + + ' + - 'sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf + + ' + - 'sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf + + ' + - sed --in-place --e s/database_name_here/ + - {Ref: DBName} + - / --e s/username_here/ + - {Ref: DBUsername} + - / --e s/password_here/ + - {Ref: DBPassword} + - '/ /usr/share/wordpress/wp-config.php + + ' + - 'systemctl restart httpd.service + + ' + - '# install cfn-hup crontab + + ' + - 'crontab /tmp/cfn-hup-crontab.txt + + ' + - '# All is well so signal success + + ' + - /opt/aws/bin/cfn-signal -e 0 -r "Wiki server setup complete" ' + - {Ref: WaitHandle} + - ''' + + ' + WaitHandle: {Type: 'AWS::CloudFormation::WaitConditionHandle'} + WaitCondition: + Type: AWS::CloudFormation::WaitCondition + DependsOn: WikiDatabase + Properties: + Handle: {Ref: WaitHandle} + Count: '1' + Timeout: '600' +Outputs: + WebsiteURL: + Value: + Fn::Join: + - '' + - - http:// + - Fn::GetAtt: [WikiDatabase, PublicIp] + - /wordpress + Description: URL for Wordpress wiki + diff --git a/cfn/WordPress_Single_Instance_With_HA_AccessPolicy.template b/cfn/WordPress_Single_Instance_With_HA_AccessPolicy.template new file mode 100644 index 00000000..36d0603a --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_HA_AccessPolicy.template @@ -0,0 +1,305 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + }, + "HupPollInterval": { + "Default": "1", + "Description" : "Interval for cfn-hup", + "Type": "String" + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "CfnUser" : { + "Type" : "AWS::IAM::User", + "Properties" : { + "Policies" : [ { "Ref": "WebServerAccessPolicy"} ] + } + }, + "WebServerAccessPolicy" : { + "Type" : "OS::Heat::AccessPolicy", + "Properties" : { + "AllowedResources" : [ "WikiDatabase" ] + } + }, + "WebServerKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "CfnUser"} + } + }, + "WebServerRestartPolicy" : { + "Type" : "OS::Heat::HARestarter", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" } + } + }, + "HttpFailureAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "AlarmDescription": "Restart the WikiDatabase if httpd fails > 3 times in 10 minutes", + "MetricName": "ServiceFailure", + "Namespace": "system/linux", + "Statistic": "SampleCount", + "Period": "300", + "EvaluationPeriods": "1", + "Threshold": "2", + "AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ], + "ComparisonOperator": "GreaterThanThreshold" + } + }, + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "files" : { + "/etc/cfn/cfn-credentials" : { + "content" : { "Fn::Join" : ["", [ + "AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n", + "AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys", + "SecretAccessKey"]}, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/cfn-hup.conf" : { + "content" : { "Fn::Join" : ["", [ + "[main]\n", + "stack=", { "Ref" : "AWS::StackName" }, "\n", + "credential-file=/etc/cfn/cfn-credentials\n", + "region=", { "Ref" : "AWS::Region" }, "\n", + "interval=", { "Ref" : "HupPollInterval" }, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/notify-on-httpd-restarted" : { + "content" : { "Fn::Join" : ["", [ + "#!/bin/sh\n", + "/opt/aws/bin/cfn-push-stats --watch ", + { "Ref" : "HttpFailureAlarm" }, + " --service-failure\n" + ]]}, + "mode" : "000700", + "owner" : "root", + "group" : "root" + }, + + "/tmp/cfn-hup-crontab.txt" : { + "content" : { "Fn::Join" : ["", [ + "MAIL=\"\"\n", + "\n", + "* * * * * /opt/aws/bin/cfn-hup -f\n" + ]]}, + "mode" : "000600", + "owner" : "root", + "group" : "root" + }, + + "/tmp/setup.mysql" : { + "content" : { "Fn::Join" : ["", [ + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, + ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n", + "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + + "/etc/cfn/hooks.conf" : { + "content": { "Fn::Join" : ["", [ + "[cfn-http-restarted]\n", + "triggers=service.restarted\n", + "path=Resources.WikiDatabase.Metadata\n", + "action=/etc/cfn/notify-on-httpd-restarted\n", + "runas=root\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + } + }, + "packages" : { + "yum" : { + "cronie" : [], + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "crond" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r WikiDatabase ", + " --access-key ", { "Ref" : "WebServerKeys" }, + " --secret-key ", {"Fn::GetAtt": ["WebServerKeys", "SecretAccessKey"]}, + " --region ", { "Ref" : "AWS::Region" }, + " || error_exit 'Failed to run cfn-init'\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, + "' || error_exit 'Failed to initialize root password'\n", + + "mysql -u root --password='", { "Ref" : "DBRootPassword" }, + "' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n", + + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, + "/ --e s/username_here/", { "Ref" : "DBUsername" }, + "/ --e s/password_here/", { "Ref" : "DBPassword" }, + "/ /usr/share/wordpress/wp-config.php\n", + + "systemctl restart httpd.service\n", + + "# install cfn-hup crontab\n", + "crontab /tmp/cfn-hup-crontab.txt\n", + + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '", + { "Ref" : "WaitHandle" }, "'\n" + ]]}} + } + }, + + "WaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "WaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "WikiDatabase", + "Properties" : { + "Handle" : {"Ref" : "WaitHandle"}, + "Count" : "1", + "Timeout" : "600" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_IHA.template b/cfn/WordPress_Single_Instance_With_IHA.template new file mode 100644 index 00000000..132bd380 --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_IHA.template @@ -0,0 +1,270 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + }, + "HupPollInterval": { + "Default": "1", + "Description" : "Interval for cfn-hup", + "Type": "String" + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "CfnUser" : { + "Type" : "AWS::IAM::User" + }, + "WebServerKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : {"Ref": "CfnUser"} + } + }, + "WebServerRestartPolicy" : { + "Type" : "OS::Heat::HARestarter", + "Properties" : { + "InstanceId" : { "Ref" : "WikiDatabase" } + } + }, + "HeartbeatFailureAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "DependsOn" : "WaitCondition", + "Properties": { + "AlarmDescription": "Restart the WikiDatabase if we miss a heartbeat", + "MetricName": "Heartbeat", + "Namespace": "system/linux", + "Statistic": "SampleCount", + "Period": "60", + "EvaluationPeriods": "1", + "Threshold": "1", + "AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ], + "ComparisonOperator": "LessThanThreshold" + } + }, + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "files" : { + "/etc/cfn/cfn-credentials" : { + "content" : { "Fn::Join" : ["", [ + "AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n", + "AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys", + "SecretAccessKey"]}, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + "/etc/cfn/cfn-hup.conf" : { + "content" : { "Fn::Join" : ["", [ + "[main]\n", + "stack=", { "Ref" : "AWS::StackName" }, "\n", + "credential-file=/etc/cfn/cfn-credentials\n", + "region=", { "Ref" : "AWS::Region" }, "\n", + "interval=", { "Ref" : "HupPollInterval" }, "\n" + ]]}, + "mode" : "000400", + "owner" : "root", + "group" : "root" + }, + "/tmp/cfn-hup-crontab.txt" : { + "content" : { "Fn::Join" : ["", [ + "MAIL=\"\"\n", + "\n", + "* * * * * /opt/aws/bin/cfn-hup -f\n", + "* * * * * /opt/aws/bin/cfn-push-stats ", + " --watch ", { "Ref" : "HeartbeatFailureAlarm" }, + " --heartbeat\n" + ]]}, + "mode" : "000600", + "owner" : "root", + "group" : "root" + }, + + "/tmp/setup.mysql" : { + "content" : { "Fn::Join" : ["", [ + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, + ".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n", + "IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n" + ]]}, + "mode" : "000644", + "owner" : "root", + "group" : "root" + } + }, + "packages" : { + "yum" : { + "cronie" : [], + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "crond" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "# Helper function\n", + "function error_exit\n", + "{\n", + " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n", + " exit 1\n", + "}\n", + + "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, + " -r WikiDatabase ", + " --region ", { "Ref" : "AWS::Region" }, + " || error_exit 'Failed to run cfn-init'\n", + + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, + "' || error_exit 'Failed to initialize root password'\n", + + "mysql -u root --password='", { "Ref" : "DBRootPassword" }, + "' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n", + + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, + "/ --e s/username_here/", { "Ref" : "DBUsername" }, + "/ --e s/password_here/", { "Ref" : "DBPassword" }, + "/ /usr/share/wordpress/wp-config.php\n", + + "systemctl restart httpd.service\n", + + "# install cfn-hup crontab\n", + "crontab /tmp/cfn-hup-crontab.txt\n", + + "# All is well so signal success\n", + "/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '", + { "Ref" : "WaitHandle" }, "'\n" + ]]}} + } + }, + + "WaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "WaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "WikiDatabase", + "Properties" : { + "Handle" : {"Ref" : "WaitHandle"}, + "Timeout" : "600" + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_With_Quantum.template b/cfn/WordPress_Single_Instance_With_Quantum.template new file mode 100644 index 00000000..049dfbe8 --- /dev/null +++ b/cfn/WordPress_Single_Instance_With_Quantum.template @@ -0,0 +1,192 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + + "network": { + "Type": "OS::Quantum::Net" + }, + + "subnet": { + "Type": "OS::Quantum::Subnet", + "Properties": { + "network_id": { "Ref" : "network" }, + "ip_version": 4, + "cidr": "10.0.1.0/24", + "allocation_pools": [{"start": "10.0.1.2", "end": "10.0.1.150"}] + } + }, + + "port": { + "Type": "OS::Quantum::Port", + "Properties": { + "device_id": { "Ref" : "WebServer" }, + "network_id": { "Ref" : "network" }, + "fixed_ips": [{ + "subnet_id": { "Ref" : "subnet" }, + "ip_address": "10.0.1.2" + }] + } + }, + + "WebServerSecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access via port 80 plus SSH access", + "SecurityGroupIngress" : [ + {"IpProtocol" : "icmp", "FromPort" : "-1", "ToPort" : "-1", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} + ] + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "mysql" : [], + "mysql-server" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ], + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + }, + "InstanceIPAddress" : { + "Value" : { "Ref" : "IPAddress" } + } + } +} diff --git a/cfn/WordPress_Single_Instance_deb.template b/cfn/WordPress_Single_Instance_deb.template new file mode 100644 index 00000000..90ad61f5 --- /dev/null +++ b/cfn/WordPress_Single_Instance_deb.template @@ -0,0 +1,138 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "U10", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : "U10" + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" } + } + }, + + "Resources" : { + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "services" : { + "sysvinit" : { + "mysql" : { "enabled" : "true", "ensureRunning" : "true" }, + "apache2" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "apt-get -y update\n", + "apt-get -y install apache2\n", + "apt-get -y install wordpress\n", + "echo mysql-server mysql-server/root_password select ", { "Ref" : "DBPassword" }, " | debconf-set-selections\n", + "echo mysql-server mysql-server/root_password_again select ", { "Ref" : "DBPassword" }, " | debconf-set-selections\n", + "apt-get -y install mysql-server\n", + "cat > /etc/apache2/conf.d/wordpress.conf <\n", + " AllowOverride Options\n", + "\n", + "EOF\n", + "/opt/aws/bin/cfn-init\n", + "bash /usr/share/doc/wordpress/examples/setup-mysql -n ", { "Ref" : "DBName" }, " 127.0.0.1\n", + "mv /etc/wordpress/config-127.0.0.1.php /etc/wordpress/config-`hostname -i`.php\n", + "service apache2 restart\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_gold.template b/cfn/WordPress_Single_Instance_gold.template new file mode 100644 index 00000000..c5205453 --- /dev/null +++ b/cfn/WordPress_Single_Instance_gold.template @@ -0,0 +1,150 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "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.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-gold", "64" : "F18-x86_64-gold" }, + "F17" : { "32" : "F17-i386-gold", "64" : "F17-x86_64-gold" }, + "U10" : { "32" : "U10-i386-gold", "64" : "U10-x86_64-gold" }, + "RHEL-6.1" : { "32" : "rhel61-i386-gold", "64" : "rhel61-x86_64-gold" }, + "RHEL-6.2" : { "32" : "rhel62-i386-gold", "64" : "rhel62-x86_64-gold" }, + "RHEL-6.3" : { "32" : "rhel63-i386-gold", "64" : "rhel63-x86_64-gold" } + } + }, + + "Resources" : { + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "mysql" : [], + "mysql-server" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat >> /tmp/mysql-wordpress-config << EOF\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "cat /tmp/mysql-wordpress-config | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "' < /tmp/mysql-wordpress-config\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n", + "cp /usr/share/wordpress/wp-config.php /usr/share/wordpress/wp-config.orig\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_Single_Instance_puppet.template b/cfn/WordPress_Single_Instance_puppet.template new file mode 100644 index 00000000..6f9bc8f3 --- /dev/null +++ b/cfn/WordPress_Single_Instance_puppet.template @@ -0,0 +1,234 @@ +{ + "TemplateFormatVersion" : "2010-09-09", + + "Description": "Sample template to bring up WordPress using the Puppet client to install server roles. A WaitCondition is used to hold up the stack creation until the application is deployed. **WARNING** This template creates one or more Amazon EC2 instances and CloudWatch alarms. You will be billed for the AWS resources used if you create a stack from this template.", + + "Parameters" : { + "KeyName": { + "Type": "String", + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server" + }, + "PuppetClientSecurityGroup": { + "Description" : "The EC2 security group for the instances", + "Type": "String" + }, + "PuppetMasterDNSName": { + "Description" : "The PuppetMaster DNS name", + "Type": "String" + }, + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.small", + "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + "DatabaseType": { + "Default": "db.m1.small", + "Description" : "The database instance type", + "Type": "String", + "AllowedValues" : [ "db.m1.small", "db.m1.large", "db.m1.xlarge", "db.m2.xlarge", "db.m2.2xlarge", "db.m2.4xlarge" ], + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "DatabaseUser": { + "Default" : "admin", + "NoEcho": "true", + "Type": "String", + "Description" : "Test database admin account name", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + "DatabasePassword": { + "Default" : "admin", + "NoEcho": "true", + "Type": "String", + "Description" : "Test database admin account password", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "64" }, + "m1.small" : { "Arch" : "64" }, + "m1.medium" : { "Arch" : "64" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "64" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64HVM" }, + "cc2.8xlarge" : { "Arch" : "64HVM" }, + "cg1.4xlarge" : { "Arch" : "64HVM" } + }, + + "AWSRegionArch2AMI" : { + "us-east-1" : { "32" : "ami-31814f58", "64" : "ami-1b814f72", "64HVM" : "ami-0da96764" }, + "us-west-2" : { "32" : "ami-38fe7308", "64" : "ami-30fe7300", "64HVM" : "NOT_YET_SUPPORTED" }, + "us-west-1" : { "32" : "ami-11d68a54", "64" : "ami-1bd68a5e", "64HVM" : "NOT_YET_SUPPORTED" }, + "eu-west-1" : { "32" : "ami-973b06e3", "64" : "ami-953b06e1", "64HVM" : "NOT_YET_SUPPORTED" }, + "ap-southeast-1" : { "32" : "ami-b4b0cae6", "64" : "ami-beb0caec", "64HVM" : "NOT_YET_SUPPORTED" }, + "ap-northeast-1" : { "32" : "ami-0644f007", "64" : "ami-0a44f00b", "64HVM" : "NOT_YET_SUPPORTED" }, + "sa-east-1" : { "32" : "ami-3e3be423", "64" : "ami-3c3be421", "64HVM" : "NOT_YET_SUPPORTED" } + } + }, + + "Resources" : { + + "CFNInitUser" : { + "Type" : "AWS::IAM::User" + }, + + "CFNKeys" : { + "Type" : "AWS::IAM::AccessKey", + "Properties" : { + "UserName" : { "Ref": "CFNInitUser" } + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "puppet" : [], + "ruby-devel" : [], + "gcc" : [], + "make" : [], + "rubygems" : [] + }, + "rubygems" : { + "json" : [] + } + }, + "files" : { + "/etc/yum.repos.d/epel.repo" : { + "source" : "https://s3.amazonaws.com/cloudformation-examples/enable-epel-on-amazon-linux-ami", + "mode" : "000644", + "owner" : "root", + "group" : "root" + }, + "/etc/puppet/puppet.conf" : { + "content" : { "Fn::Join" : ["", [ + "[main]\n", + " logdir=/var/log/puppet\n", + " rundir=/var/run/puppet\n", + " ssldir=$vardir/ssl\n", + " pluginsync=true\n", + "[agent]\n", + " classfile=$vardir/classes.txt\n", + " localconfig=$vardir/localconfig\n", + " server=",{ "Ref" : "PuppetMasterDNSName" },"\n" + ]] }, + "mode" : "000644", + "owner" : "root", + "group" : "root" + } + }, + "services" : { + "sysvinit" : { + "puppet" : { + "enabled" : "true", + "ensureRunning" : "true" + } + } + } + } + }, + "Puppet" : { + "roles" : [ "wordpress" ], + "host" : {"Fn::GetAtt" : ["WordPressDatabase", "Endpoint.Address"]}, + "database" : "WordPressDB", + "user" : {"Ref" : "DatabaseUser"}, + "password" : {"Ref" : "DatabasePassword" } + } + }, + "Properties": { + "SecurityGroups": [ { "Ref": "PuppetClientSecurityGroup" }, { "Ref" : "EC2SecurityGroup" } ], + "ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" }, { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] + }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash\n", + "yum update -y aws-cfn-bootstrap\n", + + "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, + " -s ", { "Ref" : "AWS::StackName" }, " -r WebServer ", + " --access-key ", { "Ref" : "CFNKeys" }, + " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", + "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "ApplicationWaitHandle" }, "'\n" + ]]}}, + "KeyName": { "Ref": "KeyName" }, + "InstanceType": { "Ref": "InstanceType" } + } + }, + + + "EC2SecurityGroup" : { + "Type" : "AWS::EC2::SecurityGroup", + "Properties" : { + "GroupDescription" : "Enable HTTP access for Wordpress plus SSH access via port 22", + "SecurityGroupIngress" : [ + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" }, + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" } + ] + } + }, + + "ApplicationWaitHandle" : { + "Type" : "AWS::CloudFormation::WaitConditionHandle" + }, + + "ApplicationWaitCondition" : { + "Type" : "AWS::CloudFormation::WaitCondition", + "DependsOn" : "WebServer", + "Properties" : { + "Handle" : { "Ref" : "ApplicationWaitHandle" }, + "Timeout" : "600" + } + }, + + "WordPressDatabase" : { + "Type" : "AWS::RDS::DBInstance", + "Properties" : { + "AllocatedStorage" : "5", + "DBName" : "WordPressDB", + "Engine" : "MySQL", + "DBInstanceClass" : { "Ref" : "DatabaseType" }, + "DBSecurityGroups" : [ { "Ref": "DBSecurityGroup" } ], + "MasterUsername" : { "Ref" : "DatabaseUser" }, + "MasterUserPassword" : { "Ref" : "DatabasePassword" } + } + }, + + "DBSecurityGroup": { + "Type": "AWS::RDS::DBSecurityGroup", + "Properties": { + "DBSecurityGroupIngress": { + "EC2SecurityGroupName": { "Ref": "EC2SecurityGroup" } + }, + "GroupDescription": "database access" + } + } + }, + + "Outputs": { + "WebsiteURL": { + "Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "WebServer", "PublicDnsName" ] }, "/wordpress" ] ] }, + "Description" : "URL of the WordPress website" + }, + "InstallURL": { + "Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "WebServer", "PublicDnsName" ] }, "/wordpress/wp-admin/install.php" ] ] }, + "Description" : "URL to install WordPress" + } + } +} + diff --git a/cfn/WordPress_With_LB.template b/cfn/WordPress_With_LB.template new file mode 100644 index 00000000..df37dd8c --- /dev/null +++ b/cfn/WordPress_With_LB.template @@ -0,0 +1,171 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + + "Description": "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, created within a separate stack embedded in this one with template composition, using a local MySQL database to store the data.", + + "Parameters": { + + "KeyName": { + "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type": "String" + }, + + "InstanceType": { + "Description": "WebServer EC2 instance type", + "Type": "String", + "Default": "m1.large", + "AllowedValues": [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription": "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description": "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description": "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description": "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern": "[a-zA-Z0-9]*", + "ConstraintDescription": "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description": "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern": "[a-zA-Z0-9]*", + "ConstraintDescription": "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description": "Distribution of choice", + "Type": "String", + "AllowedValues": [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings": { + "AWSInstanceType2Arch": { + "t1.micro" : { "Arch": "32" }, + "m1.small" : { "Arch": "32" }, + "m1.large" : { "Arch": "64" }, + "m1.xlarge" : { "Arch": "64" }, + "m2.xlarge" : { "Arch": "64" }, + "m2.2xlarge" : { "Arch": "64" }, + "m2.4xlarge" : { "Arch": "64" }, + "c1.medium" : { "Arch": "32" }, + "c1.xlarge" : { "Arch": "64" }, + "cc1.4xlarge" : { "Arch": "64" } + }, + "DistroArch2AMI": { + "F18" : { "32": "F18-i386-cfntools", "64": "F18-x86_64-cfntools" }, + "F17" : { "32": "F17-i386-cfntools", "64": "F17-x86_64-cfntools" }, + "U10" : { "32": "U10-i386-cfntools", "64": "U10-x86_64-cfntools" }, + "RHEL-6.1": { "32": "rhel61-i386-cfntools", "64": "rhel61-x86_64-cfntools" }, + "RHEL-6.2": { "32": "rhel62-i386-cfntools", "64": "rhel62-x86_64-cfntools" }, + "RHEL-6.3": { "32": "rhel63-i386-cfntools", "64": "rhel63-x86_64-cfntools" } + } + }, + + "Resources": { + "DatabaseServer": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://raw.github.com/openstack/heat/master/templates/MySQL_Single_Instance.template", + "Parameters": { + "KeyName" : { "Ref": "KeyName" }, + "InstanceType" : { "Ref": "InstanceType" }, + "DBName" : { "Ref": "DBName" }, + "DBUsername" : { "Ref": "DBUsername" }, + "DBPassword" : { "Ref": "DBPassword" }, + "DBRootPassword" : { "Ref": "DBRootPassword" }, + "LinuxDistribution": { "Ref": "LinuxDistribution" } + } + } + }, + + "WikiServerOne": { + "Type": "AWS::EC2::Instance", + "DependsOn" : "DatabaseServer", + "Metadata": { + "AWS::CloudFormation::Init": { + "config": { + "packages": { + "yum": { + "httpd" : [], + "wordpress" : [] + } + }, + "services": { + "systemd": { + "httpd" : { "enabled": "true", "ensureRunning": "true" } + } + } + } + } + }, + "Properties": { + "ImageId": { "Fn::FindInMap": [ "DistroArch2AMI", { "Ref": "LinuxDistribution" }, + { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref": "InstanceType" }, + "KeyName" : { "Ref": "KeyName" }, + "UserData" : { "Fn::Base64": { "Fn::Join": ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref": "DBName" }, + "/ --e s/username_here/", { "Ref": "DBUsername" }, + "/ --e s/password_here/", { "Ref": "DBPassword" }, + "/ --e s/localhost/", { "Fn::GetAtt": [ "DatabaseServer", "Outputs.PublicIp" ]}, + "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + }, + + "LoadBalancer" : { + "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", + "Properties" : { + "AvailabilityZones" : { "Fn::GetAZs" : "" }, + "Instances" : [{"Ref": "WikiServerOne"}], + "Listeners" : [ { + "LoadBalancerPort" : "80", + "InstancePort" : "80", + "Protocol" : "HTTP" + }] + } + } + }, + + "Outputs": { + "WebsiteURL": { + "Value": { "Fn::Join": ["", ["http://", { "Fn::GetAtt": [ "LoadBalancer", "DNSName" ]}, "/wordpress"]] }, + "Description": "URL for Wordpress wiki" + } + } +} diff --git a/cfn/WordPress_With_RDS.template b/cfn/WordPress_With_RDS.template new file mode 100644 index 00000000..d8a917e9 --- /dev/null +++ b/cfn/WordPress_With_RDS.template @@ -0,0 +1,170 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "AWS CloudFormation Sample Template WordPress_With_RDS: 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 RDS as a data storage.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.large", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBClass" : { + "Default" : "db.m1.small", + "Description" : "Database instance class", + "Type" : "String", + "AllowedValues" : [ "db.m1.small", "db.m1.large", "db.m1.xlarge", "db.m2.xlarge", "db.m2.2xlarge", "db.m2.4xlarge" ], + "ConstraintDescription" : "must select a valid database instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBAllocatedStorage" : { + "Default": "5", + "Description" : "The size of the database (Gb)", + "Type": "Number", + "MinValue": "5", + "MaxValue": "1024", + "ConstraintDescription" : "must be between 5 and 1024Gb." + }, + + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "DatabaseServer": { + "Type": "AWS::RDS::DBInstance", + "Properties": { + "DBName" : { "Ref" : "DBName" }, + "Engine" : "MySQL", + "MasterUsername" : { "Ref" : "DBUsername" }, + "DBInstanceClass" : { "Ref" : "DBClass" }, + "DBSecurityGroups" : [], + "AllocatedStorage" : { "Ref" : "DBAllocatedStorage" }, + "MasterUserPassword": { "Ref" : "DBPassword" } + } + }, + + "WebServer": { + "Type": "AWS::EC2::Instance", + "DependsOn": "DatabaseServer", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n", + "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ --e s/localhost/", { "Fn::GetAtt" : [ "DatabaseServer", "Endpoint.Address" ]}, "/ /usr/share/wordpress/wp-config.php\n", + "systemctl restart httpd.service\n" + ]]}} + } + } + + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +} diff --git a/cfn/getting_started.template b/cfn/getting_started.template new file mode 100644 index 00000000..9cc19eb6 --- /dev/null +++ b/cfn/getting_started.template @@ -0,0 +1,29 @@ +{ + "AWSTemplateFormatVersion" : "2010-09-09", + "Parameters" : { + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", + "Type" : "String" + } + }, + + "Resources" : { + "MyInstance" : { + "Type" : "AWS::EC2::Instance", + "Properties" : { + "KeyName" : { "Ref" : "KeyName" }, + "ImageId" : "F17-x86_64-cfntools", + "InstanceType": "m1.large", + "UserData" : { "Fn::Base64" : "80" } + } + } + }, + "Outputs" : { + "InstanceIp" : { + "Value" : { "Fn::Join" : ["", ["ssh ec2-user@", + {"Fn::GetAtt": ["MyInstance", + "PublicIp"]}]]}, + "Description" : "My ssh command" + } + } +} diff --git a/tools/cfn-json2yaml b/tools/cfn-json2yaml new file mode 100755 index 00000000..fd855956 --- /dev/null +++ b/tools/cfn-json2yaml @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import sys +import os +import yaml +import json +import re +from heat.common import template_format + +def main(): + path = sys.argv[1] + if os.path.isdir(path): + convert_directory(path) + elif os.path.isfile(path): + convert_file(path) + else: + print 'File or directory not valid: %s' % path + +def convert_file(path): + f = open(path, 'r') + print template_format.convert_json_to_yaml(f.read()) + +def convert_directory(dirpath): + for path in os.listdir(dirpath): + if not path.endswith('.template') and not path.endswith('.json'): + continue + yamlpath = re.sub('\..*$', '.yaml', path) + print 'Writing to %s' % yamlpath + f = open(os.path.join(dirpath, path), 'r') + out = open(os.path.join(dirpath, yamlpath), 'w') + yml = template_format.convert_json_to_yaml(f.read()) + out.write(yml) + out.close() + +if __name__ == '__main__': + main() diff --git a/tools/fetch-cloudformation-examples b/tools/fetch-cloudformation-examples new file mode 100755 index 00000000..4650dd2a --- /dev/null +++ b/tools/fetch-cloudformation-examples @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import httplib +import os +import sys +import shutil +import xml.etree.ElementTree as xml + +basepath = os.path.abspath(os.path.join(sys.argv[0], + os.path.pardir, + os.path.pardir, + 'templates', + 'cloudformation-examples')) + +bucket = 'cloudformation-templates-us-east-1' + +def main(): + conn = httplib.HTTPConnection('s3.amazonaws.com') + conn.request('GET', '/%s/' % bucket) + resp = conn.getresponse() + + tree = xml.parse(resp) + rootElement = tree.getroot() + + if os.path.exists(basepath): + print 'Deleting %s' % basepath + shutil.rmtree(basepath) + + os.makedirs(basepath) + print 'Creating %s' % basepath + + for entry in rootElement.iter('{http://s3.amazonaws.com/doc/2006-03-01/}Key'): + key = entry.text + if key.endswith('.html'): + continue + filename = os.path.join(basepath, key) + + print 'Writing to %s' % filename + conn.request('GET', '/%s/%s' % (bucket, key)) + resp = conn.getresponse() + contents = resp.read() + + f = open(filename, 'w') + f.write(contents) + f.close() + +if __name__ == '__main__': + main()