Created
July 5, 2023 01:17
-
-
Save riponbanik/cc79de9eb30783ea5baa2f15ee796e0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: 'Aurora PostgreSQL Cluster' | |
Parameters: | |
vpcId: | |
Type: 'AWS::EC2::VPC::Id' | |
Description: 'VPC Id' | |
SubnetList: | |
Type: 'List<AWS::EC2::Subnet::Id>' | |
Description: 'List of Subnet' | |
Availability: | |
Default: "NON" | |
Type: String | |
Description: "None, High Availablity" | |
AllowedValues: | |
- NON | |
- HA | |
DBEngine: | |
Description: Select Database Engine | |
Type: String | |
Default: aurora-postgresql | |
DBInstanceClass: | |
Default: db.t4g.medium | |
Description: Database Instance Class | |
Type: String | |
Conditions: | |
IsReplica: !Equals [!Ref Availability, 'HA'] | |
Resources: | |
DBSubnetGroup: | |
Type: 'AWS::RDS::DBSubnetGroup' | |
Properties: | |
DBSubnetGroupDescription: !Join ["", [!Ref AWS::StackName, "-rds-subnet-gp" ]] | |
SubnetIds: | |
- !Select [0, !Ref SubnetList] | |
- !Select [1, !Ref SubnetList] | |
- !Select [2, !Ref SubnetList] | |
DatabaseSecurityGroup: | |
Type: 'AWS::EC2::SecurityGroup' | |
Properties: | |
GroupDescription: !Join ["", ["sgp-", !Ref AWS::StackName, "-rds" ]] | |
VpcId: !Ref vpcId | |
SecurityGroupIngress: | |
- {IpProtocol: tcp, FromPort: 3306, ToPort: 3306, CidrIp: '10.0.0.0/8', Description: "DB Connection from Local Network"} | |
DBCluster: | |
Type: 'AWS::RDS::DBCluster' | |
Properties: | |
DBClusterIdentifier: !Ref AWS::StackName | |
Engine: !Ref DBEngine | |
EngineVersion: 15.2 | |
DBSubnetGroupName: !Ref DBSubnetGroup | |
VpcSecurityGroupIds: | |
- !Ref DatabaseSecurityGroup | |
MasterUsername: dbadmin | |
ManageMasterUserPassword: true | |
DBInstancePrimary: | |
Type: 'AWS::RDS::DBInstance' | |
Properties: | |
DBInstanceIdentifier: !Sub '${AWS::StackName}-primary' | |
DBClusterIdentifier: !Ref DBCluster | |
DBInstanceClass: !Ref DBInstanceClass | |
Engine: !Ref DBEngine | |
DBInstanceReplica: | |
Condition: IsReplica | |
Type: 'AWS::RDS::DBInstance' | |
Properties: | |
DBInstanceIdentifier: !Sub '${AWS::StackName}-replica' | |
DBClusterIdentifier: !Ref DBCluster | |
DBInstanceClass: !Ref DBInstanceClass | |
Engine: !Ref DBEngine | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment