Creating an app service - Terraform
To run web apps in Azure you need to first create an App Service Plan. If you are using custom domains then the certificates need to be assigned to the app service so that the apps can make use of them.
For a single client application, we can create and use a single application insights resource. This helps application insights to link multiple resources.
# This file creates an App Service Plan in Azure.
# It also creates an Application Insights resource and adds a certificate to the App Service.
# Create App Service plan
resource "azurerm_service_plan" "appserviceplan" {
name = var.asp_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
os_type = "Windows"
sku_name = var.asp_sku
}
# Get iscquare-net cert from key vault
data "azurerm_key_vault_secret" "iscquare_net_cert" {
name = var.key_vault_certificate_name
key_vault_id = azurerm_key_vault.keyvault.id
}
# Add certificate to App Service
resource "azurerm_app_service_certificate" "iscquare_net_cert" {
name = var.key_vault_certificate_name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
key_vault_secret_id = data.azurerm_key_vault_secret.iscquare_net_cert.id
}
# Create an application insights resource
resource "azurerm_application_insights" "appinsights" {
name = var.appinsights_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
application_type = "web"
}