Skip to content

Commit

Permalink
Merge pull request #133 from hotosm/enhance/container-envvar
Browse files Browse the repository at this point in the history
Improve envvar handling for container instances
  • Loading branch information
eternaltyro authored Jul 19, 2023
2 parents ebd9ae5 + c5e9bef commit 5a4616b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
36 changes: 34 additions & 2 deletions infra/production/container.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
locals {
redis_connection_endpoint = join("", [
"rediss://",
":",
azurerm_redis_cache.raw-data-queue.primary_access_key,
"@",
azurerm_redis_cache.raw-data-queue.hostname,
":",
azurerm_redis_cache.raw-data-queue.ssl_port,
"/0?ssl_cert_reqs=required"
]
)
}

resource "azurerm_container_group" "app" {
name = join("-", [var.project_name, var.deployment_environment])
resource_group_name = azurerm_resource_group.raw-data.name
Expand All @@ -18,7 +32,24 @@ resource "azurerm_container_group" "app" {
protocol = "TCP"
}

environment_variables = var.container_envvar
environment_variables = merge(
var.container_envvar,
{
PGHOST = azurerm_postgresql_flexible_server.raw-data.fqdn
PGPORT = "5432"
PGUSER = lookup(var.admin_usernames, "database")
PGDATABASE = azurerm_postgresql_flexible_server_database.default-db.name
}
)

secure_environment_variables = merge(
var.container_sensitive_envvar,
{
PGPASSWORD = azurerm_key_vault_secret.raw-data-db.value
CELERY_BROKER_URL = local.redis_connection_endpoint
CELERY_RESULT_BACKEND = local.redis_connection_endpoint
}
)
}

container {
Expand All @@ -34,7 +65,8 @@ resource "azurerm_container_group" "app" {
protocol = "TCP"
}

environment_variables = var.container_envvar
environment_variables = var.container_envvar
secure_environment_variables = var.container_sensitive_envvar
}

tags = {
Expand Down
6 changes: 6 additions & 0 deletions infra/production/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ variable "container_envvar" {
description = "Environment Variables to pass to the container"
type = map(string)
}

variable "container_sensitive_envvar" {
description = "Environment Variables to pass to the container"
type = map(string)
}

0 comments on commit 5a4616b

Please sign in to comment.