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

[SELC-3811] Feat: added infra files for user-cdc #33

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 48 additions & 0 deletions infra/.container_apps/user-cdc/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions infra/.container_apps/user-cdc/container_app.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
data "azurerm_resource_group" "resource_group_app" {
name = "${local.project}-container-app-rg"
}

data "azurerm_key_vault" "key_vault" {
resource_group_name = var.key_vault.resource_group_name
name = var.key_vault.name
}

data "azurerm_key_vault_secrets" "key_vault_secrets" {
key_vault_id = data.azurerm_key_vault.key_vault.id
}

data "azurerm_key_vault_secret" "keyvault_secret" {
for_each = toset(data.azurerm_key_vault_secrets.key_vault_secrets.names)
name = each.key
key_vault_id = data.azurerm_key_vault.key_vault.id
}

data "azurerm_container_app_environment" "container_app_environment" {
resource_group_name = data.azurerm_resource_group.resource_group_app.name
name = "${local.project}-cae"
}

resource "azapi_resource" "container_app_user_ms" {
type = "Microsoft.App/containerApps@2023-05-01"
name = "${local.project}-${local.app_name}-ca"
location = data.azurerm_resource_group.resource_group_app.location
parent_id = data.azurerm_resource_group.resource_group_app.id

tags = var.tags

identity {
type = "SystemAssigned"
}

body = jsonencode({
properties = {
configuration = {
activeRevisionsMode = "Single"
ingress = {
allowInsecure = true
external = true
traffic = [
{
latestRevision = true
label = "latest"
weight = 100
}
]
targetPort = 8080
}
secrets = local.secrets
}
environmentId = data.azurerm_container_app_environment.container_app_environment.id
template = {
containers = [
{
env = concat(var.app_settings, local.secrets_env)
image = "ghcr.io/pagopa/selfcare-user-cdc:${var.image_tag}"
name = "${local.project}-${local.app_name}"
resources = {
cpu = var.container_app.cpu
memory = var.container_app.memory
}
}
]
scale = {
maxReplicas = var.container_app.max_replicas
minReplicas = var.container_app.min_replicas
rules = var.container_app.scale_rules
}
}
}
})
}

resource "azurerm_key_vault_access_policy" "keyvault_containerapp_access_policy" {
key_vault_id = data.azurerm_key_vault.key_vault.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = azapi_resource.container_app_user_ms.identity[0].principal_id

secret_permissions = [
"Get",
]
}

data "azurerm_resource_group" "rg_vnet" {
name = format("%s-vnet-rg", local.project)
}

data "azurerm_private_dns_zone" "private_azurecontainerapps_io" {
name = local.container_app_environment_dns_zone_name
resource_group_name = data.azurerm_resource_group.rg_vnet.name
}

resource "azurerm_private_dns_a_record" "private_dns_record_a_azurecontainerapps_io" {
name = "${azapi_resource.container_app_user_ms.name}.${trimsuffix(data.azurerm_container_app_environment.container_app_environment.default_domain, ".${local.container_app_environment_dns_zone_name}")}"
zone_name = data.azurerm_private_dns_zone.private_azurecontainerapps_io.name
resource_group_name = data.azurerm_resource_group.rg_vnet.name
ttl = 3600
records = [data.azurerm_container_app_environment.container_app_environment.static_ip_address]
}
1 change: 1 addition & 0 deletions infra/.container_apps/user-cdc/env/dev/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=DEV-SelfCare
4 changes: 4 additions & 0 deletions infra/.container_apps/user-cdc/env/dev/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "terraform-state-rg"
storage_account_name = "tfappdevselfcare"
container_name = "terraform-state"
key = "user-app.tfstate"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions infra/.container_apps/user-cdc/env/dev/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
prefix = "selc"
env_short = "d"

tags = {
CreatedBy = "Terraform"
Environment = "Dev"
Owner = "SelfCare"
Source = "https://github.com/pagopa/selfcare-user"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
}

container_app = {
min_replicas = 1
max_replicas = 1
scale_rules = []
cpu = 0.5
memory = "1Gi"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
}

app_settings = [
{
name = "USER-CDC-MONGODB-WATCH-ENABLED"
value = "false"
}
]

key_vault = {
resource_group_name = "selc-d-sec-rg"
name = "selc-d-kv"
secrets_names = [
"mongodb-connection-string"
]
}
1 change: 1 addition & 0 deletions infra/.container_apps/user-cdc/env/prod/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=PROD-SelfCare
4 changes: 4 additions & 0 deletions infra/.container_apps/user-cdc/env/prod/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "terraform-state-rg"
storage_account_name = "tfappprodselfcare"
container_name = "terraform-state"
key = "user-app.tfstate"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions infra/.container_apps/user-cdc/env/prod/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
prefix = "selc"
env_short = "p"

tags = {
CreatedBy = "Terraform"
Environment = "Prod"
Owner = "SelfCare"
Source = "https://github.com/pagopa/selfcare-user"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
}

container_app = {
min_replicas = 0
max_replicas = 5
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
scale_rules = [
{
custom = {
metadata = {
"desiredReplicas" = "3"
"start" = "0 8 * * MON-FRI"
"end" = "0 19 * * MON-FRI"
"timezone" = "Europe/Rome"
}
type = "cron"
}
name = "cron-scale-rule"
}
]
cpu = 1.25
memory = "2.5Gi"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
}

app_settings = [
{
name = "USER-CDC-MONGODB-WATCH-ENABLED"
value = "false"
}
]

key_vault = {
resource_group_name = "selc-p-sec-rg"
name = "selc-p-kv"
secrets_names = [
"mongodb-connection-string"
]
}
1 change: 1 addition & 0 deletions infra/.container_apps/user-cdc/env/uat/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subscription=UAT-SelfCare
4 changes: 4 additions & 0 deletions infra/.container_apps/user-cdc/env/uat/backend.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource_group_name = "terraform-state-rg"
storage_account_name = "tfappuatselfcare"
container_name = "terraform-state"
key = "user-app.tfstate"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions infra/.container_apps/user-cdc/env/uat/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
prefix = "selc"
env_short = "u"

tags = {
CreatedBy = "Terraform"
Environment = "Uat"
Owner = "SelfCare"
Source = "https://github.com/pagopa/selfcare-user"
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
}

container_app = {
min_replicas = 1
max_replicas = 2
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
scale_rules = []
cpu = 0.5
memory = "1Gi"
flaminiaScarciofolo marked this conversation as resolved.
Show resolved Hide resolved
}

app_settings = [
{
name = "USER-CDC-MONGODB-WATCH-ENABLED"
value = "false"
}
]

key_vault = {
resource_group_name = "selc-u-sec-rg"
name = "selc-u-kv"
secrets_names = [
"mongodb-connection-string"
]
}
19 changes: 19 additions & 0 deletions infra/.container_apps/user-cdc/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
locals {
project = "${var.prefix}-${var.env_short}"
app_name = "user-cdc"

container_app_environment_dns_zone_name = "azurecontainerapps.io"

secrets = [for secret in var.key_vault.secrets_names :
{
identity = "system"
name = "${secret}"
keyVaultUrl = data.azurerm_key_vault_secret.keyvault_secret["${secret}"].id
}]

secrets_env = [for secret in var.key_vault.secrets_names :
{
name = upper(secret)
secretRef = secret
}]
}
24 changes: 24 additions & 0 deletions infra/.container_apps/user-cdc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.77.0"
}

azapi = {
source = "azure/azapi"
version = "~> 1.9.0"
}
}

backend "azurerm" {}
}

provider "azurerm" {
features {}
}

provider "azapi" {}

data "azurerm_client_config" "current" {}
11 changes: 11 additions & 0 deletions infra/.container_apps/user-cdc/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "container_app_resource_group_name" {
value = azapi_resource.container_app_user_cdc.location
}

output "container_app_environment_name" {
value = data.azurerm_container_app_environment.container_app_environment.name
}

output "container_app_name" {
value = azapi_resource.container_app_user_ms.name
}
Loading
Loading