import * as aws from "@pulumi/aws" ; import * as k8s from "@pulumi/kubernetes" ; import * as pulumi from "@pulumi/pulumi" ; import * as random from "@pulumi/random" ; import { config } from "./config" ; const projectName = pulumi . getProject ( ) ; const privateSubnetIds = config . privateSubnetIds ; const securityGroupIds = config . securityGroupIds ; const clusterName = config . clusterName ; const password = new random . RandomPassword ( `${ projectName }-password` , { length : 16 , overrideSpecial : "_%@" , special : true , } ) . result ; const dbSubnets = new aws . rds . SubnetGroup ( `${ projectName }-subnets` , { subnetIds : privateSubnetIds } ) ; const db = new aws . rds . Instance ( "postgresdb" , { engine : "postgres" , instanceClass : "db.t2.micro" , allocatedStorage : 20 , dbSubnetGroupName : dbSubnets . id , vpcSecurityGroupIds : securityGroupIds , name : "testdb" , username : "alice" , password : password , skipFinalSnapshot : true , } ) ; const provider = new k8s . Provider ( "provider" , { kubeconfig : config . kubeconfig } ) ; const dbConn = new k8s . core . v1 . Secret ( "postgres-db-conn" , { data : { host : db . address . apply ( addr => Buffer . from ( addr ) . toString ( "base64" ) ) , port : db . port . apply ( port => Buffer . of ( port ) . toString ( "base64" ) ) , username : db . username . apply ( user => Buffer . from ( user ) . toString ( "base64" ) ) , password : password . apply ( pass => Buffer . from ( pass ) . toString ( "base64" ) ) , } , } , { provider : provider } ) ; const cacheSubnets = new aws . elasticache . SubnetGroup ( `${ projectName }-cache-subnets` , { subnetIds : privateSubnetIds , } ) ; const cacheCluster = new aws . elasticache . Cluster ( "cachecluster" , { engine : "redis" , nodeType : "cache.t2.micro" , numCacheNodes : 1 , subnetGroupName : cacheSubnets . id , securityGroupIds : securityGroupIds , } ) ; const cacheConn = new k8s . core . v1 . ConfigMap ( "postgres-db-conn" , { data : { host : cacheCluster . cacheNodes [ 0 ] . address . apply ( addr => Buffer . from ( addr ) . toString ( "base64" ) ) , } , } , { provider : provider } ) ;