Skip to main content
  1. Posts/

AZ webapps doodle

·2 mins·

Building upon the success of the previous post this time I went to deploy a web app too. It was not more complicated than the previous exercise – only about 20 minutes in total (including typing this post!)

  • terragrunt.hcl file just to have the resource groups ready

  • the main.tf to store the config of the web app (note: I use sample code and I use a random number in the app’s address…not recommended to production!)

  • output.tf file to display the web apps line

#  cat .\terragrunt.hcl
include {
  path = find_in_parent_folders()
}

dependencies {
  paths = ["../resource-groups"]
}
# cat .\main.tf
data "azurerm_resource_group" "webapp_rg" {
  name = "my-webapp-rg"
}

# Generate a random integer to create a globally unique name
resource "random_integer" "ri" {
  min = 10000
  max = 99999
}

# Create the Linux App Service Plan
resource "azurerm_service_plan" "appserviceplan" {
  name                = "webapp-asp-${random_integer.ri.result}"
  location            = data.azurerm_resource_group.webapp_rg.location
  resource_group_name = data.azurerm_resource_group.webapp_rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

# Create the web app, pass in the App Service Plan ID
resource "azurerm_linux_web_app" "webapp" {
  name                = "webapp-${random_integer.ri.result}"
  location            = data.azurerm_resource_group.webapp_rg.location
  resource_group_name = data.azurerm_resource_group.webapp_rg.name
  service_plan_id     = azurerm_service_plan.appserviceplan.id
  https_only          = true
  site_config {
    minimum_tls_version = "1.2"
  }
}

#  Deploy code from a public GitHub repo
resource "azurerm_app_service_source_control" "sourcecontrol" {
  app_id                 = azurerm_linux_web_app.webapp.id
  repo_url               = "https://github.com/Azure-Samples/nodejs-docs-hello-world"
  branch                 = "master"
  use_manual_integration = true
  use_mercurial          = false
}
# cat .\outputs.tf
output "url" {
  value = "http://${azurerm_linux_web_app.webapp.name}.azurewebsites.net/"
}

The result we have all been waiting for: it is slightly depressingly empty, but hey – the web app is your Oyster!

empty webapp
an empty webapp