-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformationstudy.yml
187 lines (166 loc) · 4.42 KB
/
cloudformationstudy.yml
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
AWSTemplateFormatVersion: "2010-09-09"
Description: cloudformation study
#パラメータ
Parameters:
vpcid:
Type: AWS::EC2::VPC::Id
Description: Enter vpcid
privatesubnet1CidrBlock:
Type: String
Description: Enter privatesubnet1 CidrBlock
privatesubnet2CidrBlock:
Type: String
Description: Enter privatesubnet2 CidrBlock
myip:
Type: String
Description: Enter myip
imageid:
Type: AWS::EC2::Image::Id
Description: Enter imageid
rootdevicename:
Type: String
Description: Enter rootdevicename
keyname:
Type: AWS::EC2::KeyPair::KeyName
Description: Enter keyname
rdspassword:
Type: String
Description: Enter rds password
MinLength: '8'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
#リソース
Resources:
privatesubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-1a
CidrBlock: !Ref privatesubnet1CidrBlock
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: privatesubnet1
VpcId: !Ref vpcid
privatesubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-1c
CidrBlock: !Ref privatesubnet2CidrBlock
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: privatesubnet2
VpcId: !Ref vpcid
privateroutetable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: privateroutetable
VpcId: !Ref vpcid
routetableattach1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref privateroutetable
SubnetId: !Ref privatesubnet1
routetableattach2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref privateroutetable
SubnetId: !Ref privatesubnet2
ec2securitygroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ec2-securitygroup
SecurityGroupEgress:
- IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIpv6: ::/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIpv6: ::/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref myip
VpcId: !Ref vpcid
rdssecuritygroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: rds-securitygroup
SecurityGroupEgress:
- IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
SourceSecurityGroupId: !Ref ec2securitygroup
VpcId: !Ref vpcid
ec2instance:
Type: AWS::EC2::Instance
Properties:
BlockDeviceMappings:
- DeviceName: !Ref rootdevicename
Ebs:
DeleteOnTermination: true
VolumeSize: 16
VolumeType: gp2
ImageId: !Ref imageid
InstanceType: #インスタンスタイプ入力
KeyName: !Ref keyname
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeleteOnTermination: true
DeviceIndex: "0"
GroupSet:
- !Ref ec2securitygroup
SubnetId: #サブネットID入力
Tags:
- Key: Name
Value: ec2instance
rdssubnetgroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: rdssubnetgroup
SubnetIds:
- !Ref privatesubnet1
- !Ref privatesubnet2
DBSubnetGroupName: #サブネットグループ名入力
Tags:
- Key: Name
Value: rdssubnetgroup
rdsinstance:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: #ストレージ量入力
DBInstanceClass: #インスタンスクラス入力
DBSubnetGroupName:
!Ref rdssubnetgroup
Engine: mysql
EngineVersion: "5.7.34"
MasterUsername: #DBユーザ名入力
MasterUserPassword: !Ref rdspassword
StorageType: gp2
Tags:
- Key: Name
Value: rdsinstance
VPCSecurityGroups:
- !Ref rdssecuritygroup