Terraform-provider-azurerm: Feature Request: Web App for Containers support

Created on 21 Nov 2017  路  15Comments  路  Source: terraform-providers/terraform-provider-azurerm

Terraform version:

Terraform v0.11.0
+ provider.azurerm v0.3.3
+ provider.random v1.0.0

I'd like to automate deployment of Docker containers as Web Apps to a Linux App Service Plan, i.e. using the equivalent of az webapp create ... --deployment-container-image-name <image URL>.

enhancement servicapp-service upstream-microsoft

Most helpful comment

Hey @mojodna

Thanks for opening this issue :)

Taking a quick look into this issue - this appears to be a regular App Service with the linuxFxVersion field within the site configuration set to DOCKER|(container name + optional version) (e.g. DOCKER|golang or DOCKER|golang:latest); and an app setting of WEBSITES_ENABLE_APP_SERVICE_STORAGE = false.

We don't support this field right now due to a bug in the Azure App Service API - that said once the bug in the API is fixed we can take a look into supporting this functionality. Until then, you should be able to achieve the same thing with the azurerm_template_deployment resource.

Thanks!

All 15 comments

Hey @mojodna

Thanks for opening this issue :)

Taking a quick look into this issue - this appears to be a regular App Service with the linuxFxVersion field within the site configuration set to DOCKER|(container name + optional version) (e.g. DOCKER|golang or DOCKER|golang:latest); and an app setting of WEBSITES_ENABLE_APP_SERVICE_STORAGE = false.

We don't support this field right now due to a bug in the Azure App Service API - that said once the bug in the API is fixed we can take a look into supporting this functionality. Until then, you should be able to achieve the same thing with the azurerm_template_deployment resource.

Thanks!

thanks @tombuildsstuff!

I picked this back up today and haven't been having any luck getting it to work (and can't find any relevant docs). Here's my template:

resource "azurerm_template_deployment" "test" {
  name = "template-01"
  resource_group_name = "${azurerm_resource_group.rg.name}"

  template_body = <<DEPLOY
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "app_service_plan_id": {
      "type": "string",
      "metadata": {
        "description": "App Service Plan ID"
      }
    },
    "name": {
      "type": "string",
      "metadata": {
        "description": "App Name"
      }
    },
    "image": {
      "type": "string",
      "metadata": {
        "description": "Docker image"
      }
    }
  },
  "variables": {
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "kind": "app,linux,container",
      "name": "[parameters('name')]",
      "properties": {
        "siteConfig": {
          "appSettings": [
            {
              "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
              "value": "false"
            }
          ],
          "linuxFxVersion": "[concat('DOCKER|', parameters('image'))]"
        },
        "name": "[parameters('name')]",
        "serverFarmId": "[parameters('app_service_plan_id')]"
      },
      "apiVersion": "2016-08-01",
      "location": "[resourceGroup().location]"
    }
  ]
}
DEPLOY

  parameters {
    name = "golang"
    image = "golang"
    app_service_plan_id = "${azurerm_app_service_plan.plan.id}"
 }

  deployment_mode = "Incremental"
}

Things generally look like they're created properly, but Azure isn't picking it up as a Docker app for some reason.

Help?

+1 I'd also like to be able to use terraform to deploy to Web Apps for Containers.

This is the template I used that worked. The difference is "alwaysOn": true within siteConfig:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "app_service_plan_id": {
      "type": "string",
      "metadata": {
        "description": "App Service Plan ID"
      }
    },
    "name": {
      "type": "string",
      "metadata": {
        "description": "App Name"
      }
    },
    "image": {
      "type": "string",
      "metadata": {
        "description": "Docker image"
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2016-08-01",
      "kind": "app,linux,container",
      "name": "[parameters('name')]",
      "type": "Microsoft.Web/sites",
      "properties": {
        "name": "[parameters('name')]",
        "siteConfig": {
          "alwaysOn": true,
          "appSettings": [
            {
              "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
              "value": "false"
            }
          ],
          "linuxFxVersion": "[concat('DOCKER|', parameters('image'))]"
        },
        "serverFarmId": "[parameters('app_service_plan_id')]"
      },
      "location": "[resourceGroup().location]"
    }
  ]
}

+1

I have a one question, how do you add code to point image a private registry? For example, I need to deploy a web app for container and to point this web app to Azure Container Registry.

Thanks.

Hey @maurivg28
Try adding to @mojodna 's code the following appSettings:

       {
          "name": "DOCKER_REGISTRY_SERVER_URL",              
          "value": "[parameters('registryURL')]"
        },
        {
          "name": "DOCKER_REGISTRY_SERVER_USERNAME",              
          "value": "[parameters('registryLoginName')]"
        },

        {
          "name": "DOCKER_REGISTRY_SERVER_PASSWORD",
          "value": "[parameters('registryPassword')]"
        }

That will configure a private registry for the image.

Cheers,
J.-

+1

Thanks for this, I'm trying to set this up as well. How do I go from the template as shown above, to an actual deployed Docker container that I can load balance to? Does the template provide everything I need, or do I need to reference it from another resource that actually instantiates it?

I'm struggling to make this work. It creates the web app and I can visit mysubdomain.azurewebsites.net, but I just get a landing page with a link to the portal.

One thing missing from these templates is the ability to specify a port for the Docker image. How is this handled? I tried:

          "appSettings": [
            {
              "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
              "value": "false"
            },
            {
              "name": "WEBSITES_PORT",
              "value": "1337"
            }
          ],

And my Docker image, when pulled locally, successfully responds on that port. But since I'm getting a default landing page, I'm beginning to suspect that maybe I'm not setting up the port mapping correctly.

Thanks for any help. I wish I wasn't stuck with Azure's complexity, but I hope I can use Terraform to successfully wrangle it.

This looks great, thanks! When is the next release? I could never get the templates in this issue working despite the fact that I successfully created a container instance via the command line. Unfortunately, command line export of the resulting ARM templates fails, I'm a screen reader user, and the Azure portal and instructions are inaccessible enough that I can't independently follow them. So I pretty much need a text-based configuration format to automate setting this up, and am a bit blocked by not having this in a release. I can certainly wait a few days, I'm just trying to get a rough idea when I might expect to see it out.

Thanks again.

@ndarilek we don鈥檛 generally commit to dates for releases, but I have a feeling we鈥檒l be doing a release later this week :)

what is the status on this one ?

Support for this shipped in v1.10 of the AzureRM Provider a few weeks back; you can update to this by updating your Provider block and re-running terraform init:

provider "azurerm" {
  version = "=1.12.0"
}
Was this page helpful?
0 / 5 - 0 ratings