Skip to content

Commit

Permalink
[wip]: Deploy rewritten highscore api as container app
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Fosli committed Jul 3, 2023
1 parent 5c3ef3a commit 08e8c90
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
65 changes: 64 additions & 1 deletion terraform/api.tf
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# TODO: Deploy new highscore API as az container app
resource "azurerm_container_app_environment" "containerAppEnv" {
name = "cae-snake-${var.ENVIRONMENT}"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
log_analytics_workspace_id = azurerm_log_analytics_workspace.logWorkspace.id
}

resource "azurerm_container_app" "highscoreApi" {
name = "ca-snakehighscoreapi-${var.ENVIRONMENT}"
container_app_environment_id = azurerm_container_app_environment.containerAppEnv.id
resource_group_name = azurerm_container_app_environment.containerAppEnv.resource_group_name
revision_mode = "Single"

template {
container {
name = "highscore-api"
image = "ghcr.io/christianfosli/snake/highscore-api:latest" # <-- tag will be overridden by ci/cd
cpu = 0.25
memory = "0.5Gi"

env {
name = "DB_CONNSTR"
secret_name = "db-connstr"
}

liveness_probe {
transport = "http"
path = "/livez"
port = 3000
}

readiness_probe {
transport = "http"
path = "/readyz"
port = 3000
}
}
}

ingress {
# custom_domain {
# # Manual Step: Currently (July 2023), azurerm_container_app_environment_certificate doesn't support
# # managed TLS certificates.
# # Therefore during initial deploy this block must be commented out, and added through the Azure Portal
# # Then the below certificate_id must be updated as required.
# name = "${azurerm_dns_cname_record.highScoreApi.name}.${azurerm_dns_cname_record.highScoreApi.zone_name}"
# certificate_id = "??"
# certificate_binding_type = "SniEnabled"
# }
target_port = 3000

traffic_weight {
percentage = 100
}
}

secret {
name = "db-connstr"
value = azurerm_key_vault_secret.mongoConnectionString.value
}


tags = local.common_tags
}
19 changes: 8 additions & 11 deletions terraform/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ resource "azurerm_dns_cname_record" "app" {
tags = local.common_tags
}

# todo: add again after container app up
# resource "azurerm_dns_cname_record" "highScoreApi" {
# name = var.ENVIRONMENT == "prod" ? "highscores" : "highscores-${var.ENVIRONMENT}"
# zone_name = "playsnake.no" # hardcoded because sometimes different env
# resource_group_name = "rg-snake-prod" # hardcoded because sometimes different env
# ttl = 300
# # record = azurerm_linux_function_app.highScoreApi.default_hostname
# # default_hostname incorrenctly returns empty string - see upstream bug report https://github.com/hashicorp/terraform-provider-azurerm/issues/16263
# record = "${azurerm_linux_function_app.highScoreApi.name}.azurewebsites.net"
# tags = local.common_tags
# }
resource "azurerm_dns_cname_record" "highScoreApi" {
name = var.ENVIRONMENT == "prod" ? "highscores" : "highscores-${var.ENVIRONMENT}"
zone_name = "playsnake.no" # hardcoded because sometimes different env
resource_group_name = "rg-snake-prod" # hardcoded because sometimes different env
ttl = 300
record = azurerm_container_app.highscoreApi.latest_revision_fqdn
tags = local.common_tags
}

0 comments on commit 08e8c90

Please sign in to comment.