-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): ARC-1906 fetch env from ssm
fetch env from ssm
- Loading branch information
1 parent
59b6932
commit 03b7d60
Showing
6 changed files
with
152 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
NODE_ENV= | ||
LOG_LEVEL= | ||
DB_HOST= | ||
DB_PORT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_DATABASE= | ||
DB_SCHEMA= | ||
REDIS_HOST= | ||
REDIS_PORT= | ||
REDIS_URL= | ||
REDIS_PASSWORD= | ||
REDIS_DATABASE= | ||
JWT_SECRET= | ||
JWT_ISSUER= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {DataAwsSecurityGroup} from '@cdktf/provider-aws/lib/data-aws-security-group'; | ||
import {DataAwsSsmParameter} from '@cdktf/provider-aws/lib/data-aws-ssm-parameter'; | ||
import {DataAwsSubnets} from '@cdktf/provider-aws/lib/data-aws-subnets'; | ||
import {TerraformStack} from 'cdktf'; | ||
import {readFileSync} from 'fs'; | ||
|
||
export const env = { | ||
AWS_REGION: "", | ||
DB_HOST: "", | ||
DB_PORT: 5432, | ||
DB_USER: "", | ||
DB_PASSWORD: "", | ||
DB_DATABASE: "", | ||
DB_SCHEMA: "", | ||
JWT_SECRET: "", | ||
ACM_CERTIFICATE_ARN: "", | ||
HOSTED_ZONE_ID: "", | ||
DOMAIN_NAME: "", | ||
NAMESPACE: "", | ||
ENV: "", | ||
S3_BUCKET: "" | ||
}; | ||
|
||
interface EnvVar { | ||
[key: string]: string; | ||
} | ||
|
||
export const getSubnetIds = (scope: TerraformStack) => { | ||
const subnets = new DataAwsSubnets(scope, "private_subnets", { | ||
filter: [ | ||
{ | ||
name: "tag:Name", | ||
values: ['demoTagName'], //Replace demoTagName by Name Tag of subnet id | ||
}, | ||
], | ||
}); | ||
return subnets.ids; | ||
} | ||
|
||
export const getSecurityGroup = (scope: TerraformStack) => { | ||
const sgroup = new DataAwsSecurityGroup(scope, "security_group", { | ||
filter: [ | ||
{ | ||
name: "tag:Name", | ||
values: ['demoTagName'], //Replace demoTagName by Name Tag of security group | ||
}, | ||
], | ||
}); | ||
return [sgroup.id]; | ||
}; | ||
|
||
|
||
export const getEnv = (scope: TerraformStack) => { | ||
let envVar: EnvVar = {}; | ||
checkEnv(); | ||
|
||
for (const key in process.env) { | ||
// Check if the property is directly defined on the object (not inherited) | ||
if (process.env.hasOwnProperty(key)) { | ||
//read value from ssm | ||
const ssm = new DataAwsSsmParameter(scope, "db_admin_username_ssm_param", { | ||
name: process.env[key] ?? '', | ||
withDecryption: true | ||
}); | ||
// Copy the value from process.env to envVar | ||
envVar[key] = ssm.value; | ||
} | ||
} | ||
|
||
return envVar; | ||
} | ||
|
||
|
||
export const checkEnv = () => { | ||
let envToCheck = readFileSync('../.env.schema', "utf8").split(/[\n =]/).filter(Boolean); | ||
envToCheck.forEach(key => { | ||
if (!env.hasOwnProperty(key)) { | ||
throw new Error(`env is missing- ${key}`); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters