Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provision Web App for Containers #2827

Closed
tomasaschan opened this issue Feb 1, 2019 · 7 comments
Closed

Provision Web App for Containers #2827

tomasaschan opened this issue Feb 1, 2019 · 7 comments

Comments

@tomasaschan
Copy link
Contributor

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

Azure Web App for Containers are really cool, and I think it would be awesome if this provider supported them!

As far as I can tell, the CLI handles creating them with a couple of extra flags. Basically, you do

az webapp create <other required params> --deployment-container-image-name <image>

to create a single-container app service, and

az webapp create <other required params> --multicontainer-config-type COMPOSE --multicontainer-config-file <path-to-docker-compose>
az webapp create <other required params> --multicontainer-config-type KUBE --multicontainer-config-file <path-to-kubernetes-definition>

to create a multi-container app. However, I haven't been able to figure out whether - and, if it does, how - the Azure SDK for Go supports this yet.

Interestingly, if I create the service plan and web app using the CLI, according to the instructions linked above, I can then import them into my Terraform state and have the following configurations propose no changes:

az group create --name my-rg --location "West Europe"
az appservice plan create --name my-svc-plan --resource-group my-rg --sku S1 --is-linux
az webapp create --resource-group my-rg --plan my-svc-plan --name a-globally-unique-name --multicontainer-config-type compose --multicontainer-config-file a-compose-file-on-disk.yml
resource "azurerm_app_service" "app" {
  name = "a-globally-unique-name"
  resource_group_name = "my-rg"
  location = "westeurope"
  app_service_plan_id = "${azurerm_app_service_plan.svcplan.id}"
}
resource "azurerm_app_service_plan" "svcplan" {
  name = "my-svc-plan"
  resource_group_name = "my-rg"
  location = "westeurope"
  sku = {
    tier = "Standard"
    size = "S1"
  }

  kind = "linux"
}
resource "azurerm_resource_group" "rg" {
  name = "my-rg"
  location = "westeurope"
}

New or Affected Resource(s)

  • azurerm_app_service
@tomasaschan
Copy link
Contributor Author

As a workaround, I just figured out I can do this:

  provisioner "local-exec" {
    command     = "echo version: '3' > docker-compose.yml && echo 'services:' >> docker-compose.yml && az webapp config container set --ids ${azurerm_app_service.frontend.id} --multicontainer-config-type='COMPOSE' --multicontainer-config-file='docker-compose.yml'"
    interpreter = ["bash", "-c"]
  }

It feels hacky and brittle, though... :)

@Djiit
Copy link
Contributor

Djiit commented Feb 5, 2019

Hi there,

The provider already support single container deployment using a DOCKER| prefix on the App Service, and docker compose deployment using a COMPOSE| prefix on the linux_fx_versionparameter.

You need to base64encode your docker-compose file, i.e. COMPOSE|<base64_here>

Maybe this should just be documented ;) If someone can point me in the right direction, I'll be glad to write it.

@tomasaschan
Copy link
Contributor Author

@Djiit Nice! I came back here to write that I'd found that out too :)

I'm currently using the following config:

  site_config = {
    # ...
    linux_fx_version = "COMPOSE|${base64encode("version: '3'\nservices:\n")}"
  }

  lifecycle {
    ignore_changes = [
      "site_config.0.linux_fx_version", # will be updated with every deployment
    ]
  }

The lifecycle annotation is nice because it lets me update the Docker Compose file from my deployment pipelines using the Azure CLI without Terraform being confused next time I want to apply infrastructure changes.

@jnancel
Copy link

jnancel commented Feb 12, 2019

@Djiit Would be great if that could be documented here : https://www.terraform.io/docs/providers/azurerm/r/app_service.html#

A specific example usage for containers would also be great, like what exists for .net and Java.

But it's already great enough that it's supported.

@Djiit
Copy link
Contributor

Djiit commented Feb 12, 2019 via email

@tombuildsstuff tombuildsstuff self-assigned this Feb 25, 2019
@tombuildsstuff
Copy link
Member

hi @tomasaschan @Djiit @jnancel

Thanks for opening this issue :)

Just to let you know that I've added some examples for using Containers within an App Service in #2913 which should help clarify this.

Thanks!

katbyte pushed a commit that referenced this issue Feb 26, 2019
adding docker compose examples to app service docs

Fixes #2827
Fixes #1633
Fixes #1981
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants