From 3a5232842ce34b1bca1260a4db5067d0e3fd2d80 Mon Sep 17 00:00:00 2001 From: Henri Rosten Date: Thu, 5 Dec 2024 08:43:14 +0200 Subject: [PATCH] terraform: Fix random VM image deployment errors Signed-off-by: Henri Rosten --- terraform/binary-cache.tf | 1 + terraform/builder.tf | 1 + terraform/jenkins-controller.tf | 1 + terraform/main.tf | 9 ++++++++- terraform/modules/azurerm-nix-vm-image/main.tf | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/terraform/binary-cache.tf b/terraform/binary-cache.tf index 11808a44..52dfcae1 100644 --- a/terraform/binary-cache.tf +++ b/terraform/binary-cache.tf @@ -16,6 +16,7 @@ module "binary_cache_image" { location = azurerm_resource_group.infra.location storage_account_name = azurerm_storage_account.vm_images.name storage_container_name = azurerm_storage_container.vm_images.name + depends_on = [azurerm_storage_container.vm_images] } module "binary_cache_vm" { diff --git a/terraform/builder.tf b/terraform/builder.tf index fc4a8f2d..3ff2a851 100644 --- a/terraform/builder.tf +++ b/terraform/builder.tf @@ -17,6 +17,7 @@ module "builder_image" { location = azurerm_resource_group.infra.location storage_account_name = azurerm_storage_account.vm_images.name storage_container_name = azurerm_storage_container.vm_images.name + depends_on = [azurerm_storage_container.vm_images] } locals { diff --git a/terraform/jenkins-controller.tf b/terraform/jenkins-controller.tf index 72f3e581..5066f976 100644 --- a/terraform/jenkins-controller.tf +++ b/terraform/jenkins-controller.tf @@ -17,6 +17,7 @@ module "jenkins_controller_image" { location = azurerm_resource_group.infra.location storage_account_name = azurerm_storage_account.vm_images.name storage_container_name = azurerm_storage_container.vm_images.name + depends_on = [azurerm_storage_container.vm_images] } # Create a machine using this image diff --git a/terraform/main.tf b/terraform/main.tf index be9a4aa7..0e2a88f2 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -216,9 +216,16 @@ resource "azurerm_subnet" "builders" { address_prefixes = ["10.0.4.0/28"] } +# https://github.com/hashicorp/terraform-provider-azurerm/issues/15609 +resource "random_string" "id" { + length = 8 + upper = false + special = false +} + # Storage account and storage container used to store VM images resource "azurerm_storage_account" "vm_images" { - name = "img${local.ws}${local.shortloc}" + name = "img${random_string.id.result}" resource_group_name = azurerm_resource_group.infra.name location = azurerm_resource_group.infra.location account_tier = "Standard" diff --git a/terraform/modules/azurerm-nix-vm-image/main.tf b/terraform/modules/azurerm-nix-vm-image/main.tf index fad8b9b6..421f7e9a 100644 --- a/terraform/modules/azurerm-nix-vm-image/main.tf +++ b/terraform/modules/azurerm-nix-vm-image/main.tf @@ -38,6 +38,10 @@ resource "azurerm_image" "default" { os_state = "Generalized" os_type = "Linux" } + depends_on = [ + azurerm_storage_blob.default, + data.external.nix_build + ] } output "image_id" {