Skip to content

Commit ccd2e88

Browse files
authored
Merge pull request #1 from cloudmaniac/json-to-hcl
Switching from json to hcl
2 parents a30121a + 270da8d commit ccd2e88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1337
-526
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
DESCRIPTION:
3+
VMware vSphere variables used for all builds.
4+
- Variables are use by the source blocks.
5+
*/
6+
7+
// vSphere Credentials
8+
vsphere_vcenter = "vcsa01-z67.sddc.lab"
9+
vsphere_username = "administrator@vsphere.local"
10+
vsphere_password = "VMware1!"
11+
vsphere_insecure_connection = true
12+
13+
// vSphere Deployment Settings
14+
vsphere_datacenter = "Z67-DC01"
15+
vsphere_cluster = "Z67-CL01"
16+
vsphere_datastore = "nfs01"
17+
vsphere_network = "PG-10.67.10.0"

builds/common.pkrvars.hcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
DESCRIPTION: Common variables used for all builds.
3+
*/
4+
5+
// Template Account Credentials
6+
guest_root = "root" // "Only used in specific distribution (e.g., for Photon)"
7+
guest_username = "packer"
8+
guest_password = "VMware1!"
9+
guest_password_encrypted = "$6$yRp1sC9EfcWC6bg$JLJ8y/UPg6EQsyjIck78qvO6/TdA8wnzeiBPyICI2jwWtU0.sYEpyY4fSxmbVAeB74zgPdVECE/aeW4alye2X0"
10+
//var_guest_key = ""

photon/http/photon-kickstart.json renamed to builds/photon/3.0/data/photon-kickstart.pkrtpl.hcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"hostname": "packer-photon",
33
"password":
44
{
5-
"crypted": false,
6-
"text": "VMware1!"
5+
"crypted": true,
6+
"text": "${guest_password_encrypted}"
77
},
88
"disk": "/dev/sda",
9-
"packages": ["minimal", "linux", "initramfs"],
9+
"packages": ["minimal", "linux", "initramfs", "vim"],
1010
"postinstall": [
1111
"#!/bin/sh",
1212
"sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
DESCRIPTION: Photon OS 3.0 variables values.
3+
*/
4+
5+
// Operating System
6+
os_name = "Photon OS 3.0 Revision 3 Update1"
7+
iso_url = ["https://packages.vmware.com/photon/3.0/Rev3/iso/Update1/photon-minimal-3.0-913b49438.iso"]
8+
iso_checksum = "e97c2fdf27043194730a12af4b0df0067e567aac1ddfbefd11f565b5d3c65744"
9+
iso_checksum_type = "sha256"
10+
11+
// Virtual Machine Settings
12+
vm_guestos = "vmwarePhoton64Guest"
13+
vm_name = "packer-photon-3.0"
14+
vm_cpu_size = 1
15+
vm_ram_size = 1024
16+
vm_disk_controller = ["pvscsi"]
17+
vm_disk_size = 20480
18+
19+
// Deployment Settings
20+
vsphere_template_folder = "templates/packer/photon"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
DESCRIPTION: Photon OS 3.0 vSphere template.
3+
- Author: Romain Decker
4+
- Blog: https://cloudmaniac.net
5+
- Twitter: https://twitter.com/woueb
6+
- Build command: packer build -force -var-file="../../clouds/infra-z67.pkrvars.hcl" -var-file="../../common.pkrvars.hcl" .
7+
*/
8+
9+
// Packer
10+
packer {
11+
required_version = ">= 1.8.5"
12+
required_plugins {
13+
vsphere = {
14+
version = ">= v1.1.1"
15+
source = "github.com/hashicorp/vsphere"
16+
}
17+
}
18+
}
19+
20+
// Data
21+
locals {
22+
build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
23+
vm_notes = "OS: ${var.os_name} (build on: ${local.build_date})"
24+
data_source_content = {
25+
"/photon-kickstart.json" = templatefile("${abspath(path.root)}/data/photon-kickstart.pkrtpl.hcl", {
26+
guest_username = var.guest_username
27+
guest_password = var.guest_password
28+
guest_password_encrypted = var.guest_password_encrypted
29+
})
30+
}
31+
}
32+
33+
// Source
34+
source "vsphere-iso" "photon" {
35+
36+
// Endpoint
37+
vcenter_server = var.vsphere_vcenter
38+
username = var.vsphere_username
39+
password = var.vsphere_password
40+
insecure_connection = var.vsphere_insecure_connection
41+
42+
datacenter = var.vsphere_datacenter
43+
cluster = var.vsphere_cluster
44+
folder = var.vsphere_template_folder
45+
datastore = var.vsphere_datastore
46+
47+
// Virtual Machine Settings
48+
vm_name = var.vm_name
49+
guest_os_type = var.vm_guestos
50+
CPUs = var.vm_cpu_size
51+
RAM = var.vm_ram_size
52+
53+
disk_controller_type = var.vm_disk_controller
54+
55+
storage {
56+
disk_size = var.vm_disk_size
57+
disk_thin_provisioned = true
58+
}
59+
60+
network_adapters {
61+
network = var.vsphere_network
62+
network_card = "vmxnet3"
63+
}
64+
65+
vm_version = 15
66+
notes = local.vm_notes
67+
68+
// Operating System & Boot
69+
iso_urls = var.iso_url
70+
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum}"
71+
http_content = local.data_source_content
72+
73+
boot_command = ["<esc><wait>", "vmlinuz initrd=initrd.img root=/dev/ram0 loglevel=3 ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/photon-kickstart.json photon.media=cdrom", "<enter>"]
74+
boot_wait = "5s"
75+
76+
shutdown_command = "shutdown -h now"
77+
78+
// Communicator
79+
communicator = "ssh"
80+
81+
ssh_username = var.guest_root
82+
ssh_password = var.guest_password
83+
ssh_timeout = "30m"
84+
85+
// Output
86+
convert_to_template = "true"
87+
}
88+
89+
// Build
90+
build {
91+
sources = ["source.vsphere-iso.photon"]
92+
93+
provisioner "shell" {
94+
scripts = ["../scripts/update.sh", "../scripts/cleanup.sh"]
95+
}
96+
97+
provisioner "shell" {
98+
inline = ["echo 'Template build complete (${local.build_date})!'"]
99+
}
100+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
DESCRIPTION: Photon OS 3.0 variables definition.
3+
*/
4+
5+
// vSphere Credentials
6+
variable "vsphere_vcenter" {
7+
type = string
8+
description = "vSphere server instance FQDN or IP (e.g., 'vcsa01-z67.sddc.lab')."
9+
}
10+
11+
variable "vsphere_username" {
12+
type = string
13+
description = "Username to connect to the vCenter server instance."
14+
}
15+
16+
variable "vsphere_password" {
17+
type = string
18+
description = "The password of the vSphere account used to connect to the vCenter instance."
19+
}
20+
21+
variable "vsphere_insecure_connection" {
22+
type = bool
23+
description = "Do not validate the vCenter Server TLS certificate."
24+
default = false
25+
}
26+
27+
28+
// Template Account Credentials
29+
variable "guest_root" {
30+
type = string
31+
description = "The 'root' username for the guest operating system."
32+
}
33+
34+
variable "guest_username" {
35+
type = string
36+
description = "The username for the guest operating system."
37+
}
38+
39+
variable "guest_password" {
40+
type = string
41+
description = "The password to login to the guest operating system."
42+
}
43+
44+
variable "guest_password_encrypted" {
45+
type = string
46+
description = "The encrypted password to login to the guest operating system."
47+
}
48+
49+
50+
// vSphere Deployment Settings
51+
variable "vsphere_datacenter" {
52+
type = string
53+
description = "The name of the target vSphere datacenter where to deploy the template."
54+
}
55+
56+
variable "vsphere_cluster" {
57+
type = string
58+
description = "The name of the target vSphere cluster where to deploy the template."
59+
}
60+
61+
variable "vsphere_datastore" {
62+
type = string
63+
description = "The name of the target datastore where to deploy the template."
64+
}
65+
66+
variable "vsphere_network" {
67+
type = string
68+
description = "The name of the target network to connect the template."
69+
}
70+
71+
72+
// Operating System
73+
variable "os_name" {
74+
type = string
75+
description = "Name and version of the guest operating system."
76+
}
77+
78+
variable "iso_url" {
79+
type = list(string)
80+
description = "URL(s) for the ISO to download. If multiple URLs are provided, Packer will try these in order. If anything goes wrong attempting to download or while downloading a single URL, it will move on to the next. All URLs must point to the same file (same checksum)."
81+
}
82+
83+
variable "iso_checksum" {
84+
type = string
85+
description = "The checksum for the ISO file."
86+
}
87+
88+
89+
variable "iso_checksum_type" {
90+
type = string
91+
description = "The type of the checksum for the ISO file checksum."
92+
}
93+
94+
95+
// Virtual Machine Settings
96+
variable "vm_guestos" {
97+
type = string
98+
description = "Guest operating system identifier for vSphere, also known as guestid (e.g., 'ubuntu64Guest')."
99+
}
100+
101+
variable "vm_name" {
102+
type = string
103+
description = "Name of the new VM to create."
104+
}
105+
106+
variable "vm_cpu_size" {
107+
type = number
108+
description = "Number of CPU cores."
109+
default = 1
110+
}
111+
112+
variable "vm_ram_size" {
113+
type = number
114+
description = "Amount of RAM in MB."
115+
}
116+
117+
variable "vm_disk_controller" {
118+
type = list(string)
119+
description = "VM disk controller type(s) in sequence (e.g. 'pvscsi' or 'lsilogic')"
120+
default = ["pvscsi"]
121+
}
122+
123+
variable "vm_disk_size" {
124+
type = number
125+
description = "The size of the disk in MB."
126+
}
127+
128+
// Deployment Settings
129+
variable "vsphere_template_folder" {
130+
type = string
131+
description = "The name of the target vSphere folder where to deploy the template."
132+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hostname": "packer-photon",
3+
"password":
4+
{
5+
"crypted": true,
6+
"text": "${guest_password_encrypted}"
7+
},
8+
"disk": "/dev/sda",
9+
"packages": ["minimal", "linux", "initramfs", "vim"],
10+
"postinstall": [
11+
"#!/bin/sh",
12+
"sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config",
13+
"systemctl restart sshd.service"
14+
]
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
DESCRIPTION: Photon OS 4.0 variables values.
3+
*/
4+
5+
// Operating System
6+
os_name = "Photon OS 4.0 Rev 2"
7+
iso_url = ["https://packages.vmware.com/photon/4.0/Rev2/iso/photon-minimal-4.0-c001795b8.iso"]
8+
iso_checksum = "c6a5de1098228728b5d189854f387e6fe6edb87582be4d9a4568ae0405929383"
9+
iso_checksum_type = "sha256"
10+
11+
// Virtual Machine Settings
12+
vm_guestos = "vmwarePhoton64Guest"
13+
vm_name = "packer-photon-4.0"
14+
vm_cpu_size = 1
15+
vm_ram_size = 1024
16+
vm_disk_controller = ["pvscsi"]
17+
vm_disk_size = 20480
18+
19+
// Deployment Settings
20+
vsphere_template_folder = "templates/packer/photon"

0 commit comments

Comments
 (0)