Terraform-provider-azurerm: azurerm_app_service will not configure Path mappings

Created on 28 Jun 2019  路  4Comments  路  Source: terraform-providers/terraform-provider-azurerm

When modifying Path mappings manually on the configuration blade, terraform will not mark the resource as tainted. Also, you are unable to configure these values in the azurerm_app_service block. Virtual path, physical path etc... This is a commonly used configuration in many enterprise applications.

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

Terraform (and AzureRM Provider) Version

Affected Resource(s)

  • azurerm_XXXXX

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000
bug servicapp-service

Most helpful comment

Is there any alternative way to keep it as IaaC? Like ARM Template for only virtual path, physical path configs? Any suggestions?

I scripted it out using Powershell. Here is the function I wrote, you will have to change it to meet your needs. I think you can this inline in your TF code, or add it as a configuration management script somewhere. Im doing a runonce on a script after Terraform provisions to set all of the things I cannot in TF.

Edit: Formatting is getting jacked up sorry.

function Set-WebAppVirtualDirectory {
<#
.SYNOPSIS
Used for setting the Path mappings of an Azure WebApp

        .DESCRIPTION
        Sets the virtual path of the siteconfig object in an Azure WebApp

        .EXAMPLE
        Set-WebAppVirtualDirectory -Branch "something" -Product "somecoolproduct" -Environment "dev" -VirtualPath "/thepath" -PhysicalPath "site\wwwroot\mysite"

        .PARAMETER Branch
        Branch for the specific set of Azure Resources

        .PARAMETER Environment
        Environment for the specific set of Azure Resources

        .PARAMETER VirtualPath
        Virtual directory for the WebApp

        .PARAMETER Product
        Product for the app, like mycoolapp

        .PARAMETER PhysicalPath
        Physical location of the files within Azure

        .PARAMETER PreloadEnabled
        Preload is set to false by default
#>

param(
    [Parameter(Mandatory=$true)][string]$Branch,
    [Parameter(Mandatory=$true)][string]$Environment,
    [Parameter(Mandatory=$true)][string]$Product,
    [Parameter(Mandatory=$true)][string]$VirtualPath,
    [Parameter(Mandatory=$true)][string]$PhysicalPath,
    [string]$PreloadEnabled = "false"
)

$azureWebAppName = "$($Branch)-$($Product)-$($Environment)"
$azureResourceGroup = "$($Branch)-$($Product)-$($Environment)-rg"
$webApp = Get-AzWebApp -Name $azureWebAppName -ResourceGroupName $azureResourceGroup

$virtApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication
$virtApp.VirtualPath = $VirtualPath
$virtApp.PhysicalPath = $PhysicalPath
$virtApp.PreloadEnabled = $PreloadEnabled    

foreach ($path in $webApp.SiteConfig.VirtualApplications.VirtualPath) {
    $existingPaths += @($path)
}

if ($existingPaths.Contains($virtApp.VirtualPath)) {
    Write-Host "Virtual path already exists" 
}
else {        
    $webApp.siteconfig.VirtualApplications.Add($virtApp)
    Set-AzWebApp -WebApp $webApp
}

}

Then I call it with:

Set-WebAppVirtualDirectory -Branch "mymasterbranch" -Environment "dev" -Product "thiscoolproduct" -VirtualPath "/thepath" -PhysicalPath "site\wwwroot\yourwebpage"

All 4 comments

Is there any alternative way to keep it as IaaC? Like ARM Template for only virtual path, physical path configs? Any suggestions?

Is there any alternative way to keep it as IaaC? Like ARM Template for only virtual path, physical path configs? Any suggestions?

I scripted it out using Powershell. Here is the function I wrote, you will have to change it to meet your needs. I think you can this inline in your TF code, or add it as a configuration management script somewhere. Im doing a runonce on a script after Terraform provisions to set all of the things I cannot in TF.

Edit: Formatting is getting jacked up sorry.

function Set-WebAppVirtualDirectory {
<#
.SYNOPSIS
Used for setting the Path mappings of an Azure WebApp

        .DESCRIPTION
        Sets the virtual path of the siteconfig object in an Azure WebApp

        .EXAMPLE
        Set-WebAppVirtualDirectory -Branch "something" -Product "somecoolproduct" -Environment "dev" -VirtualPath "/thepath" -PhysicalPath "site\wwwroot\mysite"

        .PARAMETER Branch
        Branch for the specific set of Azure Resources

        .PARAMETER Environment
        Environment for the specific set of Azure Resources

        .PARAMETER VirtualPath
        Virtual directory for the WebApp

        .PARAMETER Product
        Product for the app, like mycoolapp

        .PARAMETER PhysicalPath
        Physical location of the files within Azure

        .PARAMETER PreloadEnabled
        Preload is set to false by default
#>

param(
    [Parameter(Mandatory=$true)][string]$Branch,
    [Parameter(Mandatory=$true)][string]$Environment,
    [Parameter(Mandatory=$true)][string]$Product,
    [Parameter(Mandatory=$true)][string]$VirtualPath,
    [Parameter(Mandatory=$true)][string]$PhysicalPath,
    [string]$PreloadEnabled = "false"
)

$azureWebAppName = "$($Branch)-$($Product)-$($Environment)"
$azureResourceGroup = "$($Branch)-$($Product)-$($Environment)-rg"
$webApp = Get-AzWebApp -Name $azureWebAppName -ResourceGroupName $azureResourceGroup

$virtApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication
$virtApp.VirtualPath = $VirtualPath
$virtApp.PhysicalPath = $PhysicalPath
$virtApp.PreloadEnabled = $PreloadEnabled    

foreach ($path in $webApp.SiteConfig.VirtualApplications.VirtualPath) {
    $existingPaths += @($path)
}

if ($existingPaths.Contains($virtApp.VirtualPath)) {
    Write-Host "Virtual path already exists" 
}
else {        
    $webApp.siteconfig.VirtualApplications.Add($virtApp)
    Set-AzWebApp -WebApp $webApp
}

}

Then I call it with:

Set-WebAppVirtualDirectory -Branch "mymasterbranch" -Environment "dev" -Product "thiscoolproduct" -VirtualPath "/thepath" -PhysicalPath "site\wwwroot\yourwebpage"

Any update on this issue ? Any plans to support path mappings ?

Here is a non-PowerShell way to do it on creation only by adding it to the azurerm_app_service resource as a provisioner:

  # https://docs.microsoft.com/en-us/azure/app-service/configure-connect-to-azure-storage?pivots=container-windows
  # az webapp config storage-account add --resource-group <group-name> --name <app-name> --custom-id <custom-id> --storage-type AzureFiles --share-name <share-name> --account-name <storage-account-name> --access-key "<access-key>" --mount-path <mount-path-directory of form c:<directory name> >
  # az webapp config storage-account list --resource-group <resource-group> --name <app-name>
  provisioner "local-exec" {
    command = "az webapp config storage-account add --resource-group ${self.resource_group_name} --name ${self.name} --custom-id archive --storage-type AzureFiles --share-name ${azurerm_storage_share.share.name} --account-name ${azurerm_storage_account.storage_account.name} --access-key ${azurerm_storage_account.storage_account.primary_access_key} --mount-path \\path\\to\\folder"
  }

If it is a Linux path, change the --mount-path parameter to something like /path/to/folder

Was this page helpful?
0 / 5 - 0 ratings