Skip to content

Commit f21b533

Browse files
authored
Merge pull request #127 from laurentpellegrino/packer-configurable-instance-location-type
Make packer build instance location and type configurable
2 parents 9c27ce6 + 9006018 commit f21b533

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

image.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ resource "terraform_data" "amd64_image" {
149149
"${length(data.hcloud_images.amd64[0].images) > 0} ||",
150150
"packer build -force",
151151
"-var 'cluster_name=${var.cluster_name}'",
152+
"-var 'server_type=${var.packer_amd64_builder.server_type}'",
153+
"-var 'server_location=${var.packer_amd64_builder.server_location}'",
152154
"-var 'talos_version=${var.talos_version}'",
153155
"-var 'talos_schematic_id=${local.talos_schematic_id}'",
154156
"-var 'talos_image_url=${local.talos_amd64_image_url}'",
@@ -181,6 +183,8 @@ resource "terraform_data" "arm64_image" {
181183
"${length(data.hcloud_images.arm64[0].images) > 0} ||",
182184
"packer build -force",
183185
"-var 'cluster_name=${var.cluster_name}'",
186+
"-var 'server_type=${var.packer_arm64_builder.server_type}'",
187+
"-var 'server_location=${var.packer_arm64_builder.server_location}'",
184188
"-var 'talos_version=${var.talos_version}'",
185189
"-var 'talos_schematic_id=${local.talos_schematic_id}'",
186190
"-var 'talos_image_url=${local.talos_arm64_image_url}'",

packer/image_amd64.pkr.hcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ variable "talos_image_url" {
1919
type = string
2020
}
2121

22+
variable "server_type" {
23+
type = string
24+
default = "cpx11"
25+
}
26+
2227
# Source for the Talos AMD64 image
2328
source "hcloud" "amd64_builder" {
2429
rescue = "linux64"
2530
image = "debian-12"
2631
location = var.server_location
27-
server_type = "cpx11"
32+
server_type = var.server_type
2833
ssh_username = "root"
2934

3035
snapshot_name = "Talos Linux AMD64 for ${var.cluster_name}"

packer/image_arm64.pkr.hcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ variable "talos_image_url" {
1919
type = string
2020
}
2121

22+
variable "server_type" {
23+
type = string
24+
default = "cax11"
25+
}
26+
2227
# Source for the Talos ARM64 image
2328
source "hcloud" "arm64_builder" {
2429
rescue = "linux64"
2530
image = "debian-12"
2631
location = var.server_location
27-
server_type = "cax11"
32+
server_type = var.server_type
2833
ssh_username = "root"
2934

3035
snapshot_name = "Talos Linux ARM64 for ${var.cluster_name}"

variables.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,39 @@ variable "cluster_autoscaler_config_patches" {
489489
description = "List of configuration patches applied to the Cluster Autoscaler nodes."
490490
}
491491

492+
# Packer
493+
494+
variable "packer_amd64_builder" {
495+
type = object({
496+
server_type = optional(string, "cpx11")
497+
server_location = optional(string, "fsn1")
498+
})
499+
default = {}
500+
description = "Configuration for the server used when building the Talos AMD64 image with Packer."
501+
502+
validation {
503+
condition = contains([
504+
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
505+
], var.packer_amd64_builder.server_location)
506+
error_message = "The server_location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
507+
}
508+
}
509+
510+
variable "packer_arm64_builder" {
511+
type = object({
512+
server_type = optional(string, "cax11")
513+
server_location = optional(string, "fsn1")
514+
})
515+
default = {}
516+
description = "Configuration for the server used when building the Talos ARM64 image with Packer."
517+
518+
validation {
519+
condition = contains([
520+
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
521+
], var.packer_arm64_builder.server_location)
522+
error_message = "The server_location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
523+
}
524+
}
492525

493526
# Talos
494527
variable "talos_version" {

0 commit comments

Comments
 (0)