Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve envvar handling for container instances #133

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

Loading