Skip to content

Commit 19a180a

Browse files
authored
Merge pull request #7 from DacoDev/6-multiple-calls-of-the-module-with-the-same-container_template_file-results-in-conflict
fix: issue #6
2 parents dc54203 + 6de30bd commit 19a180a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

main.tf

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ terraform {
44
source = "bpg/proxmox"
55
version = "0.43.2"
66
}
7+
random = {
8+
source = "hashicorp/random"
9+
version = "3.6.0"
10+
}
711
}
812
}
13+
14+
resource "random_uuid" "name_suffix" {}
15+
916
locals {
10-
container_template_file_insecure = can(regex("^https:\\/\\/.*", var.container_template_file)) ? "false" : "true"
11-
container_template_file_download = (can(regex("^https?:\\/\\/.*", var.container_template_file)) && var.migrate_template_file == true) ? 1 : 0
12-
container_template_file_local = (local.container_template_file_download == 0 || var.migrate_template_file == false) ? 1 : 0
13-
container_template = (local.container_template_file_download == 1 && var.migrate_template_file == true) ? proxmox_virtual_environment_download_file.container_template[0].id : proxmox_virtual_environment_file.container_template[0].id
17+
container_template_file_insecure = can(regex("^https:\\/\\/.*", var.container_template_file)) ? "false" : "true"
18+
container_template_file_download = (can(regex("^https?:\\/\\/.*", var.container_template_file)) && var.migrate_template_file == true) ? 1 : 0
19+
container_template_file_download_name = local.container_template_file_download == 1 ? format("%s-%s", random_uuid.name_suffix.result, join("", regex("^https?:\\/\\/.*\\/.*?\\/?(.*)", var.container_template_file))) : null
20+
container_template_file_local = (local.container_template_file_download == 0 || var.migrate_template_file == false) ? 1 : 0
21+
container_template = (local.container_template_file_download == 1 && var.migrate_template_file == true) ? proxmox_virtual_environment_download_file.container_template[0].id : proxmox_virtual_environment_file.container_template[0].id
1422
}
1523

1624
resource "proxmox_virtual_environment_container" "proxmox_lxc" {
@@ -61,6 +69,7 @@ resource "proxmox_virtual_environment_file" "container_template" {
6169

6270
resource "proxmox_virtual_environment_download_file" "container_template" {
6371
count = local.container_template_file_download
72+
file_name = local.container_template_file_download_name
6473
content_type = "vztmpl"
6574
datastore_id = "local"
6675
node_name = var.node_name

0 commit comments

Comments
 (0)