private static IInstanceEngine GetInstanceEngine(DeputyBase databaseEngineVersion, string edition = "ex")
        {
            var databaseType = databaseEngineVersion.GetType();

            if (databaseType == typeof(MysqlEngineVersion))
            {
                return(DatabaseInstanceEngine.Mysql(new MySqlInstanceEngineProps
                {
                    Version = databaseEngineVersion as MysqlEngineVersion
                }));
            }

            if (databaseType == typeof(PostgresEngineVersion))
            {
                return(DatabaseInstanceEngine.Postgres(new PostgresInstanceEngineProps()
                {
                    Version = databaseEngineVersion as PostgresEngineVersion
                }));
            }

            if (databaseType == typeof(MariaDbEngineVersion))
            {
                return(DatabaseInstanceEngine.MariaDb(new MariaDbInstanceEngineProps()
                {
                    Version = databaseEngineVersion as MariaDbEngineVersion
                }));
            }

            if (databaseType == typeof(SqlServerEngineVersion))
            {
                return(edition switch
                {
                    "ee" => DatabaseInstanceEngine.SqlServerEe(new SqlServerEeInstanceEngineProps()
                    {
                        Version = databaseEngineVersion as SqlServerEngineVersion
                    }),
                    "se" => DatabaseInstanceEngine.SqlServerSe(new SqlServerSeInstanceEngineProps()
                    {
                        Version = databaseEngineVersion as SqlServerEngineVersion
                    }),
                    "ex" => DatabaseInstanceEngine.SqlServerEx(new SqlServerExInstanceEngineProps()
                    {
                        Version = databaseEngineVersion as SqlServerEngineVersion
                    }),
                    "web" => DatabaseInstanceEngine.SqlServerWeb(new SqlServerWebInstanceEngineProps()
                    {
                        Version = databaseEngineVersion as SqlServerEngineVersion
                    }),
                    _ => throw new ArgumentException("The edition of the SQL Server is not recognized."),
                });
예제 #2
0
        private IInstanceEngine GetInstanceEngine(DeputyBase databaseEngineVersion)
        {
            var databaseType = databaseEngineVersion.GetType();

            if (databaseType == typeof(MysqlEngineVersion))
            {
                return(DatabaseInstanceEngine.Mysql(new MySqlInstanceEngineProps
                {
                    Version = databaseEngineVersion as MysqlEngineVersion
                }));
            }

            if (databaseType == typeof(PostgresEngineVersion))
            {
                return(DatabaseInstanceEngine.Postgres(new PostgresInstanceEngineProps()
                {
                    Version = databaseEngineVersion as PostgresEngineVersion
                }));
            }

            if (databaseType == typeof(MariaDbEngineVersion))
            {
                return(DatabaseInstanceEngine.MariaDb(new MariaDbInstanceEngineProps()
                {
                    Version = databaseEngineVersion as MariaDbEngineVersion
                }));
            }

            if (databaseType == typeof(SqlServerEngineVersion))
            {
                return(DatabaseInstanceEngine.SqlServerEe(new SqlServerEeInstanceEngineProps()
                {
                    Version = databaseEngineVersion as SqlServerEngineVersion
                }));
            }

            if (databaseType == typeof(OracleEngineVersion))
            {
                return(DatabaseInstanceEngine.OracleEe(new OracleEeInstanceEngineProps()
                {
                    Version = databaseEngineVersion as OracleEngineVersion
                }));
            }

            throw new ArgumentException("Not supported database option. Try: MysqlEngineVersion, PostgresEngineVersion, MariaDbEngineVersion, SqlServerEngineVersion and OracleEngineVersion");
        }
예제 #3
0
        public QaStage(Construct scope, string id, QaStageProps props) : base(scope, id, props)
        {
            var mainStack = new Stack(this, "main-stack", new StackProps
            {
                Env = Constants.DefaultEnv
            });

            var credentials = new GitHubSourceCredentials(mainStack, "github-source-credentials", new GitHubSourceCredentialsProps
            {
                AccessToken = SecretValue.SecretsManager("github/oauth/token")
            });

            var vpc = new Vpc(mainStack, "main-vpc", new VpcProps
            {
                Cidr = "10.0.0.0/16"
            });

            //should change this to Aurora Serverless!!!
            //https://dev.to/cjjenkinson/how-to-create-an-aurora-serverless-rds-instance-on-aws-with-cdk-5bb0

            var db = new PostgresStack(this, "postgres-db-stack", new DatabaseInstanceProps
            {
                Vpc    = vpc,
                Engine = DatabaseInstanceEngine.Postgres(new PostgresInstanceEngineProps
                {
                    Version = PostgresEngineVersion.VER_12_3
                }),
                AllocatedStorage         = 5,
                BackupRetention          = Duration.Days(0),
                DeletionProtection       = false,
                InstanceType             = InstanceType.Of(InstanceClass.BURSTABLE2, InstanceSize.MICRO),
                MasterUsername           = "******",
                MultiAz                  = false,
                DatabaseName             = "postgres",
                RemovalPolicy            = RemovalPolicy.DESTROY,
                AllowMajorVersionUpgrade = false
            }, new StackProps
            {
                Env = Constants.DefaultEnv
            });

            var containerEnvVars = new Dictionary <string, string>
            {
                { "DB__ADDRESS", db.Instance.InstanceEndpoint.SocketAddress }
            };
            var containerSecrets = new Dictionary <string, Secret>
            {
                { "DatabaseConnection", Secret.FromSecretsManager(db.Instance.Secret) }
            };

            var accountMetadataTable = new Table(mainStack, "AccountMetadata", new TableProps
            {
                TableName    = "AccountMetadata",
                PartitionKey = new Attribute
                {
                    Name = "UserId",
                    Type = AttributeType.NUMBER
                },
                SortKey = new Attribute
                {
                    Name = "AccountId",
                    Type = AttributeType.NUMBER
                },
                Stream = StreamViewType.NEW_IMAGE
            });

            var ecsCluster = new Cluster(mainStack, "app-cluster", new ClusterProps
            {
                Vpc               = vpc,
                ClusterName       = "app-cluster",
                ContainerInsights = true
            });

            var fargateSslCertArn = SecretValue.SecretsManager("fargateSslCertArn").ToString();
            var albCert           = Certificate.FromCertificateArn(mainStack, "alb-cert", fargateSslCertArn);

            var sandbankBuildInfra = this.CreateApiBuildStack("SandBank", vpc);
            var sandbankApi        = this.CreateApiStack("SandBank",
                                                         ecsCluster,
                                                         vpc,
                                                         sandbankBuildInfra.EcrRepository,
                                                         "sandbank-api",
                                                         props.HostedZoneName,
                                                         props.HostedZoneId,
                                                         albCert,
                                                         containerEnvVars,
                                                         containerSecrets);

            accountMetadataTable.GrantFullAccess(sandbankApi.FargateService.TaskDefinition.TaskRole);

            var cloudfrontCertArn = SecretValue.SecretsManager("cloudfrontcertarn").ToString();
            var cert = Certificate.FromCertificateArn(mainStack, "cloudfront-cert", cloudfrontCertArn);

            var sandbankSpa = new SpaStack(this, "sandbank-spa-stack", new SpaStackProps
            {
                Env               = Constants.DefaultEnv,
                Vpc               = vpc,
                ServiceName       = "sandbank-spa",
                SubDomain         = "sandbank",
                HostedZoneName    = props.HostedZoneName,
                HostedZoneId      = props.HostedZoneId,
                CloudFrontCert    = cert,
                GitHubSourceProps = Constants.GithubRepo,
                BuildSpecFile     = Constants.NpmBuildSpec,
                SpaDirectory      = "App/FrontEnd/sandbank.spa",
                ApiUrl            = $"{sandbankApi.ApiUrl}/api" //maybe should use CfnOutput instead
            });

            //lambda
            //SandBank.Lambda.ConfigAuditTrail::SandBank.Lambda.ConfigAuditTrail.Function::FunctionHandler
        }