forked from NeCTAR-RC/heat-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapache_single_instance_aws.yaml
117 lines (99 loc) · 3.91 KB
/
apache_single_instance_aws.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# http://docs.openstack.org/developer/heat/template_guide/hot_spec.html#heat-template-version
heat_template_version: 2014-10-16
description: >
A NeCTAR sample template that installs Apache on a single Ubuntu instance using the AWS::EC2::Instance resource
type.
parameters:
key_name:
type: string
description: Name of an existing KeyPair to enable SSH access to the instances
instance_type:
type: string
description: The NeCTAR flavour the webserver is to run on
default: m2.xsmall
constraints:
- allowed_values: [m2.xsmall, m2.small, m1.small]
description:
Must be a valid NeCTAR flavour, limited to the smaller ones available
image_name:
type: string
description: Name of the image to use for the instance to be created.
default: 'Ubuntu 14.04'
constraints:
- allowed_values: [ 'Ubuntu 14.04', 'Ubuntu 15.04' ]
description:
The version of Ubuntu to be launched
resources:
web_security_group:
# Use this when we do not have Neutron networking.
# http://docs.openstack.org/developer/heat/template_guide/cfn.html#AWS::EC2::SecurityGroup
type: AWS::EC2::SecurityGroup
properties:
GroupDescription: Web server access rules.
SecurityGroupIngress:
- { IpProtocol: icmp, FromPort: '-1', ToPort: '-1', 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 }
apache_server:
# http://docs.openstack.org/developer/heat/template_guide/cfn.html#AWS::EC2::Instance
type: AWS::EC2::Instance
# A deletion policy of Retain will leave this instance behind when this template is torn down.
# deletion_policy: Retain
metadata:
AWS::CloudFormation::Init:
config:
packages:
apt:
apache2: []
services:
systemd:
apache2: { enabled: 'true', ensureRunning: 'true' }
properties:
ImageId:
Fn::Select:
- { get_param: image_name }
-
'Ubuntu 14.04': 2a882d9c-3185-414c-9683-a4646b5c785e
'Ubuntu 15.04': 2ae1042a-8f8d-4f40-95c7-6d1e611714be
InstanceType: { get_param: instance_type }
KeyName: { get_param: key_name }
SecurityGroups: [ { get_resource: web_security_group } ]
# the following is written to /var/lib/cloud/data/cfn-userdata
# note the call to cfn-init which causes the AWS::CloudFomration::Init to be actioned
UserData:
str_replace:
template: |
#!/bin/bash -v
/usr/bin/cfn-init
/opt/aws/bin/cfn-signal -e 0 -r "Apache server setup complete" 'WaitHandle'
params:
WaitHandle: { get_resource: wait_handle }
# http://docs.openstack.org/developer/heat/template_guide/cfn.html#AWS::CloudFormation::WaitConditionHandle
wait_handle:
type: 'AWS::CloudFormation::WaitConditionHandle'
# http://docs.openstack.org/developer/heat/template_guide/cfn.html#AWS::CloudFormation::WaitCondition
wait_condition:
type: AWS::CloudFormation::WaitCondition
depends_on: apache_server
properties:
Handle: { get_resource: wait_handle }
Count: 1
# we'll give it 10 minutes
Timeout: 600
outputs:
instance_ip:
description: The IP address of the deployed instance
value: { get_attr: [apache_server, PublicIp] }
website_url:
description: URL for Apache server
value:
list_join: ['', ['http://', get_attr: [apache_server, PublicIp]]]
ssh_command:
description: SSH command for the newly created instance (assuming your key is in ~./ssh/).
value:
str_replace:
template: ssh ec2-user@host -i ~/.ssh/key.pem
params:
host: { get_attr: [apache_server, PublicIp] }
key: { get_param: key_name }