|
| 1 | +# Azure App Service (Web Apps) Terraform Module |
| 2 | + |
| 3 | +Terraform module to create Azure App Service with optional site_config, backup, connection_string, auth_settings and Storage for mount points. |
| 4 | + |
| 5 | +## Module Usage to create simple app service with optional resoruces |
| 6 | + |
| 7 | +```hcl |
| 8 | +# Azurerm Provider configuration |
| 9 | +provider "azurerm" { |
| 10 | + features {} |
| 11 | +} |
| 12 | +
|
| 13 | +module "app-service" { |
| 14 | + source = "kumarvna/app-service/azurerm" |
| 15 | + version = "1.1.0" |
| 16 | +
|
| 17 | + # By default, this module will not create a resource group. Location will be same as existing RG. |
| 18 | + # proivde a name to use an existing resource group, specify the existing resource group name, |
| 19 | + # set the argument to `create_resource_group = true` to create new resrouce group. |
| 20 | + resource_group_name = "rg-shared-westeurope-01" |
| 21 | +
|
| 22 | + # App service plan setttings and supported arguments. Default name used by module |
| 23 | + # To specify custom name use `app_service_plan_name` with a valid name. |
| 24 | + # for Service Plans, see https://azure.microsoft.com/en-us/pricing/details/app-service/windows/ |
| 25 | + # App Service Plan for `Free` or `Shared` Tiers `use_32_bit_worker_process` must be set to `true`. |
| 26 | + service_plan = { |
| 27 | + kind = "Windows" |
| 28 | + size = "P1v2" |
| 29 | + tier = "PremiumV2" |
| 30 | + } |
| 31 | +
|
| 32 | + # App Service settings and supported arguments |
| 33 | + # Backup, connection_string, auth_settings, Storage for mounts are optional configuration |
| 34 | + app_service_name = "myapp-poc-project" |
| 35 | + enable_client_affinity = true |
| 36 | +
|
| 37 | + # A `site_config` block to setup the application environment. |
| 38 | + # Available built-in stacks (windows_fx_version) for web apps `az webapp list-runtimes` |
| 39 | + # Runtime stacks for Linux (linux_fx_version) based web apps `az webapp list-runtimes --linux` |
| 40 | + site_config = { |
| 41 | + always_on = true |
| 42 | + dotnet_framework_version = "v2.0" |
| 43 | + ftps_state = "FtpsOnly" |
| 44 | + managed_pipeline_mode = "Integrated" |
| 45 | + use_32_bit_worker_process = true |
| 46 | + windows_fx_version = "DOTNETCORE|2.1" |
| 47 | + } |
| 48 | +
|
| 49 | + # (Optional) A key-value pair of Application Settings |
| 50 | + app_settings = { |
| 51 | + APPINSIGHTS_PROFILERFEATURE_VERSION = "1.0.0" |
| 52 | + APPINSIGHTS_SNAPSHOTFEATURE_VERSION = "1.0.0" |
| 53 | + DiagnosticServices_EXTENSION_VERSION = "~3" |
| 54 | + InstrumentationEngine_EXTENSION_VERSION = "disabled" |
| 55 | + SnapshotDebugger_EXTENSION_VERSION = "disabled" |
| 56 | + XDT_MicrosoftApplicationInsights_BaseExtensions = "disabled" |
| 57 | + XDT_MicrosoftApplicationInsights_Java = "1" |
| 58 | + XDT_MicrosoftApplicationInsights_Mode = "recommended" |
| 59 | + XDT_MicrosoftApplicationInsights_NodeJS = "1" |
| 60 | + XDT_MicrosoftApplicationInsights_PreemptSdk = "disabled" |
| 61 | + } |
| 62 | +
|
| 63 | + # The Backup feature in Azure App Service easily create app backups manually or on a schedule. |
| 64 | + # You can configure the backups to be retained up to an indefinite amount of time. |
| 65 | + # Azure storage account and container in the same subscription as the app that you want to back up. |
| 66 | + # This module creates a Storage Container to keep the all backup items. |
| 67 | + # Backup items - App configuration , File content, Database connected to your app |
| 68 | + enable_backup = true |
| 69 | + storage_account_name = "stdiagfortesting1" |
| 70 | + backup_settings = { |
| 71 | + enabled = true |
| 72 | + name = "DefaultBackup" |
| 73 | + frequency_interval = 1 |
| 74 | + frequency_unit = "Day" |
| 75 | + retention_period_in_days = 90 |
| 76 | + } |
| 77 | +
|
| 78 | + # By default App Insight resource is created by this module. |
| 79 | + # Specify valid resource Id to `application_insights_id` to use existing App Insight |
| 80 | + # Specifies the type of Application by setting up `application_insights_type` with valid string |
| 81 | + # Specifies the retention period in days using `retention_in_days`. Default 90. |
| 82 | + # By default the real client ip is masked in the logs, to enable set `disable_ip_masking` to `true` |
| 83 | + app_insights_name = "otkpocshared" |
| 84 | +
|
| 85 | + # Adding TAG's to your Azure resources |
| 86 | + tags = { |
| 87 | + ProjectName = "demo-internal" |
| 88 | + Env = "dev" |
| 89 | + |
| 90 | + BusinessUnit = "CORP" |
| 91 | + ServiceClass = "Gold" |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +## Module Usage to create app service and optional resoruces with VNet integration |
| 97 | + |
| 98 | +```hcl |
| 99 | +# Azurerm Provider configuration |
| 100 | +provider "azurerm" { |
| 101 | + features {} |
| 102 | +} |
| 103 | +
|
| 104 | +locals { |
| 105 | + tags = { |
| 106 | + ProjectName = "demo-internal" |
| 107 | + Env = "dev" |
| 108 | + |
| 109 | + BusinessUnit = "CORP" |
| 110 | + ServiceClass = "Gold" |
| 111 | + } |
| 112 | +} |
| 113 | +
|
| 114 | +module "vnet" { |
| 115 | + source = "kumarvna/vnet/azurerm" |
| 116 | + version = "2.1.0" |
| 117 | +
|
| 118 | + create_resource_group = false |
| 119 | + resource_group_name = "rg-shared-westeurope-01" |
| 120 | + vnetwork_name = "vnet-shared-hub-westeurope-002" |
| 121 | + location = "westeurope" |
| 122 | + vnet_address_space = ["10.2.0.0/16"] |
| 123 | + create_network_watcher = false |
| 124 | +
|
| 125 | + subnets = { |
| 126 | + web_subnet = { |
| 127 | + subnet_name = "snet-webapp" |
| 128 | + subnet_address_prefix = ["10.2.1.0/24"] |
| 129 | + delegation = { |
| 130 | + name = "testdelegation" |
| 131 | + service_delegation = { |
| 132 | + name = "Microsoft.Web/serverFarms" |
| 133 | + actions = ["Microsoft.Network/virtualNetworks/subnets/action"] |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + tags = local.tags |
| 139 | +} |
| 140 | +
|
| 141 | +module "app-service" { |
| 142 | + source = "kumarvna/app-service/azurerm" |
| 143 | + version = "1.1.0" |
| 144 | +
|
| 145 | + # By default, this module will not create a resource group. Location will be same as existing RG. |
| 146 | + # proivde a name to use an existing resource group, specify the existing resource group name, |
| 147 | + # set the argument to `create_resource_group = true` to create new resrouce group. |
| 148 | + resource_group_name = "rg-shared-westeurope-01" |
| 149 | +
|
| 150 | + # App service plan setttings and supported arguments. Default name used by module |
| 151 | + # To specify custom name use `app_service_plan_name` with a valid name. |
| 152 | + # for Service Plans, see https://azure.microsoft.com/en-us/pricing/details/app-service/windows/ |
| 153 | + # App Service Plan for `Free` or `Shared` Tiers `use_32_bit_worker_process` must be set to `true`. |
| 154 | + service_plan = { |
| 155 | + kind = "Windows" |
| 156 | + size = "P1v2" |
| 157 | + tier = "PremiumV2" |
| 158 | + } |
| 159 | +
|
| 160 | + # App Service settings and supported arguments |
| 161 | + # Backup, connection_string, auth_settings, Storage for mounts are optional configuration |
| 162 | + app_service_name = "kumarsmypocproject" |
| 163 | + enable_client_affinity = true |
| 164 | +
|
| 165 | + # A `site_config` block to setup the application environment. |
| 166 | + # Available built-in stacks (windows_fx_version) for web apps `az webapp list-runtimes` |
| 167 | + # Runtime stacks for Linux (linux_fx_version) based web apps `az webapp list-runtimes --linux` |
| 168 | + site_config = { |
| 169 | + always_on = true |
| 170 | + dotnet_framework_version = "v2.0" |
| 171 | + ftps_state = "FtpsOnly" |
| 172 | + managed_pipeline_mode = "Integrated" |
| 173 | + use_32_bit_worker_process = true |
| 174 | + windows_fx_version = "DOTNETCORE|2.1" |
| 175 | + } |
| 176 | +
|
| 177 | + # (Optional) A key-value pair of Application Settings |
| 178 | + app_settings = { |
| 179 | + APPINSIGHTS_PROFILERFEATURE_VERSION = "1.0.0" |
| 180 | + APPINSIGHTS_SNAPSHOTFEATURE_VERSION = "1.0.0" |
| 181 | + DiagnosticServices_EXTENSION_VERSION = "~3" |
| 182 | + InstrumentationEngine_EXTENSION_VERSION = "disabled" |
| 183 | + SnapshotDebugger_EXTENSION_VERSION = "disabled" |
| 184 | + XDT_MicrosoftApplicationInsights_BaseExtensions = "disabled" |
| 185 | + XDT_MicrosoftApplicationInsights_Java = "1" |
| 186 | + XDT_MicrosoftApplicationInsights_Mode = "recommended" |
| 187 | + XDT_MicrosoftApplicationInsights_NodeJS = "1" |
| 188 | + XDT_MicrosoftApplicationInsights_PreemptSdk = "disabled" |
| 189 | + } |
| 190 | +
|
| 191 | + # The Backup feature in Azure App Service easily create app backups manually or on a schedule. |
| 192 | + # You can configure the backups to be retained up to an indefinite amount of time. |
| 193 | + # Azure storage account and container in the same subscription as the app that you want to back up. |
| 194 | + # This module creates a Storage Container to keep the all backup items. |
| 195 | + # Backup items - App configuration , File content, Database connected to your app |
| 196 | + enable_backup = true |
| 197 | + storage_account_name = "stdiagfortesting1" |
| 198 | + backup_settings = { |
| 199 | + enabled = true |
| 200 | + name = "DefaultBackup" |
| 201 | + frequency_interval = 1 |
| 202 | + frequency_unit = "Day" |
| 203 | + retention_period_in_days = 90 |
| 204 | + } |
| 205 | +
|
| 206 | + # Regional VNet integration configuration |
| 207 | + # Enables you to place the back end of app in a subnet in virtual network in the same region |
| 208 | + enable_vnet_integration = true |
| 209 | + subnet_id = element(module.vnet.subnet_ids, 0) |
| 210 | +
|
| 211 | + # By default App Insight resource is created by this module. |
| 212 | + # Specify valid resource Id to `application_insights_id` to use existing App Insight |
| 213 | + # Specifies the type of Application by setting up `application_insights_type` with valid string |
| 214 | + # Specifies the retention period in days using `retention_in_days`. Default 90. |
| 215 | + # By default the real client ip is masked in the logs, to enable set `disable_ip_masking` to `true` |
| 216 | + app_insights_name = "otkpocshared" |
| 217 | +
|
| 218 | + # Adding TAG's to your Azure resources |
| 219 | + tags = local.tags |
| 220 | +} |
| 221 | +``` |
| 222 | + |
| 223 | +## Terraform Usage |
| 224 | + |
| 225 | +To run this example you need to execute following Terraform commands |
| 226 | + |
| 227 | +```hcl |
| 228 | +terraform init |
| 229 | +terraform plan |
| 230 | +terraform apply |
| 231 | +``` |
| 232 | + |
| 233 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments