Skip to content

Instantly share code, notes, and snippets.

@sajuptpm
Forked from therve/template7
Created March 24, 2014 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajuptpm/9738831 to your computer and use it in GitHub Desktop.
Save sajuptpm/9738831 to your computer and use it in GitHub Desktop.
heat_template_version: 2013-05-23
parameters:
subnet_id:
type: string
resources:
mydb:
type: OS::DBInstance
properties:
database_name: wordpress
database_user: wordpress
database_password: wordpress_password
database_root_password: root_password
cfn_user:
type: AWS::IAM::User
web_server_keys:
type: AWS::IAM::AccessKey
properties:
UserName: {get_resource: cfn_user}
web_server_group:
type: AWS::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones: [nova]
LaunchConfigurationName: {get_resource: launch_config}
MinSize: 1
MaxSize: 3
LoadBalancerNames:
- {get_resource: mylb}
web_server_scaleup_policy:
type: AWS::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: {get_resource: web_server_group}
Cooldown: 60
ScalingAdjustment: 1
web_server_scaledown_policy:
type: AWS::AutoScaling::ScalingPolicy
properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: {get_resource: web_server_group}
Cooldown: 60
ScalingAdjustment: -1
cpu_alarm_high:
type: OS::Metering::Alarm
properties:
description: Scale-up if the average CPU > 50% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 50
alarm_actions:
- {get_attr: [web_server_scaleup_policy, AlarmUrl]}
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}}
comparison_operator: gt
cpu_alarm_low:
type: OS::Metering::Alarm
properties:
description: Scale-down if the average CPU < 15% for 1 minute
meter_name: cpu_util
statistic: avg
period: 600
evaluation_periods: 1
threshold: 15
alarm_actions:
- {get_attr: [web_server_scaledown_policy, AlarmUrl]}
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}}
comparison_operator: lt
mymonitor:
type: OS::Neutron::HealthMonitor
properties:
type: TCP
delay: 3
max_retries: 5
timeout: 5
mypool:
type: OS::Neutron::Pool
properties:
protocol: HTTP
monitors: [{get_resource: mymonitor}]
subnet_id: {get_param: subnet_id}
lb_method: ROUND_ROBIN
vip:
protocol_port: 80
mylb:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: {get_resource: mypool}
launch_config:
type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
config:
files:
/etc/cfn/cfn-credentials:
content:
str_replace:
template: |
AWSAccessKeyId=$key
AWSSecretKey=$secret
params:
$key: {get_resource: web_server_keys}
$secret: {get_attr: [web_server_keys, SecretAccessKey]}
mode: '000400'
owner: root
group: root
packages:
yum:
httpd: []
wordpress: []
services:
systemd:
httpd: {enabled: 'true', ensureRunning: 'true'}
properties:
ImageId: Fedora-x86_64-20-20131211.1-sda
InstanceType: m1.small
KeyName: heat
UserData:
str_replace:
template: |
#!/bin/bash -v
/opt/aws/bin/cfn-init
firewall-cmd --add-service=http
firewall-cmd --permanent --add-service=http
setsebool -P httpd_can_network_connect_db=1
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 -i s/database_name_here/wordpress/ /etc/wordpress/wp-config.php
sed -i s/username_here/wordpress/ /etc/wordpress/wp-config.php
sed -i s/password_here/wordpress_password/ /etc/wordpress/wp-config.php
sed -i s/localhost/$db_host/ /etc/wordpress/wp-config.php
systemctl restart httpd.service
params:
$db_host: {get_attr: [mydb, server_address]}
@sajuptpm
Copy link
Author

Example template with AutoScaling and Load balancing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment