From 4376bd0a762ae3518ae1fc4947450fc40225772d Mon Sep 17 00:00:00 2001 From: Christopher Lindsay Date: Wed, 20 Dec 2023 12:40:23 -0500 Subject: [PATCH] chore: Added container only deployments --- terraform/eus/dev/backend/context.tf | 29 ++++++++++ terraform/eus/dev/backend/main.tf | 77 +++++++++++++++++++++++++ terraform/eus/dev/backend/providers.tf | 3 + terraform/eus/dev/backend/terraform.tf | 15 +++++ terraform/eus/dev/backend/variables.tf | 61 ++++++++++++++++++++ terraform/eus/dev/frontend/context.tf | 9 +++ terraform/eus/dev/frontend/main.tf | 31 ++++++++++ terraform/eus/dev/frontend/providers.tf | 3 + terraform/eus/dev/frontend/terraform.tf | 15 +++++ terraform/eus/dev/frontend/variables.tf | 61 ++++++++++++++++++++ 10 files changed, 304 insertions(+) create mode 100644 terraform/eus/dev/backend/context.tf create mode 100644 terraform/eus/dev/backend/main.tf create mode 100644 terraform/eus/dev/backend/providers.tf create mode 100644 terraform/eus/dev/backend/terraform.tf create mode 100644 terraform/eus/dev/backend/variables.tf create mode 100644 terraform/eus/dev/frontend/context.tf create mode 100644 terraform/eus/dev/frontend/main.tf create mode 100644 terraform/eus/dev/frontend/providers.tf create mode 100644 terraform/eus/dev/frontend/terraform.tf create mode 100644 terraform/eus/dev/frontend/variables.tf diff --git a/terraform/eus/dev/backend/context.tf b/terraform/eus/dev/backend/context.tf new file mode 100644 index 0000000000..dceca45654 --- /dev/null +++ b/terraform/eus/dev/backend/context.tf @@ -0,0 +1,29 @@ +module "ctx" { + source = "../../../global/context" + environment = var.environment +} + +data "azurerm_container_app_environment" "aca_env" { + name = module.ctx.labels.core.resourceNames["azurerm_container_app_environment"] + resource_group_name = module.ctx.resource_group_name +} + +data "azurerm_postgresql_flexible_server" "ops_dbs" { + name = module.ctx.labels.db.resourceNames["azurerm_postgresql_flexible_server"] + resource_group_name = module.ctx.resource_group_name +} + +data "azurerm_key_vault" "vault" { + name = module.ctx.labels.core.resourceNames["azurerm_key_vault"] + resource_group_name = module.ctx.resource_group_name +} + +data "azurerm_key_vault_secret" "ops-pw" { + name = "ops-role-password" + key_vault_id = data.azurerm_key_vault.vault.id +} + +data "azurerm_key_vault_secret" "ops-jwt-private-key" { + name = "ops-jwt-private-key" + key_vault_id = data.azurerm_key_vault.vault.id +} \ No newline at end of file diff --git a/terraform/eus/dev/backend/main.tf b/terraform/eus/dev/backend/main.tf new file mode 100644 index 0000000000..f8de0ff757 --- /dev/null +++ b/terraform/eus/dev/backend/main.tf @@ -0,0 +1,77 @@ + + +resource "azurerm_container_app" "backend" { + name = module.ctx.labels.be.resourceNames["azurerm_container_app"] + container_app_environment_id = data.azurerm_container_app_environment.aca_env.id + resource_group_name = module.ctx.resource_group_name + revision_mode = "Multiple" + + template { + revision_suffix = substr(var.container_tag, 0, 8) + min_replicas = 1 + container { + name = var.container_name + image = "${var.container_image}:${var.container_tag}" + cpu = var.cpu + memory = var.memory + env { + name = "OPS_CONFIG" + value = "environment/azure/dev.py" + } + env { + name = "PGUSER" + value = "ops" + } + env { + name = "PGPASSWORD" + secret_name = "pgpassword" + } + env { + name = "PGHOST" + value = data.azurerm_postgresql_flexible_server.ops_dbs.fqdn + } + env { + name = "PGPORT" + value = 5432 + } + env { + name = "PGDATABASE" + value = "postgres" + } + env { + name = "JWT_PRIVATE_KEY" + secret_name = "jwt-private-key" + } + env { + name = "OPS_FRONTEND_URL" + value = "https://${module.ctx.labels.fe.resourceNames["azurerm_container_app"]}.${data.azurerm_container_app_environment.aca_env.default_domain}" + } + } + } + + ingress { + external_enabled = true + target_port = var.port + traffic_weight { + percentage = 100 + latest_revision = true + } + } + secret { + name = "pgpassword" + value = data.azurerm_key_vault_secret.ops-pw.value + } + secret { + name = "jwt-private-key" + value = data.azurerm_key_vault_secret.ops-jwt-private-key.value + } +} + +output "fe_domain" { + value = "https://${module.ctx.labels.fe.resourceNames["azurerm_container_app"]}.${data.azurerm_container_app_environment.aca_env.default_domain}" +} + +output "be_domain" { + value = "https://${module.ctx.labels.be.resourceNames["azurerm_container_app"]}.${data.azurerm_container_app_environment.aca_env.default_domain}" +} + diff --git a/terraform/eus/dev/backend/providers.tf b/terraform/eus/dev/backend/providers.tf new file mode 100644 index 0000000000..ab91b24812 --- /dev/null +++ b/terraform/eus/dev/backend/providers.tf @@ -0,0 +1,3 @@ +provider "azurerm" { + features {} +} diff --git a/terraform/eus/dev/backend/terraform.tf b/terraform/eus/dev/backend/terraform.tf new file mode 100644 index 0000000000..b69390f6e4 --- /dev/null +++ b/terraform/eus/dev/backend/terraform.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "3.79.0" + } + } + + backend "azurerm" { + resource_group_name = "opre-ops-dev-eus-tf-rg" + storage_account_name = "opreopsdeveustfst" + container_name = "opre-ops-dev-eus-tf-sc" + key = "ops-be-deployment.tfstate" + } +} diff --git a/terraform/eus/dev/backend/variables.tf b/terraform/eus/dev/backend/variables.tf new file mode 100644 index 0000000000..78345f89d3 --- /dev/null +++ b/terraform/eus/dev/backend/variables.tf @@ -0,0 +1,61 @@ +variable "owner" { + description = "Name of the owner of the workload and resources" + type = string + default = "OPRE" +} + +variable "project" { + description = "Project name that resources fall under" + type = string + default = "ops" +} + +variable "environment" { + description = "Environment tag for the resources" + type = string + default = "dev" +} + +variable "location" { + description = "Azure location for the resources" + type = string + default = "eastus" +} + +### Container Details + +variable "container_name" { + description = "Name of the container" + type = string + default = "ops-backend" +} + +variable "container_image" { + description = "Container image" + type = string + default = "ghcr.io/hhs/opre-ops/ops-backend" +} + +variable "container_tag" { + description = "Container image tag" + type = string + default = "764bc3296bcdc1abeac2b230088857a54bf4c84e" +} + +variable "cpu" { + description = "CPU requirements. This has specific ration with memory... (beta)" + type = number + default = 0.25 +} + +variable "memory" { + description = "Memory requirements. This has specific ration with cpu... (beta)" + type = string + default = "0.5Gi" +} + +variable "port" { + description = "Port for application" + type = number + default = 8080 +} \ No newline at end of file diff --git a/terraform/eus/dev/frontend/context.tf b/terraform/eus/dev/frontend/context.tf new file mode 100644 index 0000000000..ad9a89e2a8 --- /dev/null +++ b/terraform/eus/dev/frontend/context.tf @@ -0,0 +1,9 @@ +module "ctx" { + source = "../../../global/context" + environment = var.environment +} + +data "azurerm_container_app_environment" "aca_env" { + name = module.ctx.labels.core.resourceNames["azurerm_container_app_environment"] + resource_group_name = module.ctx.resource_group_name +} diff --git a/terraform/eus/dev/frontend/main.tf b/terraform/eus/dev/frontend/main.tf new file mode 100644 index 0000000000..c0b00299bd --- /dev/null +++ b/terraform/eus/dev/frontend/main.tf @@ -0,0 +1,31 @@ +resource "azurerm_container_app" "frontend" { + name = module.ctx.labels.fe.resourceNames["azurerm_container_app"] + container_app_environment_id = data.azurerm_container_app_environment.aca_env.id + resource_group_name = module.ctx.resource_group_name + revision_mode = "Multiple" + + template { + revision_suffix = substr(var.container_tag, 0, 8) + min_replicas = 1 + container { + name = var.container_name + image = "${var.container_image}:${var.container_tag}" + cpu = var.cpu + memory = var.memory + + env { + name = "REACT_APP_BACKEND_DOMAIN" + value = "https://${module.ctx.labels.be.resourceNames["azurerm_container_app"]}.${data.azurerm_container_app_environment.aca_env.default_domain}" + } + } + } + + ingress { + external_enabled = true + target_port = var.port + traffic_weight { + percentage = 100 + latest_revision = true + } + } +} diff --git a/terraform/eus/dev/frontend/providers.tf b/terraform/eus/dev/frontend/providers.tf new file mode 100644 index 0000000000..ab91b24812 --- /dev/null +++ b/terraform/eus/dev/frontend/providers.tf @@ -0,0 +1,3 @@ +provider "azurerm" { + features {} +} diff --git a/terraform/eus/dev/frontend/terraform.tf b/terraform/eus/dev/frontend/terraform.tf new file mode 100644 index 0000000000..b6b7f45e2b --- /dev/null +++ b/terraform/eus/dev/frontend/terraform.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "3.79.0" + } + } + + backend "azurerm" { + resource_group_name = "opre-ops-dev-eus-tf-rg" + storage_account_name = "opreopsdeveustfst" + container_name = "opre-ops-dev-eus-tf-sc" + key = "ops-fe-deployment.tfstate" + } +} diff --git a/terraform/eus/dev/frontend/variables.tf b/terraform/eus/dev/frontend/variables.tf new file mode 100644 index 0000000000..66fb24f540 --- /dev/null +++ b/terraform/eus/dev/frontend/variables.tf @@ -0,0 +1,61 @@ +variable "owner" { + description = "Name of the owner of the workload and resources" + type = string + default = "OPRE" +} + +variable "project" { + description = "Project name that resources fall under" + type = string + default = "ops" +} + +variable "environment" { + description = "Environment tag for the resources" + type = string + default = "dev" +} + +variable "location" { + description = "Azure location for the resources" + type = string + default = "eastus" +} + +### Container Details + +variable "container_name" { + description = "Name of the container" + type = string + default = "ops-frontend" +} + +variable "container_image" { + description = "Container image" + type = string + default = "ghcr.io/hhs/opre-ops/ops-frontend" +} + +variable "container_tag" { + description = "Container image tag" + type = string + default = "a6c6948ff0cc6ac68d9aba32059b14e61e924640" +} + +variable "cpu" { + description = "CPU requirements. This has specific ration with memory... (beta)" + type = number + default = 0.25 +} + +variable "memory" { + description = "Memory requirements. This has specific ration with cpu... (beta)" + type = string + default = "0.5Gi" +} + +variable "port" { + description = "Port for application" + type = number + default = 80 +} \ No newline at end of file