Reputation: 3860
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
}
Upvotes: 2
Views: 1657
Reputation: 21
This is now possible to manage fully in terraform. See this little guide on how to do it.
Upvotes: 1
Reputation: 31454
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.
Upvotes: 1