-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages.tf
67 lines (62 loc) · 2.27 KB
/
images.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
locals {
# images to copy into the azure container registry.
source_images = {
# see https://hub.docker.com/_/caddy
caddy = {
name = "docker.io/library/caddy"
# renovate: datasource=docker depName=library/caddy
tag = "2.9.1"
}
# see https://github.com/cloudbase/garm/pkgs/container/garm
garm = {
name = "ghcr.io/cloudbase/garm"
# renovate: datasource=docker depName=cloudbase/garm registryUrl=https://ghcr.io
tag = "v0.1.5"
}
}
images = {
for key, value in local.source_images : key => "${azurerm_container_registry.garm.login_server}/${key}:${value.tag}"
}
}
# see https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry
# NB this name must be unique within azure.
# it will be used as the registry public FQDN as {name}.azurecr.io.
# NB garmcr123.azurecr.io
resource "azurerm_container_registry" "garm" {
resource_group_name = azurerm_resource_group.garm.name
location = azurerm_resource_group.garm.location
name = "garm${local.dns_name_label}"
sku = "Basic"
admin_enabled = true
}
# see https://developer.hashicorp.com/terraform/language/resources/terraform-data
resource "terraform_data" "acr_image" {
for_each = local.source_images
triggers_replace = {
source_image = "${each.value.name}:${each.value.tag}"
target_image = local.images[each.key]
target_location = azurerm_container_registry.garm.location
}
provisioner "local-exec" {
when = create
environment = {
ACR_IMAGE_COMMAND = "copy"
ACR_IMAGE_SOURCE_IMAGE = "${each.value.name}:${each.value.tag}"
ACR_IMAGE_TARGET_IMAGE = local.images[each.key]
ACR_IMAGE_TARGET_LOCATION = azurerm_container_registry.garm.location
}
interpreter = ["bash"]
command = "${path.module}/acr-image.sh"
}
provisioner "local-exec" {
when = destroy
environment = {
ACR_IMAGE_COMMAND = "delete"
ACR_IMAGE_SOURCE_IMAGE = self.triggers_replace.source_image
ACR_IMAGE_TARGET_IMAGE = self.triggers_replace.target_image
ACR_IMAGE_TARGET_LOCATION = self.triggers_replace.target_location
}
interpreter = ["bash"]
command = "${path.module}/acr-image.sh"
}
}