Terraform-provider-azurerm: AppService: Setting Virtual applications and directories

Created on 21 Jun 2018  路  9Comments  路  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

_This issue was originally opened by @kalyanrajsista as hashicorp/terraform#18295. It was migrated here as a result of the provider split. The original body of the issue is below._


Hi there,

Can I set virtual applications and directories from app_service resource using terraform?

enhancement servicapp-service

Most helpful comment

For anyone coming back to this in terraform 0.13, I can confirm this code works until the provider supports the creation of virtual applications:

resource "azurerm_template_deployment" "virtual_directory" {
  name                = "virtual_directory"
  resource_group_name = var.resource_group_name
  deployment_mode     = "Incremental"

  template_body = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
        "webAppName": {
            "type": "String"
        },
       "webAppSlotName": {
            "type": "String"
        },
        "virtualApplications":{
        "type": "array",
        "defaultValue":[
            {
            "virtualPath": "/",
            "physicalPath": "site\\wwwroot"
            },
            {
            "virtualPath": "/api",
            "physicalPath": "site\\wwwroot\\api"
            }
        ]
        }
  },
  "variables": {},
  "resources": [
      {
          "type": "Microsoft.Web/sites/config",
          "name": "[concat(parameters('webAppName'), '/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      },
      {
          "type": "Microsoft.Web/sites/slots/config",
          "name": "[concat(parameters('webAppName'),'/', parameters('webAppSlotName'),'/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      }

  ]
}
DEPLOY

  parameters = {
    webAppName          = azurerm_app_service.web_app.name
    webAppSlotName      = azurerm_app_service_slot.web_app_slot.name
  }

  depends_on = [
    azurerm_app_service.web_app,
    azurerm_app_service_slot.web_app_slot
  ]
}

All 9 comments

If possible, it would be great to add on both resources:

  • azurerm_app_service
  • azurerm_app_service_slot

We are using the following:

resource "azurerm_template_deployment" "virtual_directory" {
  name                = "virtual_directory"
  resource_group_name = "${azurerm_resource_group.test.name}"
  deployment_mode     = "Incremental"

  template_body = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
        "webAppName": {
            "type": "String"
        },
       "webAppSlotName": {
            "type": "String"
        },
        "virtualApplications":{
        "type": "array",
        "defaultValue":[
            {
            "virtualPath": "/",
            "physicalPath": "site\\wwwroot",
            "preloadEnabled": false,
            "virtualDirectories": null
            },
            {
            "virtualPath": "/api",
            "physicalPath": "site\\wwwroot\\api",
            "preloadEnabled": false,
            "virtualDirectories": null
            },
            {
            "virtualPath": "/admin",
            "physicalPath": "site\\wwwroot\\admin",
            "preloadEnabled": false,
            "virtualDirectories": null
            }
        ]
        }
  },
  "variables": {},
  "resources": [
      {
          "type": "Microsoft.Web/sites/config",
          "name": "[concat(parameters('webAppName'), '/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      },
      {
          "type": "Microsoft.Web/sites/slots/config",
          "name": "[concat(parameters('webAppName'),'/', parameters('webAppSlotName'),'/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      }

  ]
}
DEPLOY

  parameters {
    "webAppName"          = "${azurerm_app_service.test.name}"
    "webAppSlotName"      = "${azurerm_app_service_slot.msbx_spa.name}"

    # We use the a baked default value; I have not tried the below jsonencode; mostly because it is not easy to read.
    # "virtualApplications" = "${jsonencode(list(map("virtualPath","/","physicalPath","site\\wwwroot","preloadEnabled","false","virtualDirectories","null"),map("virtualPath","/api","physicalPath","site\\wwwroot\\api","preloadEnabled","false","virtualDirectories","null"),map("virtualPath","/admin","physicalPath","site\\wwwroot\\admin","preloadEnabled","false","virtualDirectories","null")))}"
  }

  depends_on = [
    "azurerm_app_service.test",
    "azurerm_app_service_slot.test"
  ]
}

Not ideal, but it works.

I would like to have the same functionality for my App service slot. Please let us know if this is in the road map?

I've also run into this issue while researching if terraform will support this App Service use-case. I think this limitation will require me to use a different tool.

Is this being worked on?

Is this being worked on?

Is this being worked on?

any update on this? We are facing the same problem of not being able to set virtual app after creating it with terraform

is there any alternative to keep IaaC for other configs that not supported by terraform?

For anyone coming back to this in terraform 0.13, I can confirm this code works until the provider supports the creation of virtual applications:

resource "azurerm_template_deployment" "virtual_directory" {
  name                = "virtual_directory"
  resource_group_name = var.resource_group_name
  deployment_mode     = "Incremental"

  template_body = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
        "webAppName": {
            "type": "String"
        },
       "webAppSlotName": {
            "type": "String"
        },
        "virtualApplications":{
        "type": "array",
        "defaultValue":[
            {
            "virtualPath": "/",
            "physicalPath": "site\\wwwroot"
            },
            {
            "virtualPath": "/api",
            "physicalPath": "site\\wwwroot\\api"
            }
        ]
        }
  },
  "variables": {},
  "resources": [
      {
          "type": "Microsoft.Web/sites/config",
          "name": "[concat(parameters('webAppName'), '/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      },
      {
          "type": "Microsoft.Web/sites/slots/config",
          "name": "[concat(parameters('webAppName'),'/', parameters('webAppSlotName'),'/web')]",
          "apiVersion": "2016-08-01",
          "properties": {
              "virtualApplications": "[parameters('virtualApplications')]"
          },
          "dependsOn": []
      }

  ]
}
DEPLOY

  parameters = {
    webAppName          = azurerm_app_service.web_app.name
    webAppSlotName      = azurerm_app_service_slot.web_app_slot.name
  }

  depends_on = [
    azurerm_app_service.web_app,
    azurerm_app_service_slot.web_app_slot
  ]
}
Was this page helpful?
0 / 5 - 0 ratings