add in HCL support (#593) · boyter/scc@a05a76a

1+

#!/usr/bin/env packer build --force

2+

#

3+

# Author: Hari Sekhon

4+

# Date: 2023-06-13 02:46:59 +0100 (Tue, 13 Jun 2023)

5+

#

6+

# vim:ts=2:sts=2:sw=2:et:filetype=conf

7+

#

8+

# https://github.com/HariSekhon/Templates

9+

#

10+

# License: see accompanying Hari Sekhon LICENSE file

11+

#

12+

# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish

13+

#

14+

# https://www.linkedin.com/in/HariSekhon

15+

#

16+17+

# Uses adjacent Debian Preseed from installers/

18+

#

19+

# 'packer' command must be run from the same directory as this file so the preseed.cfg provided is auto-served via HTTP

20+21+

# ============================================================================ #

22+

# P a c k e r - F e d o r a - Q e m u

23+

# ============================================================================ #

24+25+

packer {

26+

# Data sources only available in 1.7+

27+

required_version = ">= 1.7.0, < 2.0.0"

28+

required_plugins {

29+

qemu = {

30+

version = "~> 1.1"

31+

source = "github.com/hashicorp/qemu"

32+

}

33+

}

34+

}

35+36+

# https://alt.fedoraproject.org/alt/

37+

variable "version" {

38+

type = string

39+

default = "38"

40+

}

41+42+

variable "iso" {

43+

type = string

44+

default = "Fedora-Server-dvd-x86_64-38-1.6.iso"

45+

}

46+47+

variable "checksum" {

48+

type = string

49+

default = "09dee2cd626a269aefc67b69e63a30bd0baa52d4"

50+

}

51+

locals {

52+

name = "fedora"

53+

url = "https://download.fedoraproject.org/pub/fedora/linux/releases/${var.version}/Server/x86_64/iso/${var.iso}"

54+

vm_name = "${local.name}-${var.version}"

55+

arch = "x86_64"

56+

}

57+58+

# https://developer.hashicorp.com/packer/plugins/builders/qemu

59+

source "qemu" "fedora" {

60+

vm_name = local.vm_name

61+

qemu_binary = "qemu-system-x86_64"

62+

machine_type = "pc"

63+

iso_url = local.url

64+

iso_checksum = var.checksum

65+

cpus = 2

66+

memory = 2048

67+

net_device = "virtio-net"

68+

disk_interface = "virtio-scsi" # or virtio?

69+

format = "qcow2"

70+

disk_discard = "unmap"

71+

disk_image = true

72+

disk_size = 40960

73+

disk_additional_size = []

74+

output_directory = "output-${local.vm_name}-${local.arch}"

75+

headless = false

76+

use_default_display = true # might be needed on Mac to avoid errors about sdl not being available

77+

http_directory = "installers"

78+

ssh_timeout = "30m"

79+

ssh_password = "packer"

80+

ssh_username = "packer"

81+

shutdown_command = "echo 'packer' | sudo -S shutdown -P now"

82+

boot_wait = "5s"

83+

boot_command = [

84+

"<up><wait>",

85+

"e",

86+

"<down><down><down><left>",

87+

# leave a space from last arg

88+

" inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/anaconda-ks.cfg <f10>"

89+

]

90+

qemuargs = [

91+

#["-smbios", "type=1,serial=ds=nocloud-net;instance-id=packer;seedfrom=http://{{ .HTTPIP }}:{{ .HTTPPort }}/"],

92+

# spice-app isn't respected despite doc https://www.qemu.org/docs/master/system/invocation.html#hxtool-3

93+

# packer-builder-qemu plugin: Qemu stderr: qemu-system-x86_64: -display spice-app: Parameter 'type' does not accept value 'spice-app'

94+

#["-display", "spice-app"],

95+

#["-display", "cocoa"], # Mac only

96+

#["-display", "vnc:0"], # starts VNC by default, but doesn't launch user's vncviewer - ubuntu-x86_64.qemu.pkr.hcl

97+

]

98+

# Only on ARM Macs

99+

#machine_type = "virt" # packer-builder-qemu plugin: Qemu stderr: qemu-system-x86_64: unsupported machine type

100+

}

101+102+103+

build {

104+

name = local.name

105+106+

sources = ["source.qemu.fedora"]

107+108+

# https://developer.hashicorp.com/packer/docs/provisioners/shell-local

109+

#

110+

#provisioner "shell-local" {

111+

# environment_vars = [

112+

# "VM_NAME=${local.vm_name}"

113+

# ]

114+

# script = "./scripts/local_vboxsf.sh"

115+

#}

116+117+

# https://developer.hashicorp.com/packer/docs/provisioners/shell

118+

#

119+

provisioner "shell" {

120+

scripts = [

121+

"./scripts/version.sh",

122+

#"./scripts/mount_vboxsf.sh",

123+

#"./scripts/collect_anaconda.sh",

124+

"./scripts/final.sh",

125+

]

126+

execute_command = "{{ .Vars }} echo 'packer' | sudo -S -E bash '{{ .Path }}' '${packer.version}'"

127+

}

128+129+

post-processor "checksum" {

130+

checksum_types = ["md5", "sha512"]

131+

keep_input_artifact = true

132+

output = "output-{{.BuildName}}/{{.BuildName}}.{{.ChecksumType}}"

133+

}

134+

}