This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
ebs.yaml
132 lines (132 loc) · 3.29 KB
/
ebs.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS in Action: chapter 9 (EBS)'
Parameters:
KeyName:
Description: Key Pair name
Type: 'AWS::EC2::KeyPair::KeyName'
Default: mykey
VPC:
Description: 'Just select the one and only default VPC'
Type: 'AWS::EC2::VPC::Id'
Subnet:
Description: 'Just select one of the available subnets'
Type: 'AWS::EC2::Subnet::Id'
AttachVolume:
Description: 'Should the volume be attached?'
Type: String
Default: 'yes'
AllowedValues:
- 'yes'
- 'no'
Mappings:
RegionMap:
'ap-south-1':
AMI: 'ami-2ed19c41'
'eu-west-3':
AMI: 'ami-c8a017b5'
'eu-west-2':
AMI: 'ami-e3051987'
'eu-west-1':
AMI: 'ami-760aaa0f'
'ap-northeast-2':
AMI: 'ami-fc862292'
'ap-northeast-1':
AMI: 'ami-2803ac4e'
'sa-east-1':
AMI: 'ami-1678037a'
'ca-central-1':
AMI: 'ami-ef3b838b'
'ap-southeast-1':
AMI: 'ami-dd7935be'
'ap-southeast-2':
AMI: 'ami-1a668878'
'eu-central-1':
AMI: 'ami-e28d098d'
'us-east-1':
AMI: 'ami-6057e21a'
'us-east-2':
AMI: 'ami-aa1b34cf'
'us-west-1':
AMI: 'ami-1a033c7a'
'us-west-2':
AMI: 'ami-32d8124a'
Conditions:
Attached: !Equals [!Ref AttachVolume, 'yes']
Resources:
SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'Allow incoming SSH from anywhere'
VpcId: !Ref VPC
SecurityGroupIngress:
- CidrIp: '0.0.0.0/0'
FromPort: 22
ToPort: 22
IpProtocol: tcp
Tags:
- Key: Name
Value: 'AWS in Action: chapter 9 (EBS)'
IamRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: 'ec2.amazonaws.com'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: ec2
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'ec2:DescribeVolumes'
- 'ec2:CreateSnapshot'
- 'ec2:DescribeSnapshots'
- 'ec2:DeleteSnapshot'
Resource: '*'
IamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref IamRole
EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
IamInstanceProfile: !Ref IamInstanceProfile
ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
InstanceType: 't2.micro'
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref SecurityGroup
SubnetId: !Ref Subnet
Tags:
- Key: Name
Value: 'AWS in Action: chapter 9 (EBS)'
Volume:
Type: 'AWS::EC2::Volume'
Properties:
AvailabilityZone: !Sub ${EC2Instance.AvailabilityZone}
Size: 5
VolumeType: gp2
Tags:
- Key: Name
Value: 'AWS in Action: chapter 9 (EBS)'
VolumeAttachment:
Type: 'AWS::EC2::VolumeAttachment'
Condition: Attached
Properties:
Device: '/dev/xvdf'
InstanceId: !Ref EC2Instance
VolumeId: !Ref Volume
Outputs:
PublicName:
Value: !Sub ${EC2Instance.PublicDnsName}
Description: 'Public name (connect via SSH as user ec2-user)'
VolumeId:
Value: !Ref Volume
Description: 'ID of the EBS volume'