/
1st recommend.yaml
211 lines (197 loc) · 5.38 KB
/
1st recommend.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
AWSTemplateFormatVersion: "2010-09-09"
Metadata:
Generator: "former2"
Description: "CFn Template for Former2 Test"
Parameters:
AllowedCIDR:
Description: "cidr to allow ssh access to ec2"
Type: String
Default: "111.111.111.111/24"
Resources:
EC2Instance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: "ami-0f9816f78187c68fb"
InstanceType: "t2.micro"
KeyName: "publicTestKey"
AvailabilityZone: !GetAtt EC2Subnet2.AvailabilityZone
Tenancy: "default"
SubnetId: !Ref EC2Subnet2
EbsOptimized: false
SecurityGroupIds:
- !Ref EC2SecurityGroup2
SourceDestCheck: false # Disable source/destination checking for increased security
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
Encrypted: true # Enable EBS volume encryption for data at rest
VolumeSize: 8
VolumeType: "gp3"
DeleteOnTermination: true
Tags:
- Key: "prj"
Value: "former"
- Key: "Name"
Value: "test1"
HibernationOptions:
Configured: false
EnclaveOptions:
Enabled: false
EC2Instance2:
Type: "AWS::EC2::Instance"
Properties:
ImageId: "ami-0f9816f78187c68fb"
InstanceType: "t2.micro"
KeyName: "publicTestKey"
AvailabilityZone: !GetAtt EC2Subnet.AvailabilityZone
Tenancy: "default"
SubnetId: !Ref EC2Subnet
EbsOptimized: false
SecurityGroupIds:
- !Ref EC2SecurityGroup2
SourceDestCheck: false # Disable source/destination checking for increased security
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
Encrypted: true # Enable EBS volume encryption for data at rest
VolumeSize: 8
VolumeType: "gp3"
DeleteOnTermination: true
Tags:
- Key: "Name"
Value: "test2"
- Key: "prj"
Value: "former"
HibernationOptions:
Configured: false
EnclaveOptions:
Enabled: false
EC2SecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "former-rds"
GroupName: "former-rds"
Tags:
- Key: "prj"
Value: "former"
VpcId: !Ref EC2VPC
SecurityGroupIngress:
- CidrIp: !GetAtt EC2VPC.CidrBlock
FromPort: !GetAtt RDSDBInstance.Endpoint.Port
IpProtocol: "tcp"
ToPort: !GetAtt RDSDBInstance.Endpoint.Port
SecurityGroupEgress:
- CidrIp: "0.0.0.0/0"
IpProtocol: "-1"
EC2SecurityGroup2:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "formertest-ec2"
GroupName: "formertest-ec2"
Tags:
- Key: "prj"
Value: "former"
VpcId: !Ref EC2VPC
SecurityGroupIngress:
- CidrIp: !Ref AllowedCIDR
FromPort: 22
ToPort: 22
IpProtocol: "tcp"
- CidrIp: !Ref AllowedCIDR
FromPort: 80
ToPort: 80
IpProtocol: "tcp"
SecurityGroupEgress:
- CidrIp: "0.0.0.0/0"
IpProtocol: "-1"
EC2VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsHostnames: true
EnableDnsSupport: true
InstanceTenancy: "default"
Tags:
- Key: "prj"
Value: "former"
EC2Subnet:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: "ap-northeast-1a"
CidrBlock: "10.0.1.0/24"
MapPublicIpOnLaunch: false
VpcId: !Ref EC2VPC
Tags:
- Key: "prj"
Value: "former"
EC2Subnet2:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: "ap-northeast-1c"
CidrBlock: "10.0.2.0/24"
MapPublicIpOnLaunch: false
VpcId: !Ref EC2VPC
Tags:
- Key: "prj"
Value: "former"
EC2InternetGateway:
Type: "AWS::EC2::InternetGateway"
Properties:
Tags:
- Key: "prj"
Value: "former"
EC2VPCGatewayAttachment:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
VpcId: !Ref EC2VPC
InternetGatewayId: !Ref EC2InternetGateway
EC2RouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref EC2VPC
Tags:
- Key: "prj"
Value: "former"
EC2RouteTable2:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref EC2VPC
Tags:
- Key: "prj"
Value: "former"
EC2Route:
Type: "AWS::EC2::Route"
Properties:
RouteTableId: !Ref EC2RouteTable
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref EC2InternetGateway
EC2Route2:
Type: "AWS::EC2::Route"
Properties:
RouteTableId: !Ref EC2RouteTable2
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref EC2InternetGateway
RDSDBInstance:
Type: "AWS::RDS::DBInstance"
Properties:
Engine: "mysql"
EngineVersion: "5.7"
DBInstanceIdentifier: "mydbinstance"
AllocatedStorage: 20
DBInstanceClass: "db.t2.micro"
MasterUsername: "admin"
MasterUserPassword: "password123"
VPCSecurityGroups:
- !Ref EC2SecurityGroup
MultiAZ: false
StorageEncrypted: true # Enable RDS storage encryption for data at rest
Tags:
- Key: "prj"
Value: "former"
Outputs:
EC2Instance1IP:
Value: !Ref EC2Instance
EC2Instance2IP:
Value: !Ref EC2Instance2
RDSDBEndpoint:
Value: !GetAtt RDSDBInstance.Endpoint.Address