-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
53 lines (47 loc) · 1.6 KB
/
template.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
AWSTemplateFormatVersion: 2010-09-09
Description: |
The ec2 instance configuration
Parameters:
NetworkStack:
Type: String
Description: This is our base layer of networking components eg. VPC, Subnets
Default: TestUbuntuNet
Resources:
WebServerInstance:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#aws-properties-ec2-instance--examples
Type: AWS::EC2::Instance
Properties:
ImageId: "ami-053b0d53c279acc90"
InstanceType: "t2.micro"
KeyName: "terraform-demo"
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Fn::ImportValue: !Sub ${NetworkStack}SecurityGroupId
SubnetId:
Fn::Select:
- 0 # Index 0 to get the first subnet
- Fn::Split:
- ","
- Fn::ImportValue: !Sub "${NetworkStack}PublicSubnetIds"
UserData:
Fn::Base64: |
#!/bin/bash
sudo apt update -y
sudo apt install apache2 -y
sudo systemctl start apache2
sudo bash -c 'echo "Cloudformation first web server" > /var/www/html/index.html'
Tags:
- Key: Name
Value: "test-ubuntu-ec2-instance"
Outputs:
ServerPublicIP:
Description: "Public IP of the EC2 instance"
Value: !GetAtt WebServerInstance.PublicIp
ServerPrivateIP:
Description: "Private IP of the EC2 instance"
Value: !GetAtt WebServerInstance.PrivateIp
ServerInstanceID:
Description: "Instance ID of the EC2 instance"
Value: !Ref WebServerInstance