Skip to content

Commit

Permalink
VA-411-1-2: Set correct database hostname when running on AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
anttu committed May 17, 2024
1 parent f0bf6a2 commit 4abe314
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const app = new cdk.App()
vpcStack.vpc,
ecsStack.ecsCluster,
dbStack.permitDBAccessSecurityGroup,
encryptionStack.logGroupEncryptionKey
encryptionStack.logGroupEncryptionKey,
databaseHostname: dbStack.clusterWriterEndpointHostname,
)
const bastionStack = new BastionStack(
dev,
Expand Down
4 changes: 4 additions & 0 deletions cdk/lib/va-service-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class VaServiceStack extends cdk.Stack {
cluster: Cluster,
dbAccessSecurityGroup: cdk.aws_ec2.SecurityGroup,
storageEncryptionKey: aws_kms.Key,
databaseHostname: string,
props?: cdk.StackProps
) {
super(scope, id, props)
Expand Down Expand Up @@ -67,6 +68,9 @@ export class VaServiceStack extends cdk.Stack {
image: valtionavustuksetImage,
command: ['with-profile', 'server-dev', 'run', '-m', 'oph.va.hakija.main'],
containerName: 'valtionavustukset',
environment: {
DB_HOSTNAME: databaseHostname,
},
logging: LogDriver.awsLogs({
streamPrefix: 'fargate',
logGroup: logGroup,
Expand Down
9 changes: 8 additions & 1 deletion server/src/clojure/oph/soresu/common/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@
(merge-with merge config secrets-config)
config))

(defn- merge-with-environment [config]
(merge-with merge config
(into {:db (filter val {:server-name (System/getenv "DB_HOSTNAME")
:password (System/getenv "DB_PASSWORD")})
})))

(def config
(when-not *compile-files*
(->> (or (env :config) "config/dev.edn")
(slurp)
(clojure.edn/read-string)
(merge-with-secrets)
(merge-with-defaults))))
(merge-with-defaults)
(merge-with-environment))))

(def environment
(when-not *compile-files*
Expand Down

0 comments on commit 4abe314

Please sign in to comment.