aws-nakama-stack/cloudformation/nakama/top.yaml

199 lines
6.4 KiB
YAML
Raw Normal View History

2019-10-23 07:03:54 +02:00
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."
2019-10-24 01:44:48 +02:00
VpcId:
Description: ID of the VPC
Type: AWS::EC2::VPC::Id
2019-10-23 07:03:54 +02:00
#-------------------
# ECS Configuration
#-------------------
EcsCluster:
Type: String
Description: The cluster to run the Nakama service on.
#-----------------
# Load Balancing
#-----------------
PublicSubnets:
Description: The public subnets for the ALB to run in.
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: ""
2019-10-24 01:44:48 +02:00
#------------------------
# Database Configuration
#------------------------
2019-10-24 01:44:48 +02:00
CreateDatabase:
Type: String
Default: "true"
AllowedValues: ["true", "false"]
# Manual Database Configuration
2019-10-23 07:03:54 +02:00
DatabaseUsername:
Type: String
Description: Username of the Postgres server
Default: postgres
DatabasePassword:
Type: String
Description: Password for the Postgres server
2019-10-24 01:44:48 +02:00
Default: ""
2019-10-23 07:03:54 +02:00
DatabaseEndpoint:
Type: String
Description: Endpoint for the Postgres server
2019-10-24 01:44:48 +02:00
Default: ""
2019-10-23 07:03:54 +02:00
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"
2019-11-11 02:02:43 +01:00
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
2019-10-24 01:44:48 +02:00
Conditions:
CreateRdsStack: !Equals [!Ref CreateDatabase, "true"]
2019-11-11 02:02:43 +01:00
CreateDns: !Not [!Equals [!Ref Domain, ""]]
2019-10-24 01:44:48 +02:00
2019-10-23 07:03:54 +02:00
Resources:
2019-11-11 02:02:43 +01:00
#-----
# 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
2019-11-11 02:55:35 +01:00
NakamaDns: !GetAtt LoadBalancing.Outputs.PublicNlbDnsName
AdminDns: !GetAtt LoadBalancing.Outputs.PublicAlbDnsName
2019-11-11 02:02:43 +01:00
2019-10-24 01:44:48 +02:00
#----------
# 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
2019-10-24 01:44:48 +02:00
2019-10-23 07:03:54 +02:00
#-----------------
# Load Balancing
#-----------------
2019-11-11 02:55:35 +01:00
LoadBalancing:
Type: AWS::CloudFormation::Stack
2019-10-23 07:03:54 +02:00
Properties:
2019-11-11 02:55:35 +01:00
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/${release}/cloudformation/nakama/load_balancing.yaml'
Parameters:
environment: !Ref environment
release: !Ref release
VpcId: !Ref VpcId
PublicSubnets: !Ref PublicSubnets
PortalCertificate: !Ref PortalCertificate
2019-10-23 07:03:54 +02:00
#-------------------
# ECS Task & Service
#-------------------
TaskDefinition:
Type: AWS::CloudFormation::Stack
Properties:
2019-10-23 07:26:00 +02:00
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/nakama/${release}/cloudformation/nakama/task.yaml'
2019-10-23 07:03:54 +02:00
Parameters:
2019-10-24 01:44:48 +02:00
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
2019-10-23 07:03:54 +02:00
EcsService:
2019-11-11 02:55:35 +01:00
DependsOn: LoadBalancing
2019-10-23 07:03:54 +02:00
Type: AWS::ECS::Service
Properties:
Cluster: !Ref EcsCluster
DesiredCount: 1
TaskDefinition: !GetAtt TaskDefinition.Outputs.TaskArn
LoadBalancers:
- ContainerName: "nakama"
ContainerPort: 7351
2019-11-11 02:55:35 +01:00
TargetGroupArn: !GetAtt LoadBalancing.Outputs.AdminPortalTargetGroup
- ContainerName: "nakama"
ContainerPort: 7350
2019-11-11 02:55:35 +01:00
TargetGroupArn: !GetAtt LoadBalancing.Outputs.HttpApiTargetGroup
- ContainerName: "nakama"
ContainerPort: 7349
2019-11-11 02:55:35 +01:00
TargetGroupArn: !GetAtt LoadBalancing.Outputs.GRpcApiTargetGroup
- ContainerName: "nakama"
ContainerPort: 7348
2019-11-11 02:55:35 +01:00
TargetGroupArn: !GetAtt LoadBalancing.Outputs.GRpcEApiTargetGroup