Resources:
  MyDatabaseDbSubnetGroup:
    Properties:
      DBSubnetGroupDescription: DBSubnetGroup
      SubnetIds:
      - Ref: MyDatabaseSubnetGroupSubnet
      - Ref: MyDatabaseSubnetGroupSubnet2
      - Ref: MyDatabaseSubnetGroupSubnet3
    Type: AWS::RDS::DBSubnetGroup
  MyDatabaseSubnetGroupSubnet:
    Properties:
      AvailabilityZone:
        Fn::Select:
        - 0
        - Fn::GetAZs: ''
      CidrBlock: 10.0.8.0/26
      Tags:
      - Key: Name
        Value: MyDatabaseSubnetGroupSubnet
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::Subnet
  MyDatabaseSubnetGroupSubnet2:
    Properties:
      AvailabilityZone:
        Fn::Select:
        - 1
        - Fn::GetAZs: ''
      CidrBlock: 10.0.8.64/26
      Tags:
      - Key: Name
        Value: MyDatabaseSubnetGroupSubnet2
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::Subnet
  MyDatabaseSubnetGroupSubnet3:
    Properties:
      AvailabilityZone:
        Fn::Select:
        - 2
        - Fn::GetAZs: ''
      CidrBlock: 10.0.8.128/26
      Tags:
      - Key: Name
        Value: MyDatabaseSubnetGroupSubnet3
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::Subnet
  MyDatabaseSubnetGroupSubnetRouteTableAssociation:
    Properties:
      RouteTableId:
        Ref: MyDatabaseSkeletonRouteTable
      SubnetId:
        Ref: MyDatabaseSubnetGroupSubnet
    Type: AWS::EC2::SubnetRouteTableAssociation
  MyDatabaseSubnetGroupSubnetRouteTableAssociation2:
    Properties:
      RouteTableId:
        Ref: MyDatabaseSkeletonRouteTable
      SubnetId:
        Ref: MyDatabaseSubnetGroupSubnet2
    Type: AWS::EC2::SubnetRouteTableAssociation
  MyDatabaseSubnetGroupSubnetRouteTableAssociation3:
    Properties:
      RouteTableId:
        Ref: MyDatabaseSkeletonRouteTable
      SubnetId:
        Ref: MyDatabaseSubnetGroupSubnet3
    Type: AWS::EC2::SubnetRouteTableAssociation
  SkeletonVpc:
    Properties:
      CidrBlock: 10.0.0.0/16
    Type: AWS::EC2::VPC
  MyDatabaseSkeletonRoute:
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: SkeletonInternetGateway
      RouteTableId:
        Ref: MyDatabaseSkeletonRouteTable
    Type: AWS::EC2::Route
  MyDatabaseSkeletonRouteTable:
    Properties:
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::RouteTable
  SkeletonInternetGateway:
    Type: AWS::EC2::InternetGateway
  MyDatabaseFirewallSecurityGroup:
    Properties:
      GroupDescription: SecurityGroup
      SecurityGroupIngress:
      - CidrIp: 10.0.0.0/16
        FromPort: 5432
        IpProtocol: 6
        ToPort: 5432
      Tags:
      - Key: Name
        Value: MyDatabaseFirewallSecurityGroup
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::SecurityGroup
  SkeletonVpcGatewayAttachment:
    Properties:
      InternetGatewayId:
        Ref: SkeletonInternetGateway
      VpcId:
        Ref: SkeletonVpc
    Type: AWS::EC2::VPCGatewayAttachment

  AuroraPrimaryInstance:
    DeletionPolicy: Retain
    Properties:
      AllowMajorVersionUpgrade: true
      AutoMinorVersionUpgrade: true
      DBClusterIdentifier:
        Ref: AuroraCluster
      DBInstanceClass: db.t3.medium
      DBSubnetGroupName:
        Ref: MyDatabaseDbSubnetGroup
      EnablePerformanceInsights: true
      Engine: aurora-postgresql
      EngineVersion: '11.7'
      PubliclyAccessible: false
    Type: AWS::RDS::DBInstance
  AuroraCluster:
    DeletionPolicy: Retain
    Properties:
      AvailabilityZones:
      - Fn::Select:
        - 0
        - Fn::GetAZs: ''
      - Fn::Select:
        - 1
        - Fn::GetAZs: ''
      - Fn::Select:
        - 2
        - Fn::GetAZs: ''
      BackupRetentionPeriod: '1'
      MasterUsername: root
      MasterUserPassword: ypWTXyFkmVFQGfqsRLzFjhEmsijXh32b
      DBSubnetGroupName:
        Ref: MyDatabaseDbSubnetGroup
      Engine: aurora-postgresql
      EngineVersion: '11.7'
      Port: '5432'
      VpcSecurityGroupIds:
      - Fn::GetAtt:
        - MyDatabaseFirewallSecurityGroup
        - GroupId
    Type: AWS::RDS::DBCluster
