Skip to content

Commit

Permalink
feat: enable content library (#861)
Browse files Browse the repository at this point in the history
- Adds option to enable a content library to source all guest operating system ISOs or use a datastore path. Defaults to `false`, disabled.

  Set `common_iso_content_library_enabled` to `true` to enable use of a content library for all guest operating system ISOs.

- Adds option to enable a content library for the placement of virtual machine images builds. Defaults to `true`, enabled.

  Set `common_content_library_enabled` to `false` to disable use of a content library for saving virtual machine image builds.
  • Loading branch information
tenthirtyam committed Apr 4, 2024
1 parent f92b70a commit d23da87
Show file tree
Hide file tree
Showing 87 changed files with 1,743 additions and 875 deletions.
685 changes: 448 additions & 237 deletions CHANGELOG.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions builds/common.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ common_remove_cdrom = true

// Template and Content Library Settings
common_template_conversion = false
common_content_library_name = "sfo-w01-lib01"
common_content_library = "sfo-w01-lib01"
common_content_library_enabled = true
common_content_library_ovf = true
common_content_library_destroy = true
common_content_library_skip_export = false
Expand All @@ -24,7 +25,9 @@ common_ovf_export_enabled = false
common_ovf_export_overwrite = true

// Removable Media Settings
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"
common_iso_datastore = "sfo-w01-cl01-ds-nfs01"
common_iso_content_library = "sfo-w01-lib01"
common_iso_content_library_enabled = false

// Boot and Provisioning Settings
common_data_source = "http"
Expand Down
21 changes: 12 additions & 9 deletions builds/linux/almalinux/8/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ locals {
build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
build_version = data.git-repository.cwd.head
build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}"
iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"]
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
iso_paths = {
content_library = "${var.common_iso_content_library}/${var.iso_content_library_item}/${var.iso_file}",
datastore = "[${var.common_iso_datastore}] ${var.iso_datastore_path}/${var.iso_file}"
}
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -121,7 +124,7 @@ source "vsphere-iso" "linux-almalinux" {
notes = local.build_description

// Removable Media Settings
iso_paths = local.iso_paths
iso_paths = var.common_iso_content_library_enabled ? [local.iso_paths.content_library] : [local.iso_paths.datastore]
http_content = var.common_data_source == "http" ? local.data_source_content : null
cd_content = var.common_data_source == "disk" ? local.data_source_content : null

Expand Down Expand Up @@ -163,9 +166,9 @@ source "vsphere-iso" "linux-almalinux" {
// Template and Content Library Settings
convert_to_template = var.common_template_conversion
dynamic "content_library_destination" {
for_each = var.common_content_library_name != null ? [1] : []
for_each = var.common_content_library_enabled ? [1] : []
content {
library = var.common_content_library_name
library = var.common_content_library
description = local.build_description
ovf = var.common_content_library_ovf
destroy = var.common_content_library_destroy
Expand All @@ -175,7 +178,7 @@ source "vsphere-iso" "linux-almalinux" {

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
for_each = var.common_ovf_export_enabled ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/almalinux/8/linux-almalinux.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ vm_disk_thin_provisioned = true
vm_network_card = "vmxnet3"

// Removable Media Settings
iso_path = "iso/linux/almalinux"
iso_file = "AlmaLinux-8.9-x86_64-dvd.iso"
iso_datastore_path = "iso/linux/almalinux"
iso_content_library_item = "AlmaLinux-8.9-x86_64-dvd"
iso_file = "AlmaLinux-8.9-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
29 changes: 23 additions & 6 deletions builds/linux/almalinux/8/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ variable "common_template_conversion" {
default = false
}

variable "common_content_library_name" {
variable "common_content_library_enabled" {
type = bool
description = "Import the virtual machine into the vSphere content library."
default = true
}

variable "common_content_library" {
type = string
description = "The name of the target vSphere content library, if used."
description = "The name of the target vSphere content library, if enabled."
default = null
}

Expand Down Expand Up @@ -254,21 +260,32 @@ variable "common_ovf_export_overwrite" {

// Removable Media Settings

variable "common_iso_datastore" {
variable "common_iso_content_library_enabled" {
type = bool
description = "Import the guest operating system ISO into the vSphere content library."
default = false
}

variable "common_iso_content_library" {
type = string
description = "The name of the source vSphere datastore for the guest operating system ISO."
description = "The name of the target vSphere content library for the guest operating system ISO."
}

variable "iso_path" {
variable "common_iso_datastore" {
type = string
description = "The path on the source vSphere datastore for the guest operating system ISO."
description = "The name of the target vSphere datastore for the guest operating system ISO."
}

variable "iso_file" {
type = string
description = "The file name of the guest operating system ISO."
}

variable "iso_content_library_item" {
type = string
description = "The vSphere content library item name for the guest operating system ISO."
}

// Boot Settings

variable "common_data_source" {
Expand Down
21 changes: 12 additions & 9 deletions builds/linux/almalinux/9/linux-almalinux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ locals {
build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
build_version = data.git-repository.cwd.head
build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}"
iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"]
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
iso_paths = {
content_library = "${var.common_iso_content_library}/${var.iso_content_library_item}/${var.iso_file}",
datastore = "[${var.common_iso_datastore}] ${var.iso_datastore_path}/${var.iso_file}"
}
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -121,7 +124,7 @@ source "vsphere-iso" "linux-almalinux" {
notes = local.build_description

// Removable Media Settings
iso_paths = local.iso_paths
iso_paths = var.common_iso_content_library_enabled ? [local.iso_paths.content_library] : [local.iso_paths.datastore]
http_content = var.common_data_source == "http" ? local.data_source_content : null
cd_content = var.common_data_source == "disk" ? local.data_source_content : null

Expand Down Expand Up @@ -163,9 +166,9 @@ source "vsphere-iso" "linux-almalinux" {
// Template and Content Library Settings
convert_to_template = var.common_template_conversion
dynamic "content_library_destination" {
for_each = var.common_content_library_name != null ? [1] : []
for_each = var.common_content_library_enabled ? [1] : []
content {
library = var.common_content_library_name
library = var.common_content_library
description = local.build_description
ovf = var.common_content_library_ovf
destroy = var.common_content_library_destroy
Expand All @@ -175,7 +178,7 @@ source "vsphere-iso" "linux-almalinux" {

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
for_each = var.common_ovf_export_enabled ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/almalinux/9/linux-almalinux.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ vm_disk_thin_provisioned = true
vm_network_card = "vmxnet3"

// Removable Media Settings
iso_path = "iso/linux/almalinux"
iso_file = "AlmaLinux-9.3-x86_64-dvd.iso"
iso_datastore_path = "iso/linux/almalinux"
iso_content_library_item = "AlmaLinux-9.3-x86_64-dvd"
iso_file = "AlmaLinux-9.3-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
30 changes: 26 additions & 4 deletions builds/linux/almalinux/9/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ variable "common_template_conversion" {
default = false
}

variable "common_content_library_name" {
variable "common_content_library_enabled" {
type = bool
description = "Import the virtual machine into the vSphere content library."
default = true
}

variable "common_content_library" {
type = string
description = "The name of the target vSphere content library, if used."
description = "The name of the target vSphere content library, if enabled."
default = null
}

Expand Down Expand Up @@ -254,12 +260,23 @@ variable "common_ovf_export_overwrite" {

// Removable Media Settings

variable "common_iso_content_library_enabled" {
type = bool
description = "Import the guest operating system ISO into the vSphere content library."
default = false
}

variable "common_iso_content_library" {
type = string
description = "The name of the target vSphere content library for the guest operating system ISO."
}

variable "common_iso_datastore" {
type = string
description = "The name of the source vSphere datastore for the guest operating system ISO."
description = "The name of the target vSphere datastore for the guest operating system ISO."
}

variable "iso_path" {
variable "iso_datastore_path" {
type = string
description = "The path on the source vSphere datastore for the guest operating system ISO."
}
Expand All @@ -269,6 +286,11 @@ variable "iso_file" {
description = "The file name of the guest operating system ISO."
}

variable "iso_content_library_item" {
type = string
description = "The vSphere content library item name for the guest operating system ISO."
}

// Boot Settings

variable "common_data_source" {
Expand Down
21 changes: 12 additions & 9 deletions builds/linux/centos/7/linux-centos.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ locals {
build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
build_version = data.git-repository.cwd.head
build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}"
iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"]
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
iso_paths = {
content_library = "${var.common_iso_content_library}/${var.iso_content_library_item}/${var.iso_file}",
datastore = "[${var.common_iso_datastore}] ${var.iso_datastore_path}/${var.iso_file}"
}
manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp())
manifest_path = "${path.cwd}/manifests/"
manifest_output = "${local.manifest_path}${local.manifest_date}.json"
ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}"
data_source_content = {
"/ks.cfg" = templatefile("${abspath(path.root)}/data/ks.pkrtpl.hcl", {
build_username = var.build_username
Expand Down Expand Up @@ -121,7 +124,7 @@ source "vsphere-iso" "linux-centos" {
notes = local.build_description

// Removable Media Settings
iso_paths = local.iso_paths
iso_paths = var.common_iso_content_library_enabled ? [local.iso_paths.content_library] : [local.iso_paths.datastore]
http_content = var.common_data_source == "http" ? local.data_source_content : null
cd_content = var.common_data_source == "disk" ? local.data_source_content : null

Expand Down Expand Up @@ -163,9 +166,9 @@ source "vsphere-iso" "linux-centos" {
// Template and Content Library Settings
convert_to_template = var.common_template_conversion
dynamic "content_library_destination" {
for_each = var.common_content_library_name != null ? [1] : []
for_each = var.common_content_library_enabled ? [1] : []
content {
library = var.common_content_library_name
library = var.common_content_library
description = local.build_description
ovf = var.common_content_library_ovf
destroy = var.common_content_library_destroy
Expand All @@ -175,7 +178,7 @@ source "vsphere-iso" "linux-centos" {

// OVF Export Settings
dynamic "export" {
for_each = var.common_ovf_export_enabled == true ? [1] : []
for_each = var.common_ovf_export_enabled ? [1] : []
content {
name = local.vm_name
force = var.common_ovf_export_overwrite
Expand Down
5 changes: 3 additions & 2 deletions builds/linux/centos/7/linux-centos.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ vm_disk_thin_provisioned = true
vm_network_card = "vmxnet3"

// Removable Media Settings
iso_path = "iso/linux/centos"
iso_file = "CentOS-7-x86_64-DVD-2009.iso"
iso_datastore_path = "iso/linux/centos"
iso_content_library_item = "CentOS-7-x86_64-DVD-2009"
iso_file = "CentOS-7-x86_64-DVD-2009.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
30 changes: 26 additions & 4 deletions builds/linux/centos/7/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ variable "common_template_conversion" {
default = false
}

variable "common_content_library_name" {
variable "common_content_library_enabled" {
type = bool
description = "Import the virtual machine into the vSphere content library."
default = true
}

variable "common_content_library" {
type = string
description = "The name of the target vSphere content library, if used."
description = "The name of the target vSphere content library, if enabled."
default = null
}

Expand Down Expand Up @@ -254,12 +260,23 @@ variable "common_ovf_export_overwrite" {

// Removable Media Settings

variable "common_iso_content_library_enabled" {
type = bool
description = "Import the guest operating system ISO into the vSphere content library."
default = false
}

variable "common_iso_content_library" {
type = string
description = "The name of the target vSphere content library for the guest operating system ISO."
}

variable "common_iso_datastore" {
type = string
description = "The name of the source vSphere datastore for the guest operating system ISO."
description = "The name of the target vSphere datastore for the guest operating system ISO."
}

variable "iso_path" {
variable "iso_datastore_path" {
type = string
description = "The path on the source vSphere datastore for the guest operating system ISO."
}
Expand All @@ -269,6 +286,11 @@ variable "iso_file" {
description = "The file name of the guest operating system ISO."
}

variable "iso_content_library_item" {
type = string
description = "The vSphere content library item name for the guest operating system ISO."
}

// Boot Settings

variable "common_data_source" {
Expand Down
Loading

0 comments on commit d23da87

Please sign in to comment.