-
Notifications
You must be signed in to change notification settings - Fork 340
Add python-mongo template terraform #532
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
Merged
HadwaAbdelhalem
merged 35 commits into
Azure:main
from
kaizentm:cse/add-template-terraform
Sep 2, 2022
Merged
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 60a463b
adding vscode debugging support
hattan 68e6947
adding .tmp folder to gitignore
hattan 362572c
refator to support bicep in folder structure
hattan 3d18273
update repoman to add new rule to copy specific files, update repoman…
HadwaAbdelhalem f2152c3
add aca/bicep layer in common infra folders
HadwaAbdelhalem bb37d8a
update to set -t to the project template
HadwaAbdelhalem 6e115b0
update node-js-mongo project
HadwaAbdelhalem 222007b
update repo.yaml files to reference common/infra/bicep
HadwaAbdelhalem de0f308
Removing extra lines in python-mongo azure*.yaml files.
hattan c1b9754
Code Cleanup
HadwaAbdelhalem d3fb35d
redirect configurations to upstream azure/azure-dev
HadwaAbdelhalem ec30798
address bicep lint failures
HadwaAbdelhalem dd99040
Update todo-project template.
HadwaAbdelhalem f38bf69
Merge remote-tracking branch 'upstream/main' into cse/restructure-inf…
HadwaAbdelhalem 861e34a
fix asset rules for path rewitre
HadwaAbdelhalem 9e1fa5a
Add rewrite path rules tmp fix
HadwaAbdelhalem c0657b3
add python-mongo, application insights terraform modules
HadwaAbdelhalem 616f1a0
add repo.yml, azure.yml files
HadwaAbdelhalem 6e0cb75
fix asset rules
HadwaAbdelhalem f7d4c4b
ignore terraform files
HadwaAbdelhalem 1e4730c
merge upstream main
HadwaAbdelhalem 5d139d8
update remote main and staging urls
HadwaAbdelhalem 025d3d8
fix typo, update cspell
HadwaAbdelhalem 3c7e7b7
addreses PR feedback
HadwaAbdelhalem bd7de3f
update template name
HadwaAbdelhalem 01188dd
split resources in multiple files.
HadwaAbdelhalem 17dc803
resolve cspell
HadwaAbdelhalem 65bee8b
address review comments
HadwaAbdelhalem 44f3620
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem b9691cd
add tfvars.json
HadwaAbdelhalem 18635d9
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem 3cccab7
add rewrite path rules
HadwaAbdelhalem bd804fb
rename to environment_name
HadwaAbdelhalem a71cbbf
Merge branch 'main' into cse/add-template-terraform
HadwaAbdelhalem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,241 changes: 1,241 additions & 0 deletions
1,241
templates/common/infra/terraform/applicationinsights/applicationinsights.tf
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
templates/common/infra/terraform/applicationinsights/applicationinsights_output.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
29 changes: 29 additions & 0 deletions
29
templates/common/infra/terraform/applicationinsights/applicationinsights_variables.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
15
templates/todo/projects/python-mongo/.repo/terraform/azure.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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 | ||
|
HadwaAbdelhalem marked this conversation as resolved.
|
||
119 changes: 119 additions & 0 deletions
119
templates/todo/projects/python-mongo/.repo/terraform/infra/apps.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" | ||
|
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 | ||
| } | ||
| } | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
templates/todo/projects/python-mongo/.repo/terraform/infra/cosmos.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
templates/todo/projects/python-mongo/.repo/terraform/infra/keyvault.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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 | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
templates/todo/projects/python-mongo/.repo/terraform/infra/loganalytics.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
wbreza marked this conversation as resolved.
|
||
41 changes: 41 additions & 0 deletions
41
templates/todo/projects/python-mongo/.repo/terraform/infra/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" { | ||
|
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 | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
templates/todo/projects/python-mongo/.repo/terraform/infra/main.tfvars.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.