-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds.yaml
87 lines (83 loc) · 2.5 KB
/
rds.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
AWSTemplateFormatVersion: 2010-09-09
Description: Hands-on template for RDS
#------------------------------------------------------
# AWS CLIの実行の仕方
# aws cloudformation create-stack --stack-name handson-cfn-rds --template-body file://ec2.yaml
#
# スタック名
# handson-cfn-rds
# DBユーザー
# dbmaster
# パスワード
# H&ppyHands0n
#
# データベース名
# wordpress
#------------------------------------------------------
#------------------------------------------------------
# パラメーター(RDS)
#------------------------------------------------------
Parameters:
VPCStack:
Type: String
Default: handson-cfn
DBUser:
Type: String
Default: dbmaster
DBPassword:
Type: String
Default: H&ppyHands0n
NoEcho: true
#------------------------------------------------------
# RDSInstance
#------------------------------------------------------
Resources:
DBInstance:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
Properties:
DBInstanceClass: db.t3.micro
AllocatedStorage: "10"
StorageType: gp2
Engine: MySQL
MasterUsername: !Ref DBUser
MasterUserPassword: !Ref DBPassword
DBName: wordpress
BackupRetentionPeriod: 0
MultiAZ: 'false'
AvailabilityZone: !Sub ${AWS::Region}a
DBSubnetGroupName: !Ref DBSubnetGroup
VPCSecurityGroups:
- !Ref DBSecurityGroup
#------------------------------------------------------
# サブネット
#------------------------------------------------------
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: DB Subnet Group for Private Subnet
SubnetIds:
- Fn::ImportValue: !Sub ${VPCStack}-PrivateSubnet1
- Fn::ImportValue: !Sub ${VPCStack}-PrivateSubnet2
#------------------------------------------------------
# セキュリティーグループ(EC2Instance)
#------------------------------------------------------
DBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Sub ${AWS::StackName}-MySQL
VpcId:
Fn::ImportValue: !Sub ${VPCStack}-VPCID
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: 10.0.0.0/24
#------------------------------------------------------
# Outputsセクション
#------------------------------------------------------
Outputs:
DBEndpoint:
Value: !GetAtt DBInstance.Endpoint.Address
Export:
Name: !Sub ${AWS::StackName}-DBEndpoint