Skip to content

Commit 992b1a1

Browse files
authored
Use DB_SECRET env var and deploy env IDs (#16)
1 parent 9d79712 commit 992b1a1

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ name: 'Deploy'
88
# PREREQUISITES:
99
# 1. Deploy infrastructure first to create ECR repositories:
1010
# cd infra/cdktf
11-
# pnpm deploy:aws-main # for main branch
12-
# pnpm deploy:aws-demo # for demo branch
11+
# pnpm deploy:flexion-sandbox-main # for main branch
12+
# pnpm deploy:flexion-sandbox-demo # for demo branch
1313
#
1414
# 2. Configure GitHub secrets:
1515
# - AWS_ACCOUNT_ID

apps/sandbox/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import { createCustomServer } from './server.js';
66
const port = process.env.PORT || 4321;
77

88
const getAppRunnerSecrets = async () => {
9-
const dbSecretArn = process.env.DB_SECRET_ARN;
9+
const dbSecretStr = process.env.DB_SECRET;
1010
const dbHost = process.env.DB_HOST;
1111
const dbPort = process.env.DB_PORT;
1212
const dbName = process.env.DB_NAME;
1313

14-
if (!dbSecretArn || !dbHost || !dbPort || !dbName) {
14+
if (!dbSecretStr || !dbHost || !dbPort || !dbName) {
1515
console.error(
16-
'Missing required environment variables: DB_SECRET_ARN, DB_HOST, DB_PORT, DB_NAME'
16+
'Missing required environment variables: DB_SECRET, DB_HOST, DB_PORT, DB_NAME'
1717
);
1818
return;
1919
}
2020

21-
const vault = getAWSSecretsManagerVault();
22-
const dbSecretString = await vault.getSecret(dbSecretArn);
23-
if (dbSecretString === undefined) {
24-
console.error('Error getting secret:', dbSecretArn);
21+
const dbSecret = JSON.parse(dbSecretStr);
22+
if (!dbSecret.username || !dbSecret.password) {
23+
console.error(
24+
'`DB_SECRET` environment variable is missing username or password'
25+
);
2526
return;
2627
}
2728

28-
const dbSecret = JSON.parse(dbSecretString);
2929
return {
3030
dbUri: `postgresql://${dbSecret.username}:${dbSecret.password}@${dbHost}:${dbPort}/${dbName}`,
3131
};

infra/cdktf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export AWS_DEFAULT_REGION=us-east-1
5959

6060
```bash
6161
# Deploy infrastructure for demo environment
62-
pnpm deploy:aws-demo
62+
pnpm deploy:flexion-sandbox-demo
6363

6464
# Deploy infrastructure for main/production environment
65-
pnpm deploy:aws-main
65+
pnpm deploy:flexion-sandbox-main
6666
```
6767

6868
This creates:

infra/cdktf/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"clean:gen": "rimraf .gen",
2222
"deploy:cloud-gov-main": "DEPLOY_ENV=cloud-gov-main cdktf deploy",
2323
"deploy:cloud-gov-demo": "DEPLOY_ENV=cloud-gov-demo cdktf deploy",
24-
"deploy:aws-main": "DEPLOY_ENV=aws-main cdktf deploy",
25-
"deploy:aws-demo": "DEPLOY_ENV=aws-demo cdktf deploy",
24+
"deploy:flexion-sandbox-main": "DEPLOY_ENV=aws-main cdktf deploy",
25+
"deploy:flexion-sandbox-demo": "DEPLOY_ENV=aws-demo cdktf deploy",
2626
"deploy:main:local": "DEPLOY_GIT_REF=main DEPLOY_ENV=cloud-gov-main cdktf deploy",
2727
"dev": "tsc -w",
2828
"test": "echo 'no tests'"

infra/cdktf/src/lib/aws/sandbox-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class SandboxStack extends Construct {
340340
DB_NAME: 'postgres',
341341
},
342342
runtimeEnvironmentSecrets: {
343-
DB_SECRET_ARN: dbSecret.arn,
343+
DB_SECRET: dbSecret.arn,
344344
},
345345
},
346346
},

0 commit comments

Comments
 (0)