aws-nakama-stack/cloudformation/nakama/top.yaml
Joseph Manley 89c10fffde Integrated cluster into stack
Update pipes

Update actions/checkout

Fix s3 url
2020-04-26 00:44:43 -04:00

215 lines
7.1 KiB
YAML

AWSTemplateFormatVersion: '2010-09-09'
Description: Nakama ECS Service
Parameters:
#------------------------
# Deployment Information
#------------------------
environment:
Type: String
Description: Name of the environment to use in naming.
Default: production
release:
Type: String
Description: Name of the release name of the stack version to use.
Default: production
AllowedValues: ['develop', 'production']
ConstraintDescription: "Must be a possible release version."
VpcId:
Description: ID of the VPC
Type: AWS::EC2::VPC::Id
#-------------------
# ECS Configuration
#-------------------
EcsClusterOverride:
Type: String
Description: The cluster to run the Nakama service on, if empty will create new cluster
Default: ""
#-----------------
# Load Balancing
#-----------------
PublicSubnets:
Description: The public subnets for the ALB to run in. (Seperate by spaces)
Type: String
PortalCertificate:
Description: Arn of AWS Certificate
Type: String
#----------------------
# Nakama Configuration
#----------------------
NakamaUsername:
Type: String
Description: Username to access the Nakama admin portal
Default: "admin"
NakamaPasswordOverride:
Type: String
Description: Override Nakama admin portal password. Leave blank for random password.
Default: ""
#------------------------
# Database Configuration
#------------------------
CreateDatabase:
Type: String
Default: "true"
AllowedValues: ["true", "false"]
# Manual Database Configuration
DatabaseUsername:
Type: String
Description: Username of the Postgres server
Default: postgres
DatabasePassword:
Type: String
Description: Password for the Postgres server
Default: ""
DatabaseEndpoint:
Type: String
Description: Endpoint for the Postgres server
Default: ""
DatabasePort:
Type: Number
Description: Port for the Postgres server
Default: 5432
# Advanced RDS Configuration
RdsInstanceClass:
Type: String
Description: Instance class for the dabase to run on
Default: db.t2.micro
RdsEngine:
Type: String
Description: Database engine for the database to use
Default: postgres
AllowedValues: ["aurora", "aurora-mysql", "aurora-postgresql", "mariadb", "mysql", "oracle-ee", "oracle-se2", "oracle-se1", "oracle-se", "postgres", "sqlserver-ee", "sqlserver-se", "sqlserver-ex", "sqlserver-web"]
RdsUsername:
Type: String
Description: Master account's username for database
Default: postgres
RdsPort:
Type: Number
Description: Port for the database to open a socket on
Default: "5432"
RdsStorage:
Type: Number
Description: The amount of storage (in GB) allocated to the RDS instance
Default: "100"
RdsAccessCidr:
Type: String
Description: The CIDR used in the security group to secure the database
Default: "0.0.0.0/0"
Domain:
Type: String
Description: The domain to create the endpoint on (Must have an existing hosted zone ex. `example.com`) Leave blank to skip DNS.
Default: ""
SubDomain:
Type: String
Description: The subdomain to be used by nakama. (ex. `nakama.example.com`)
Default: nakama
Conditions:
CreateRdsStack: !Equals [!Ref CreateDatabase, "true"]
CreateDns: !Not [!Equals [!Ref Domain, ""]]
CreateCluster: !Equals [!Ref EcsClusterOverride, ""]
Resources:
#-----
# DNS
#-----
DnsRecords:
Condition: CreateDns
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/dns.yaml'
Parameters:
environment: !Ref environment
Domain: !Ref Domain
SubDomain: !Ref SubDomain
NakamaDns: !GetAtt LoadBalancing.Outputs.PublicNlbDnsName
AdminDns: !GetAtt LoadBalancing.Outputs.PublicAlbDnsName
#----------
# Database
#----------
RdsDatabase:
Condition: CreateRdsStack
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/rds.yaml'
Parameters:
environment: !Ref environment
VpcId: !Ref VpcId
InstanceClass: !Ref RdsInstanceClass
DatabaseEngine: !Ref RdsEngine
DatabaseUsername: !Ref RdsUsername
DatabasePort: !Ref RdsPort
DatabaseStorage: !Ref RdsStorage
DatabaseAccessCidr: !Ref RdsAccessCidr
#-----------------
# Load Balancing
#-----------------
LoadBalancing:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/load_balancing.yaml'
Parameters:
environment: !Ref environment
release: !Ref release
VpcId: !Ref VpcId
PublicSubnets: !Join [",", !Split [" ", !Ref PublicSubnets]]
PortalCertificate: !Ref PortalCertificate
#-------------
# ECS Cluster
#-------------
EcsCluster:
Condition: CreateCluster
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/cluster/top.yaml'
Parameters:
Environment: !Ref environment
VpcId: !Ref VpcId
SubnetIds: !Join [",", !Split [" ", !Ref PublicSubnets]]
Project: "Nakama"
#-------------------
# ECS Task & Service
#-------------------
TaskDefinition:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/task.yaml'
Parameters:
DatabaseUsername: !If ["CreateRdsStack", !GetAtt RdsDatabase.Outputs.RdsUsername, !Ref DatabaseUsername]
DatabasePassword: !If ["CreateRdsStack", !Join ["", ["{{resolve:secretsmanager:", !GetAtt RdsDatabase.Outputs.RdsSecret, ":SecretString}}" ]], !Ref DatabasePassword]
DatabaseEndpoint: !If ["CreateRdsStack", !GetAtt RdsDatabase.Outputs.RdsEnpoint, !Ref DatabaseEndpoint]
DatabasePort: !If ["CreateRdsStack", !GetAtt RdsDatabase.Outputs.RdsPort, !Ref DatabasePort]
NakamaUsername: !Ref NakamaUsername
NakamaPasswordOverride: !Ref NakamaPasswordOverride
EcsService:
DependsOn: LoadBalancing
Type: AWS::ECS::Service
Properties:
Cluster: !If ["CreateCluster", !GetAtt EcsCluster.Outputs.Cluster, !Ref EcsClusterOverride]
DesiredCount: 1
TaskDefinition: !GetAtt TaskDefinition.Outputs.TaskArn
LoadBalancers:
- ContainerName: "nakama"
ContainerPort: 7351
TargetGroupArn: !GetAtt LoadBalancing.Outputs.AdminPortalTargetGroup
- ContainerName: "nakama"
ContainerPort: 7350
TargetGroupArn: !GetAtt LoadBalancing.Outputs.HttpApiTargetGroup
- ContainerName: "nakama"
ContainerPort: 7349
TargetGroupArn: !GetAtt LoadBalancing.Outputs.GRpcApiTargetGroup
- ContainerName: "nakama"
ContainerPort: 7348
TargetGroupArn: !GetAtt LoadBalancing.Outputs.GRpcEApiTargetGroup