1

I am using Terraform to set up an infrastructure, in which I want to run a Docker container (using ACI) every day, with the same (default) command every time.

My initial idea is to use Terraform to provision a Container Group resource, and then my only remaining task is to make sure it is started every day. However, I can't figure out how to do this the simplest.

Currently, my attempt is to use Logic Apps, but I can't find the right action. Ideally, a Container Group had a web-hook that could trigger it starting, or logic apps had an action that could run Azure CLI commands.

Any input?

provider "azure" {

}

resource "azurerm_resource_group" "test" {
  name     = "testResourceGroup1"
  location = "North Europe"
}

data "azurerm_container_registry" "test" {
  name                = "..."
  resource_group_name = "..."
}

resource "azurerm_container_group" "example" {
  name                = "example-continst"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
  os_type             = "Linux"
  ip_address_type     = "Public"
  restart_policy      = "Never"

  image_registry_credential {
    username = "${data.azurerm_container_registry.test.admin_username}"
    password = "${data.azurerm_container_registry.test.admin_password}"
    server = "${data.azurerm_container_registry.test.login_server}"
  }

  container {
    name   = "main"
    image  = "${data.azurerm_container_registry.test.login_server}/compute-instance"
    cpu    = "1.0"
    memory = "1.0"

    ports {
      port     = 443
      protocol = "TCP"
    }
  }
}

resource "azurerm_logic_app_workflow" "test" {
  name                = "workflow1"
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_logic_app_trigger_recurrence" "test" {
  name         = "run-every-day"
  logic_app_id = "${azurerm_logic_app_workflow.test.id}"
  frequency    = "Day"
  interval     = 1
}
casparjespersen
  • 3,460
  • 5
  • 38
  • 63
  • I am trying to do something similar. Why is it so hard to just run a Docker image once a day in Azure? In the documentation, I keep getting the watered-down runaround. Did you find a solution? – Thomas Beauvais Feb 25 '21 at 11:02

2 Answers2

1

For the container group, there is no webhook to create a trigger to let the container group starts every day. For logic app, as I know, it does not support running the Azure CLI commands.

For your purpose that starts the container group every day. To the container group, stop and start, it also means creating a new container group with the same configuration. See Manually stop or start containers in Azure Container Instances. According to this and in the logic app, you can create a time trigger that creates the container group and deletes it later, then repeats the trigger every day.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
0

This is now possible to manage fully in terraform. See this little guide on how to do it.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34871743) – mechnicov Aug 26 '23 at 19:44