Skip to content

Commit

Permalink
terraform: Fix random VM image deployment errors
Browse files Browse the repository at this point in the history
Signed-off-by: Henri Rosten <[email protected]>
  • Loading branch information
henrirosten committed Dec 9, 2024
1 parent 4070ca0 commit 3a52328
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions terraform/binary-cache.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions terraform/builder.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions terraform/jenkins-controller.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions terraform/modules/azurerm-nix-vm-image/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 3a52328

Please sign in to comment.