Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
528f9ad
adding in cse fork changes
hattan Aug 3, 2022
60a463b
adding vscode debugging support
hattan Aug 3, 2022
68e6947
adding .tmp folder to gitignore
hattan Aug 3, 2022
362572c
refator to support bicep in folder structure
hattan Aug 3, 2022
3d18273
update repoman to add new rule to copy specific files, update repoman…
HadwaAbdelhalem Aug 4, 2022
f2152c3
add aca/bicep layer in common infra folders
HadwaAbdelhalem Aug 4, 2022
bb37d8a
update to set -t to the project template
HadwaAbdelhalem Aug 4, 2022
6e115b0
update node-js-mongo project
HadwaAbdelhalem Aug 4, 2022
222007b
update repo.yaml files to reference common/infra/bicep
HadwaAbdelhalem Aug 4, 2022
de0f308
Removing extra lines in python-mongo azure*.yaml files.
hattan Aug 4, 2022
c1b9754
Code Cleanup
HadwaAbdelhalem Aug 5, 2022
d3fb35d
redirect configurations to upstream azure/azure-dev
HadwaAbdelhalem Aug 5, 2022
ec30798
address bicep lint failures
HadwaAbdelhalem Aug 5, 2022
dd99040
Update todo-project template.
HadwaAbdelhalem Aug 22, 2022
f38bf69
Merge remote-tracking branch 'upstream/main' into cse/restructure-inf…
HadwaAbdelhalem Aug 22, 2022
861e34a
fix asset rules for path rewitre
HadwaAbdelhalem Aug 22, 2022
9e1fa5a
Add rewrite path rules tmp fix
HadwaAbdelhalem Aug 23, 2022
c0657b3
add python-mongo, application insights terraform modules
HadwaAbdelhalem Aug 23, 2022
616f1a0
add repo.yml, azure.yml files
HadwaAbdelhalem Aug 23, 2022
6e0cb75
fix asset rules
HadwaAbdelhalem Aug 24, 2022
f7d4c4b
ignore terraform files
HadwaAbdelhalem Aug 24, 2022
1e4730c
merge upstream main
HadwaAbdelhalem Aug 26, 2022
5d139d8
update remote main and staging urls
HadwaAbdelhalem Aug 26, 2022
025d3d8
fix typo, update cspell
HadwaAbdelhalem Aug 26, 2022
3c7e7b7
addreses PR feedback
HadwaAbdelhalem Aug 27, 2022
bd7de3f
update template name
HadwaAbdelhalem Aug 27, 2022
01188dd
split resources in multiple files.
HadwaAbdelhalem Aug 27, 2022
17dc803
resolve cspell
HadwaAbdelhalem Aug 29, 2022
65bee8b
address review comments
HadwaAbdelhalem Aug 29, 2022
44f3620
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem Sep 1, 2022
b9691cd
add tfvars.json
HadwaAbdelhalem Sep 1, 2022
18635d9
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem Sep 1, 2022
3cccab7
add rewrite path rules
HadwaAbdelhalem Sep 1, 2022
bd804fb
rename to environment_name
HadwaAbdelhalem Sep 2, 2022
a71cbbf
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem Sep 2, 2022
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ obj/
bin/
node_modules/
test-results/
playwright-report/

# terraform .tfstate files
**/.terraform
*.tfstate*
*.terraform*
4 changes: 4 additions & 0 deletions .vscode/cspell.global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ ignoreWords:
- httptrigger
- resourcegroups
- devcontainer
- azurecaf
- azurerm
- aztfmod
- menuid
useGitignore: true
dictionaryDefinitions:
- name: gitHubUserAliases
Expand Down
1,241 changes: 1,241 additions & 0 deletions templates/common/infra/terraform/applicationinsights/applicationinsights.tf

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "APPLICATIONINSIGHTS_CONNECTION_STRING" {
value = azurerm_application_insights.applicationinsights.connection_string
sensitive = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "location" {
description = "The supported azure location where the resource deployed"
type = string
}

variable "rg_name" {
description = "The name of the resource group to deploy resources into"
type = string
}

variable "environment_name" {
description = "The name of the environment to be deployed"
type = string
}

variable "workspace_id" {
description = "The name of the Azure log analytics workspace"
type = string
}

variable "tags" {
description = "A list of tags used for deployed services."
type = map(string)
}

variable "resource_token" {
description = "A postfix string to centrally mitigate resource name collisions."
type = string
}
15 changes: 15 additions & 0 deletions templates/todo/projects/python-mongo/.repo/terraform/azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

Comment thread
HadwaAbdelhalem marked this conversation as resolved.
name: todo-python-mongo-terraform
metadata:
template: todo-python-mongo-terraform@0.0.1-beta
services:
web:
project: ../../web/react-fluent
dist: build
language: js
host: appservice
api:
project: ../../api/python
language: py
host: appservice
Comment thread
HadwaAbdelhalem marked this conversation as resolved.
119 changes: 119 additions & 0 deletions templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# ------------------------------------------------------------------------------------------------------
# Deploy app service plan
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "plan_name" {
name = random_string.resource_token.result
resource_type = "azurerm_app_service_plan"
random_length = 0
clean_input = true
}

resource "azurerm_service_plan" "plan" {
name = azurecaf_name.plan_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
os_type = "Linux"
sku_name = "B1"

tags = local.tags
}

# ------------------------------------------------------------------------------------------------------
# Deploy app service web app
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "web_name" {
name = "web-${random_string.resource_token.result}"
Comment thread
jongio marked this conversation as resolved.
resource_type = "azurerm_app_service"
random_length = 0
clean_input = true
}

resource "azurerm_linux_web_app" "web" {
name = azurecaf_name.web_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.plan.id
https_only = true
tags = merge(local.tags, { azd-service-name : "web" })

site_config {
always_on = true
ftps_state = "FtpsOnly"
app_command_line = "pm2 serve /home/site/wwwroot --no-daemon --spa"
application_stack {
node_version = "16-lts"
}
}

app_settings = {
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "false"
"APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING
}

logs {
application_logs {
file_system_level = "Verbose"
}
detailed_error_messages = true
failed_request_tracing = true
http_logs {
file_system {
retention_in_days = 1
retention_in_mb = 35
}
}
}
}

# ------------------------------------------------------------------------------------------------------
# Deploy app service api
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "appi_name" {
name = "api-${random_string.resource_token.result}"
resource_type = "azurerm_app_service"
random_length = 0
clean_input = true
}

resource "azurerm_linux_web_app" "api" {
name = azurecaf_name.appi_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.plan.id
https_only = true
tags = merge(local.tags, { "azd-service-name" : "api" })

site_config {
always_on = true
ftps_state = "FtpsOnly"
app_command_line = local.api_command_line
application_stack {
python_version = "3.8"
}
}

identity {
type = "SystemAssigned"
}

app_settings = {
"AZURE_COSMOS_CONNECTION_STRING_KEY" = "AZURE-COSMOS-CONNECTION-STRING"
"AZURE_COSMOS_DATABASE_NAME" = azurerm_cosmosdb_mongo_database.mongodb.name
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
"AZURE_KEY_VAULT_ENDPOINT" = azurerm_key_vault.kv.vault_uri
"APPLICATIONINSIGHTS_CONNECTION_STRING" = module.applicationinsights.APPLICATIONINSIGHTS_CONNECTION_STRING
}
logs {
application_logs {
file_system_level = "Verbose"
}
detailed_error_messages = true
failed_request_tracing = true
http_logs {
file_system {
retention_in_days = 1
retention_in_mb = 35
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ------------------------------------------------------------------------------------------------------
# Deploy cosmos db account
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "db_acc_name" {
name = random_string.resource_token.result
resource_type = "azurerm_cosmosdb_account"
random_length = 0
clean_input = true
}

resource "azurerm_cosmosdb_account" "db" {
name = azurecaf_name.db_acc_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
offer_type = "Standard"
kind = "MongoDB"
enable_automatic_failover = false
enable_multiple_write_locations = false
mongo_server_version = "4.0"
tags = local.tags

capabilities {
name = "EnableServerless"
}

consistency_policy {
consistency_level = "Session"
}

geo_location {
location = azurerm_resource_group.rg.location
failover_priority = 0
zone_redundant = false
}
}

# ------------------------------------------------------------------------------------------------------
# Deploy cosmos mongo db and collections
# ------------------------------------------------------------------------------------------------------
resource "azurerm_cosmosdb_mongo_database" "mongodb" {
name = "Todo"
resource_group_name = azurerm_cosmosdb_account.db.resource_group_name
account_name = azurerm_cosmosdb_account.db.name
}

resource "azurerm_cosmosdb_mongo_collection" "todolist" {
name = "TodoList"
resource_group_name = azurerm_cosmosdb_account.db.resource_group_name
account_name = azurerm_cosmosdb_account.db.name
database_name = azurerm_cosmosdb_mongo_database.mongodb.name
shard_key = "_id"


index {
keys = ["_id"]
unique = true
}
}

resource "azurerm_cosmosdb_mongo_collection" "todocollection" {
name = "TodoItem"
resource_group_name = azurerm_cosmosdb_account.db.resource_group_name
account_name = azurerm_cosmosdb_account.db.name
database_name = azurerm_cosmosdb_mongo_database.mongodb.name
shard_key = "_id"

index {
keys = ["_id"]
unique = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ------------------------------------------------------------------------------------------------------
# DEPLOY AZURE KEYVAULT
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "kv_name" {
name = random_string.resource_token.result
resource_type = "azurerm_key_vault"
random_length = 0
clean_input = true
}

resource "azurerm_key_vault" "kv" {
name = azurecaf_name.kv_name.result
location = azurerm_resource_group.rg.location
Comment thread
jongio marked this conversation as resolved.
resource_group_name = azurerm_resource_group.rg.name
tenant_id = data.azurerm_client_config.current.tenant_id
purge_protection_enabled = false
sku_name = "standard"

tags = local.tags
}

resource "azurerm_key_vault_access_policy" "app" {
key_vault_id = azurerm_key_vault.kv.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = azurerm_linux_web_app.api.identity.0.principal_id

secret_permissions = [
"Get",
"Set",
"List",
"Delete",
]
}

resource "azurerm_key_vault_access_policy" "user" {
count = var.principal_id == "" ? 0 : 1
key_vault_id = azurerm_key_vault.kv.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = var.principal_id

secret_permissions = [
"Get",
"Set",
"List",
"Delete",
]
}

resource "azurerm_key_vault_secret" "dbconnection" {
name = "AZURE-COSMOS-CONNECTION-STRING"
value = azurerm_cosmosdb_account.db.connection_strings[0]
key_vault_id = azurerm_key_vault.kv.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ------------------------------------------------------------------------------------------------------
# Deploy log analytics workspace
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "workspace_name" {
name = random_string.resource_token.result
resource_type = "azurerm_log_analytics_workspace"
random_length = 0
clean_input = true
}

resource "azurerm_log_analytics_workspace" "workspace" {
name = azurecaf_name.workspace_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "PerGB2018"
retention_in_days = 30
tags = local.tags
}
Comment thread
wbreza marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
locals {
tags = { azd-env-name : var.environment_name }
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"
}
# ------------------------------------------------------------------------------------------------------
# Deploy resource Group
# ------------------------------------------------------------------------------------------------------
resource "azurecaf_name" "rg_name" {
name = var.environment_name
resource_type = "azurerm_resource_group"
random_length = 0
clean_input = true
}

resource "azurerm_resource_group" "rg" {
Comment thread
HadwaAbdelhalem marked this conversation as resolved.
name = azurecaf_name.rg_name.result
location = var.location

tags = local.tags
}

resource "random_string" "resource_token" {
length = 10
upper = false
lower = true
numeric = false
special = false
}

# ------------------------------------------------------------------------------------------------------
# Deploy application insights
# ------------------------------------------------------------------------------------------------------
module "applicationinsights" {
source = "../../../../../../common/infra/terraform/applicationinsights"
location = var.location
rg_name = azurerm_resource_group.rg.name
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"location": "${AZURE_LOCATION}",
"environment_name": "${AZURE_ENV_NAME}",
"principal_id": "${AZURE_PRINCIPAL_ID}"
}
Loading