Description:  "AWS CloudFormation Sample Template DocumentDB_Quick_Create: Sample template showing how to create a DocumentDB DB cluster and DB instance. **WARNING** This template creates an Amazon DocumentDB resources and you will be billed for the AWS resources used if you create a stack from this template."

Parameters: 
  DBClusterName: 
    Default: "MyCluster"
    Description : "Cluster name"
    Type: "String"
    MinLength: "1"
    MaxLength: "64"
    AllowedPattern : "[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*"
    ConstraintDescription : "Must begin with a letter and contain only alphanumeric characters."

  DBInstanceName: 
    Default: "MyInstance"
    Description : "Instance name"
    Type: "String"
    MinLength: "1"
    MaxLength: "64"
    AllowedPattern : "[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*"
    ConstraintDescription : "Must begin with a letter and contain only alphanumeric characters."

  MasterUser:
    NoEcho: "true"
    Description : "The database admin account username"
    Type: "String"
    MinLength: "1"
    MaxLength: "16"
    AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*"
    ConstraintDescription : "Must begin with a letter and contain only alphanumeric characters."

  MasterPassword:
    NoEcho: "true"
    Description : "The database admin account password"
    Type: "String"
    MinLength: "1"
    MaxLength: "41"
    AllowedPattern : "[a-zA-Z0-9]+"
    ConstraintDescription : "must contain only alphanumeric characters."

  DBInstanceClass:
    Description : "Instance class. Please refer to: https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-classes-by-region"
    Type: "String"
    AllowedValues:
      - db.t3.medium
      - db.r5.large
      - db.r5.xlarge
      - db.r5.2xlarge
      - db.r5.4xlarge
      - db.r5.12xlarge
      - db.r5.24xlarge                             
    ConstraintDescription : "Instance type must be of the ones supported for the region. Please refer to: https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-classes-by-region"  

Resources:
  DBCluster:
    Type: "AWS::DocDB::DBCluster"
    DeletionPolicy: Delete
    Properties:
      DBClusterIdentifier: !Ref DBClusterName
      MasterUsername: !Ref MasterUser
      MasterUserPassword: !Ref MasterPassword
      EngineVersion: 4.0.0

  DBInstance:
    Type: "AWS::DocDB::DBInstance"
    Properties:
      DBClusterIdentifier: !Ref DBCluster
      DBInstanceIdentifier: !Ref DBInstanceName
      DBInstanceClass: !Ref DBInstanceClass
    DependsOn: DBCluster

Outputs:
  ClusterId:
    Value: !Ref DBCluster
  ClusterEndpoint:
    Value: !GetAtt DBCluster.Endpoint
  ClusterPort:
    Value: !GetAtt DBCluster.Port
  EngineVersion:
    Value: "4.0.0"

