Skip to content

Commit

Permalink
[NWSDE #107] Add Windows image field to Admin VM template
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyry committed Jan 16, 2025
1 parent fa7df46 commit f3ede8c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
12 changes: 12 additions & 0 deletions templates/shared_services/admin-vm/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
"source": {
"env": "KEY_STORE_ID"
}
},
{
"name": "os_image",
"source": {
"env": "OS_IMAGE"
}
},
{
"name": "image_gallery_id",
"source": {
"env": "IMAGE_GALLERY_ID"
}
}
]
}
27 changes: 26 additions & 1 deletion templates/shared_services/admin-vm/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
---
schemaVersion: 1.0.0
name: tre-shared-service-admin-vm
version: 0.5.1
version: 0.5.2
description: "An admin vm shared service"
dockerfile: Dockerfile.tmpl
registry: azuretre

custom:
image_options:
"Windows 11":
source_image_reference:
publisher: MicrosoftWindowsDesktop
offer: windows-11
sku: win11-24h2-pro
version: latest
# For information on using custom images, see README.me in the guacamole/user-resources folder
# "Custom Image From Gallery":
# source_image_name: your-image

credentials:
- name: azure_tenant_id
env: ARM_TENANT_ID
Expand Down Expand Up @@ -50,6 +62,13 @@ parameters:
- name: key_store_id
type: string
default: ""
- name: os_image
type: string
default: "Windows 11"
- name: image_gallery_id
type: string
description: Azure resource ID for the compute image gallery to pull images from (if specifying custom images by name)
default: ""

mixins:
- terraform:
Expand All @@ -64,6 +83,8 @@ install:
admin_jumpbox_vm_sku: ${ bundle.parameters.admin_jumpbox_vm_sku }
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
image: ${ bundle.parameters.os_image }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
Expand All @@ -81,6 +102,8 @@ upgrade:
admin_jumpbox_vm_sku: ${ bundle.parameters.admin_jumpbox_vm_sku }
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
image: ${ bundle.parameters.os_image }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
Expand All @@ -98,6 +121,8 @@ uninstall:
admin_jumpbox_vm_sku: ${ bundle.parameters.admin_jumpbox_vm_sku }
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
image: ${ bundle.parameters.os_image }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
Expand Down
10 changes: 10 additions & 0 deletions templates/shared_services/admin-vm/template_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"description": "Provides VM in the core network",
"required": [],
"properties": {
"os_image": {
"$id": "#/properties/os_image",
"type": "string",
"title": "Windows image",
"description": "Select Windows image to use for VM",
"enum": [
"Windows 11"
],
"default": "Windows 11"
},
"admin_jumpbox_vm_sku": {
"$id": "#/properties/admin_jumpbox_vm_sku",
"type": "string",
Expand Down
15 changes: 10 additions & 5 deletions templates/shared_services/admin-vm/terraform/admin-jumpbox.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ resource "azurerm_windows_virtual_machine" "jumpbox" {
admin_password = random_password.password.result
tags = local.tre_shared_service_tags

source_image_reference {
publisher = "MicrosoftWindowsDesktop"
offer = "windows-11"
sku = "win11-24h2-pro"
version = "latest"
# set source_image_id/reference depending on the config for the selected image
source_image_id = local.selected_image_source_id
dynamic "source_image_reference" {
for_each = local.selected_image_source_refs
content {
publisher = source_image_reference.value["publisher"]
offer = source_image_reference.value["offer"]
sku = source_image_reference.value["sku"]
version = source_image_reference.value["version"]
}
}

os_disk {
Expand Down
10 changes: 10 additions & 0 deletions templates/shared_services/admin-vm/terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ locals {
}
cmk_name = "tre-encryption-${var.tre_id}"
encryption_identity_name = "id-encryption-${var.tre_id}"

# Load image details from porter.yaml
porter_yaml = yamldecode(file("${path.module}/../porter.yaml"))
image_details = local.porter_yaml["custom"]["image_options"]

# Create local variables to support the VM resource
selected_image = local.image_details[var.image]
# selected_image_source_refs is an array to enable easy use of a dynamic block
selected_image_source_refs = lookup(local.selected_image, "source_image_reference", null) == null ? [] : [local.selected_image.source_image_reference]
selected_image_source_id = lookup(local.selected_image, "source_image_name", null) == null ? null : "${var.image_gallery_id}/images/${local.selected_image.source_image_name}"
}
9 changes: 9 additions & 0 deletions templates/shared_services/admin-vm/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ variable "enable_cmk_encryption" {
variable "key_store_id" {
type = string
}

variable "image_gallery_id" {
type = string
default = ""
}

variable "image" {
type = string
}

0 comments on commit f3ede8c

Please sign in to comment.