Skip to content

Commit

Permalink
chore: Added container only deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
devops-chris committed Dec 20, 2023
1 parent af0bd2c commit 4376bd0
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 0 deletions.
29 changes: 29 additions & 0 deletions terraform/eus/dev/backend/context.tf
Original file line number Diff line number Diff line change
@@ -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
}
77 changes: 77 additions & 0 deletions terraform/eus/dev/backend/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}

3 changes: 3 additions & 0 deletions terraform/eus/dev/backend/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "azurerm" {
features {}
}
15 changes: 15 additions & 0 deletions terraform/eus/dev/backend/terraform.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
61 changes: 61 additions & 0 deletions terraform/eus/dev/backend/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions terraform/eus/dev/frontend/context.tf
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions terraform/eus/dev/frontend/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
}
3 changes: 3 additions & 0 deletions terraform/eus/dev/frontend/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "azurerm" {
features {}
}
15 changes: 15 additions & 0 deletions terraform/eus/dev/frontend/terraform.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
61 changes: 61 additions & 0 deletions terraform/eus/dev/frontend/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4376bd0

Please sign in to comment.