During the build process of our application Marketplace, we needed a MySQL database to run system tests against. So, we’re using Bisque AWS to create that RDS instance. We’ve defined a Template to create that RDS instance. We’re also peering the VPC that the RDS instance is in back to our build server and our development workstations.
This template is deployed during our build process right before our system test are run. It is then deleted using Bisque TFS vNext Build Task “AwsCloudFormationDeleteStack”.
The code is pretty small and is as follows:
using System.Net; using YadaYada.Bisque.Aws.CloudFormation.Resource.EC2.Instancing.Metadata.Authentication; using YadaYada.Bisque.Aws.CloudFormation.Resource.EC2.Networking; using YadaYada.Bisque.Aws.CloudFormation.Resource.RDS; using YadaYada.Bisque.Aws.CloudFormation.Templates; using YadaYada.Bisque.Aws.CloudFormation.Templates.Functions; using YadaYada.Bisque.Aws.CloudFormation.Templates.Parameters; namespace Marketplace.Deploy { public class MySqlForBuildTesting : Template { public MySqlForBuildTesting() : base("MySqlForBuildTesting", "Creates resources for build testing") { var vpc = new Vpc(IPNetwork.Parse("172.0.0.0/16"), true); this.Add(vpc); var developmentVpcId = this.Parameters.Add(new Parameter("DevelopmentVpcId", ParameterType.AwsEc2VpcId, "Id of the development Vpc")); var developmentBuildServerAndWorkstationSubnetsCidrBlock = this.Parameters.Add(new Parameter("DevelopmentAndBuildServerCidrBlock", ParameterType.String, "CidrBlock of the build server and workstation subnets")); var developerWorkstationSubnetRouteTableId = this.Parameters.Add(new Parameter("DevelopmentAndBuildServerRouteTableId", ParameterType.String, "Id of Route Table for the developer workstation and build server subnet. Physical Id, not the logical id.")); var peeringConnection = new VpcPeeringConnection(vpc, developmentVpcId); this.Add(peeringConnection); var dbParameterGroup = new DbParameterGroup(); dbParameterGroup.Description = "Allows Enity Framework To Create Database In MySql"; dbParameterGroup.Family = DbParameterFamily.MySql56; dbParameterGroup.DbParameters.Add("log_bin_trust_function_creators", "1"); this.Add(dbParameterGroup); var db = vpc.AddDbSubnetGroup().AddDbInstance(); db.AllocatedStorage = 5.ToString(); db.DbParameterGroupName = dbParameterGroup; db.Engine = EngineType.MySql; db.Port = Ports.MySql; db.Connect(developmentBuildServerAndWorkstationSubnetsCidrBlock, developerWorkstationSubnetRouteTableId, peeringConnection); this.Outputs.Add(new Output("MySqlForBuildTestEndPoint", new FnGetAtt(db, FnGetAttAttribute.AwsRdsDbInstanceEndpointAddress))); this.Outputs.Add(new Output("MySqlForBuildTestMasterUserName", new Reference($"{db.LogicalId}MasterUserName"))); this.Outputs.Add(new Output("MySqlForBuildTestMasterPassword", new Reference($"{db.LogicalId}MasterPassword"))); db.Metadata.Authentication.AddCredential(new S3AccessCreds("yadayadacustomer")); db.Metadata.Authentication.AddCredential(new S3AccessCreds("yadayada")); } } }