Skip to content

Commit

Permalink
setup postgres and sqlserver data variable for connecting to a metada…
Browse files Browse the repository at this point in the history
…ta database
  • Loading branch information
alismx committed Nov 21, 2024
1 parent bc07eba commit 4c3f65c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
6 changes: 6 additions & 0 deletions _check.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
check "database_data" {
assert {
condition = (local.database_data.non_integrated_viewer == "false" && length(local.database_data.metadata_database_type) == 0) || (local.database_data.non_integrated_viewer == "true" && length(local.database_data.metadata_database_type) > 0)
error_message = "When non_integrated_viewer is false, no other database data should be provided. When non_integrated_viewer is true, metadata_database_type, metadata_database_schema, and secrets_manager_* variables should be provided."
}
}
28 changes: 27 additions & 1 deletion _local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ locals {
registry_url = var.disable_ecr == false ? "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com" : "ghcr.io/cdcgov/phdi"
registry_username = data.aws_ecr_authorization_token.this.user_name
registry_password = data.aws_ecr_authorization_token.this.password
database_data = var.postgres_database_data.non_integrated_viewer == "true" ? var.postgres_database_data : var.sqlserver_database_data

service_data = length(var.service_data) > 0 ? var.service_data : {
ecr-viewer = {
short_name = "ecrv",
Expand Down Expand Up @@ -36,7 +38,7 @@ locals {
},
{
name = "NEXT_PUBLIC_NON_INTEGRATED_VIEWER",
value = var.non_integrated_viewer
value = local.database_data.non_integrated_viewer
},
{
name = "SOURCE",
Expand All @@ -53,6 +55,30 @@ locals {
{
name = "NEXT_PUBLIC_BASEPATH",
value = var.ecr_viewer_basepath
},
{
name = "METADATA_DATABASE_TYPE",
value = local.database_data.non_integrated_viewer == "true" ? local.database_data.metadata_database_type : ""
},
{
name = "METADATA_DATABASE_SCHEMA",
value = local.database_data.non_integrated_viewer == "true" ? local.database_data.metadata_database_schema : ""
},
{
name = "DATABASE_URL",
value = local.database_data.metadata_database_type == "postgres" ? local.database_data.secrets_manager_postgres_database_url_arn : ""
},
{
name = "SQL_SERVER_USER",
value = local.database_data.metadata_database_type == "sqlserver" ? local.database_data.secrets_manager_sqlserver_user_arn : ""
},
{
name = "SQL_SERVER_PASSWORD",
value = local.database_data.metadata_database_type == "sqlserver" ? local.database_data.secrets_manager_sqlserver_password_arn : ""
},
{
name = "SQL_SERVER_HOST",
value = local.database_data.metadata_database_type == "sqlserver" ? local.database_data.secrets_manager_sqlserver_host_arn : ""
}
]
},
Expand Down
44 changes: 39 additions & 5 deletions _variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,40 @@ variable "service_data" {
default = {}
}

variable "postgres_database_data" {
type = object({
non_integrated_viewer = string
metadata_database_type = string
metadata_database_schema = string
secrets_manager_postgres_database_url_arn = string
})
default = {
non_integrated_viewer = "false"
metadata_database_type = ""
metadata_database_schema = ""
secrets_manager_postgres_database_url_arn = ""
}
}

variable "sqlserver_database_data" {
type = object({
non_integrated_viewer = string
metadata_database_type = string
metadata_database_schema = string
secrets_manager_sqlserver_user_arn = string
secrets_manager_sqlserver_password_arn = string
secrets_manager_sqlserver_host_arn = string
})
default = {
non_integrated_viewer = "false"
metadata_database_type = ""
metadata_database_schema = ""
secrets_manager_sqlserver_user_arn = ""
secrets_manager_sqlserver_password_arn = ""
secrets_manager_sqlserver_host_arn = ""
}
}

variable "certificate_arn" {
type = string
description = "ARN of the SSL certificate that enables ssl termination on the ALB"
Expand Down Expand Up @@ -148,11 +182,11 @@ variable "tags" {
default = {}
}

variable "non_integrated_viewer" {
type = string
description = "A flag to determine if the viewer is the non-integrated version"
default = "false"
}
# variable "non_integrated_viewer" {
# type = string
# description = "A flag to determine if the viewer is the non-integrated version"
# default = "false"
# }

variable "ecr_viewer_basepath" {
type = string
Expand Down

0 comments on commit 4c3f65c

Please sign in to comment.