From 5e01afdf1459a68172a0b3d1772e8bcca06e1d6a Mon Sep 17 00:00:00 2001 From: Hadwa Gaber Date: Tue, 6 Sep 2022 18:51:25 -0700 Subject: [PATCH 1/5] test keepers property --- .../projects/python-mongo/.repo/terraform/infra/main.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf index e52cf248ba6..9f294e8f072 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf @@ -25,6 +25,12 @@ resource "random_string" "resource_token" { lower = true numeric = false special = false + + keepers = { + env = var.environment_name, + location = azurerm_resource_group.rg.location, + subid = data.azurerm_client_config.current.subscription_id + } } # ------------------------------------------------------------------------------------------------------ From b5198f837dd90322f641f1b3023f44b2c5e47ffc Mon Sep 17 00:00:00 2001 From: Hadwa Gaber Date: Tue, 6 Sep 2022 22:38:49 -0700 Subject: [PATCH 2/5] update resource_token Co-authored-by: Hattan Shobokshi --- .../.repo/terraform/infra/apps.tf | 6 ++--- .../.repo/terraform/infra/cosmos.tf | 2 +- .../.repo/terraform/infra/keyvault.tf | 2 +- .../.repo/terraform/infra/loganalytics.tf | 2 +- .../.repo/terraform/infra/main.tf | 22 ++++++++----------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf index 362b9998b93..763f5ebc99e 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf @@ -2,7 +2,7 @@ # Deploy app service plan # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "plan_name" { - name = random_string.resource_token.result + name = local.resource_token resource_type = "azurerm_app_service_plan" random_length = 0 clean_input = true @@ -22,7 +22,7 @@ resource "azurerm_service_plan" "plan" { # Deploy app service web app # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "web_name" { - name = "web-${random_string.resource_token.result}" + name = "web-${local.resource_token}" resource_type = "azurerm_app_service" random_length = 0 clean_input = true @@ -69,7 +69,7 @@ resource "azurerm_linux_web_app" "web" { # Deploy app service api # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "appi_name" { - name = "api-${random_string.resource_token.result}" + name = "api-${local.resource_token}" resource_type = "azurerm_app_service" random_length = 0 clean_input = true diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/cosmos.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/cosmos.tf index d94f6f48f25..618a080e9c4 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/cosmos.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/cosmos.tf @@ -2,7 +2,7 @@ # Deploy cosmos db account # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "db_acc_name" { - name = random_string.resource_token.result + name = local.resource_token resource_type = "azurerm_cosmosdb_account" random_length = 0 clean_input = true diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/keyvault.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/keyvault.tf index 1cea32beedc..5298b48438e 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/keyvault.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/keyvault.tf @@ -2,7 +2,7 @@ # DEPLOY AZURE KEYVAULT # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "kv_name" { - name = random_string.resource_token.result + name = local.resource_token resource_type = "azurerm_key_vault" random_length = 0 clean_input = true diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/loganalytics.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/loganalytics.tf index dedb1f01410..6e626fdcefd 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/loganalytics.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/loganalytics.tf @@ -2,7 +2,7 @@ # Deploy log analytics workspace # ------------------------------------------------------------------------------------------------------ resource "azurecaf_name" "workspace_name" { - name = random_string.resource_token.result + name = local.resource_token resource_type = "azurerm_log_analytics_workspace" random_length = 0 clean_input = true diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf index 9f294e8f072..a2943ffffb2 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf @@ -1,5 +1,7 @@ locals { tags = { azd-env-name : var.environment_name } + sha = base64encode(sha256("${var.environment_name}${var.location}${data.azurerm_client_config.current.subscription_id}")) + resource_token = substr(replace(lower(local.sha),"[^A-Za-z0-9_]",""), 0, 13) api_command_line = "gunicorn --workers 4 --threads 2 --timeout 60 --access-logfile \"-\" --error-logfile \"-\" --bind=0.0.0.0:8000 -k uvicorn.workers.UvicornWorker todo.app:app" } # ------------------------------------------------------------------------------------------------------ @@ -19,19 +21,13 @@ resource "azurerm_resource_group" "rg" { tags = local.tags } -resource "random_string" "resource_token" { - length = 10 - upper = false - lower = true - numeric = false - special = false - keepers = { - env = var.environment_name, - location = azurerm_resource_group.rg.location, - subid = data.azurerm_client_config.current.subscription_id - } -} +# keepers = { +# env = var.environment_name, +# location = azurerm_resource_group.rg.location, +# subid = data.azurerm_client_config.current.subscription_id +# } +# } # ------------------------------------------------------------------------------------------------------ # Deploy application insights @@ -43,5 +39,5 @@ module "applicationinsights" { environment_name = var.environment_name workspace_id = azurerm_log_analytics_workspace.workspace.id tags = azurerm_resource_group.rg.tags - resource_token = random_string.resource_token.result + resource_token = local.resource_token } From 8cb7e43c2f8975ef7068a8a3a9a41ab0e6886a5d Mon Sep 17 00:00:00 2001 From: Hadwa Gaber Date: Tue, 6 Sep 2022 22:40:28 -0700 Subject: [PATCH 3/5] fmt main.tf --- .../todo/projects/python-mongo/.repo/terraform/infra/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf index a2943ffffb2..6a588af4822 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf @@ -1,7 +1,7 @@ locals { tags = { azd-env-name : var.environment_name } - sha = base64encode(sha256("${var.environment_name}${var.location}${data.azurerm_client_config.current.subscription_id}")) - resource_token = substr(replace(lower(local.sha),"[^A-Za-z0-9_]",""), 0, 13) + sha = base64encode(sha256("${var.environment_name}${var.location}${data.azurerm_client_config.current.subscription_id}")) + resource_token = substr(replace(lower(local.sha), "[^A-Za-z0-9_]", ""), 0, 13) api_command_line = "gunicorn --workers 4 --threads 2 --timeout 60 --access-logfile \"-\" --error-logfile \"-\" --bind=0.0.0.0:8000 -k uvicorn.workers.UvicornWorker todo.app:app" } # ------------------------------------------------------------------------------------------------------ From f1bc446c1b8f370bcb878b826f1cdacb7163b813 Mon Sep 17 00:00:00 2001 From: Hadwa Gaber Date: Tue, 6 Sep 2022 22:41:36 -0700 Subject: [PATCH 4/5] . --- .../projects/python-mongo/.repo/terraform/infra/main.tf | 8 -------- 1 file changed, 8 deletions(-) diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf index 6a588af4822..d9c3a0c735c 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf @@ -21,14 +21,6 @@ resource "azurerm_resource_group" "rg" { tags = local.tags } - -# keepers = { -# env = var.environment_name, -# location = azurerm_resource_group.rg.location, -# subid = data.azurerm_client_config.current.subscription_id -# } -# } - # ------------------------------------------------------------------------------------------------------ # Deploy application insights # ------------------------------------------------------------------------------------------------------ From 152d7050a62b8fb515c151d363e9280594da5f60 Mon Sep 17 00:00:00 2001 From: Hadwa Gaber Date: Wed, 7 Sep 2022 14:28:49 -0700 Subject: [PATCH 5/5] update terraform provider version --- .../projects/python-mongo/.repo/terraform/infra/provider.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/todo/projects/python-mongo/.repo/terraform/infra/provider.tf b/templates/todo/projects/python-mongo/.repo/terraform/infra/provider.tf index cd31bba2c39..b155125c556 100644 --- a/templates/todo/projects/python-mongo/.repo/terraform/infra/provider.tf +++ b/templates/todo/projects/python-mongo/.repo/terraform/infra/provider.tf @@ -2,7 +2,7 @@ # Configure the Azure Provider terraform { - required_version = "= v1.1.7" + required_version = "~> v1.1.7" required_providers { azurerm = { version = "~>3.18.0"