|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + azurerm = { |
| 4 | + source = "hashicorp/azurerm" |
| 5 | + version = ">= 3.8" |
| 6 | + } |
| 7 | + } |
| 8 | + |
| 9 | + backend "azurerm" { |
| 10 | + resource_group_name = "cohort32-33_AleYip_ProjectExercise" |
| 11 | + storage_account_name = "m12tfstore" |
| 12 | + container_name = "m12-tf-store-container" |
| 13 | + key = "terraform.tfstate" |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +provider "azurerm" { |
| 18 | + features {} |
| 19 | + subscription_id = "d33b95c7-af3c-4247-9661-aa96d47fccc0" |
| 20 | +} |
| 21 | + |
| 22 | +data "azurerm_resource_group" "main" { |
| 23 | + name = "cohort32-33_AleYip_ProjectExercise" |
| 24 | +} |
| 25 | + |
| 26 | +resource "azurerm_service_plan" "main" { |
| 27 | + name = "${var.prefix}-terraformed-asp" |
| 28 | + location = data.azurerm_resource_group.main.location |
| 29 | + resource_group_name = data.azurerm_resource_group.main.name |
| 30 | + os_type = "Linux" |
| 31 | + sku_name = "B1" |
| 32 | +} |
| 33 | + |
| 34 | +resource "azurerm_linux_web_app" "main" { |
| 35 | + name = "${var.prefix}-aleyipsoftwire-m12-exercise" |
| 36 | + location = data.azurerm_resource_group.main.location |
| 37 | + resource_group_name = data.azurerm_resource_group.main.name |
| 38 | + service_plan_id = azurerm_service_plan.main.id |
| 39 | + |
| 40 | + site_config { |
| 41 | + application_stack { |
| 42 | + docker_image_name = "aleyipsoftwire/todo-app:prod" |
| 43 | + docker_registry_url = "https://docker.io" |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + app_settings = { |
| 48 | + WEBSITES_PORT = 8000 |
| 49 | + MONGODB_PRIMARY_CONNECTION_STRING = azurerm_cosmosdb_account.main.primary_mongodb_connection_string |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +resource "azurerm_cosmosdb_account" "main" { |
| 54 | + name = "${var.prefix}-aleyipsoftwire-m12-mongodb-cluster" |
| 55 | + location = data.azurerm_resource_group.main.location |
| 56 | + resource_group_name = data.azurerm_resource_group.main.name |
| 57 | + offer_type = "Standard" |
| 58 | + kind = "MongoDB" |
| 59 | + |
| 60 | + automatic_failover_enabled = true |
| 61 | + |
| 62 | + capabilities { |
| 63 | + name = "EnableMongo" |
| 64 | + } |
| 65 | + |
| 66 | + capabilities { |
| 67 | + name = "EnableServerless" |
| 68 | + } |
| 69 | + |
| 70 | + consistency_policy { |
| 71 | + consistency_level = "BoundedStaleness" |
| 72 | + max_interval_in_seconds = 300 |
| 73 | + max_staleness_prefix = 100000 |
| 74 | + } |
| 75 | + |
| 76 | + geo_location { |
| 77 | + location = "uksouth" |
| 78 | + failover_priority = 0 |
| 79 | + } |
| 80 | + |
| 81 | + lifecycle { |
| 82 | + prevent_destroy = true |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +resource "azurerm_cosmosdb_mongo_database" "main" { |
| 87 | + name = "todo-app-db" |
| 88 | + resource_group_name = data.azurerm_resource_group.main.name |
| 89 | + account_name = azurerm_cosmosdb_account.main.name |
| 90 | +} |
0 commit comments