Skip to content

Commit

Permalink
ER-716: Slot database
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-sidhu-and committed Sep 22, 2023
1 parent a33ff58 commit 8e01e57
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
25 changes: 25 additions & 0 deletions terraform-azure/local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ locals {
"WEBSITES_CONTAINER_START_TIME_LIMIT" = 1800
}

webapp_slot_app_settings = {
"ENVIRONMENT" = var.environment
"DATABASE_URL" = var.webapp_slot_database_url
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
"GOVUK_APP_DOMAIN" = "london.cloudapps.digital" #TODO: Remove this dependency post-migration to Azure
"GOVUK_WEBSITE_ROOT" = "ey-recovery-dev" #TODO: Remove this dependency post-migration to Azure
"BOT_TOKEN" = var.webapp_config_bot_token
"CONTENTFUL_ENVIRONMENT" = var.webapp_config_contentful_environment
"CONTENTFUL_PREVIEW" = var.webapp_config_contentful_preview
"DOMAIN" = var.webapp_config_domain
"EDITOR" = var.webapp_config_editor
"FEEDBACK_URL" = var.webapp_config_feedback_url
"GROVER_NO_SANDBOX" = var.webapp_config_grover_no_sandbox
"HOTJAR_SITE_ID" = var.hotjar_site_id
"NODE_ENV" = var.webapp_config_node_env
"RAILS_ENV" = var.webapp_config_rails_env
"RAILS_LOG_TO_STDOUT" = var.webapp_config_rails_log_to_stdout
"RAILS_MASTER_KEY" = var.webapp_config_rails_master_key
"RAILS_MAX_THREADS" = var.webapp_config_rails_max_threads
"RAILS_SERVE_STATIC_FILES" = var.webapp_config_rails_serve_static_files
"TRACKING_ID" = var.tracking_id
"WEB_CONCURRENCY" = var.webapp_config_web_concurrency
"WEBSITES_CONTAINER_START_TIME_LIMIT" = 1800
}

# Background Worker Application Configuration
app_worker_environment_variables = {
"DATABASE_URL" = var.webapp_database_url
Expand Down
2 changes: 2 additions & 0 deletions terraform-azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module "network" {
module "database" {
source = "./terraform-azure-database"

environment = var.environment
location = var.azure_region
resource_group = azurerm_resource_group.rg.name
resource_name_prefix = var.resource_name_prefix
Expand Down Expand Up @@ -79,6 +80,7 @@ module "webapp" {
webapp_subnet_id = module.network.webapp_subnet_id
webapp_name = var.webapp_name
webapp_app_settings = local.webapp_app_settings
webapp_slot_app_settings = local.webapp_slot_app_settings
webapp_docker_image = var.webapp_docker_image
webapp_docker_image_tag = var.webapp_docker_image_tag
webapp_docker_registry_url = var.webapp_docker_registry_url
Expand Down
10 changes: 10 additions & 0 deletions terraform-azure/terraform-azure-database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ resource "azurerm_postgresql_flexible_server_database" "psqldb" {
server_id = azurerm_postgresql_flexible_server.psqlfs.id
collation = "en_US.utf8"
charset = "utf8"
}

resource "azurerm_postgresql_flexible_server_database" "psqldb_slot" {
# Secondary database only deployed for Green Web App slot on Production subscription
count = var.environment == "production" ? 1 : 0

name = "${var.resource_name_prefix}-${random_pet.name.id}-psqldb-slot"
server_id = azurerm_postgresql_flexible_server.psqlfs.id
collation = "en_US.utf8"
charset = "utf8"
}
5 changes: 5 additions & 0 deletions terraform-azure/terraform-azure-database/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ variable "psqlfs_subnet_id" {
type = string
}

variable "environment" {
description = "Environment to deploy resources"
type = string
}

variable "psqlfs_dns_zone_id" {
description = "ID of the Private DNS Zone for the Database Server"
type = string
Expand Down
5 changes: 5 additions & 0 deletions terraform-azure/terraform-azure-web/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ variable "webapp_app_settings" {
type = map(string)
}

variable "webapp_slot_app_settings" {
description = "App Settings are exposed as environment variables"
type = map(string)
}

variable "webapp_docker_registry_url" {
description = "URL to the Docker Registry"
type = string
Expand Down
2 changes: 1 addition & 1 deletion terraform-azure/terraform-azure-web/webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ resource "azurerm_linux_web_app_slot" "webapp_slot" {
app_service_id = azurerm_linux_web_app.webapp.id
https_only = true
virtual_network_subnet_id = var.webapp_subnet_id
app_settings = var.webapp_app_settings
app_settings = var.webapp_slot_app_settings

site_config {
app_command_line = var.webapp_startup_command
Expand Down
6 changes: 6 additions & 0 deletions terraform-azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ variable "webapp_database_url" {
sensitive = true
}

variable "webapp_slot_database_url" {
description = "URL to the slot Database"
type = string
sensitive = true
}

variable "webapp_docker_registry_url" {
description = "URL to the Docker Registry"
type = string
Expand Down

0 comments on commit 8e01e57

Please sign in to comment.