|
| 1 | +packer { |
| 2 | + required_plugins { |
| 3 | + xenserver= { |
| 4 | + version = ">= v0.9.0" |
| 5 | + source = "github.com/vatesfr/xenserver" |
| 6 | + } |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +data "null" "version" { |
| 11 | + input = "3.23.2" |
| 12 | +} |
| 13 | + |
| 14 | +locals { |
| 15 | + timestamp = regex_replace(timestamp(), "[- TZ:]", "") |
| 16 | + version = data.null.version.output |
| 17 | + sha256_version = regex_replace(local.version, "\\.[0-9]+$", "") |
| 18 | + |
| 19 | + template_name = { |
| 20 | + latest = "NHT Alpine" |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +# local "sha256" { |
| 26 | +# expression = regex("^([a-f0-9]+)", data.http.sha256.body) |
| 27 | +# } |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +# Fetch Alpine ISO SHA256 |
| 32 | +# data "http" "sha256" { |
| 33 | +# url = "https://dl-cdn.alpinelinux.org/alpine/v${local.version}/releases/x86_64/alpine-virt-${local.version}.iso.sha256" |
| 34 | +# } |
| 35 | + |
| 36 | + |
| 37 | +variable "remote_host" { |
| 38 | + type = string |
| 39 | + description = "The ip or fqdn of your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_HOST'" |
| 40 | + sensitive = true |
| 41 | + default = null |
| 42 | +} |
| 43 | + |
| 44 | +variable "remote_password" { |
| 45 | + type = string |
| 46 | + description = "The password used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_PASSWORD'" |
| 47 | + sensitive = true |
| 48 | + default = null |
| 49 | +} |
| 50 | + |
| 51 | +variable "remote_username" { |
| 52 | + type = string |
| 53 | + description = "The username used to interact with your XenServer. This will be pulled from the env var 'PKR_VAR_XAPI_USERNAME'" |
| 54 | + sensitive = true |
| 55 | + default = null |
| 56 | +} |
| 57 | + |
| 58 | +variable "sr_iso_name" { |
| 59 | + type = string |
| 60 | + default = "" |
| 61 | + description = "The ISO-SR to packer will use" |
| 62 | +} |
| 63 | + |
| 64 | +variable "sr_name" { |
| 65 | + type = string |
| 66 | + default = "" |
| 67 | + description = "The name of the SR to packer will use" |
| 68 | +} |
| 69 | + |
| 70 | +source "xenserver-iso" "alpine" { |
| 71 | + iso_checksum = "c328a553ba9861e4ccb3560d69e426256955fa954bc6f084772e6e6cd5b0a4d0" |
| 72 | + iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/x86_64/alpine-virt-3.23.2-x86_64.iso" |
| 73 | + |
| 74 | + sr_iso_name = var.sr_iso_name |
| 75 | + sr_name = var.sr_name |
| 76 | + tools_iso_name = "guest-tools.iso" |
| 77 | + |
| 78 | + remote_host = var.remote_host |
| 79 | + remote_password = var.remote_password |
| 80 | + remote_username = var.remote_username |
| 81 | + |
| 82 | + # Use the Alpine template |
| 83 | + clone_template = local.template_name["latest"] |
| 84 | + vm_name = "packer-alpine-${data.null.version.output}-${local.timestamp}" |
| 85 | + vm_description = "Build started: ${local.timestamp}" |
| 86 | + vm_memory = 4096 |
| 87 | + disk_size = 30720 |
| 88 | + |
| 89 | + ssh_username = "testuser" |
| 90 | + ssh_password = "alpine" |
| 91 | + ssh_wait_timeout = "60000s" |
| 92 | + ssh_handshake_attempts = 10000 |
| 93 | + |
| 94 | + output_directory = "packer-alpine-iso" |
| 95 | + keep_vm = "always" |
| 96 | +} |
| 97 | + |
| 98 | +build { |
| 99 | + sources = ["xenserver-iso.alpine"] |
| 100 | + # Wait for cloud-init to finish everything. We need to do this as a |
| 101 | + # packer provisioner to prevent packer-plugin-xenserver from shutting |
| 102 | + # the VM down before all cloud-init processing is complete. |
| 103 | + provisioner "shell" { |
| 104 | + inline = [ |
| 105 | + "echo alpine | sudo -S cloud-init status --wait" |
| 106 | + ] |
| 107 | + valid_exit_codes = [0, 2] |
| 108 | + } |
| 109 | +} |
0 commit comments