Use packer.io to upload base os-image

This commit is contained in:
Serge Logvinov
2021-07-13 14:14:18 +03:00
parent 5d435bcc6a
commit 954f6ac376
4 changed files with 55 additions and 3 deletions

3
.gitignore vendored
View File

@@ -9,6 +9,9 @@
*.tfstate
*.tfstate.*
# packer files
.auto.pkrvars.hcl
# Crash log files
crash.log

View File

@@ -3,8 +3,10 @@ data "hcloud_image" "talos" {
with_selector = "type=infra"
}
data "hcloud_ssh_key" "infra" {
with_selector = "type=infra"
resource "hcloud_ssh_key" "infra" {
name = "infra"
public_key = file("~/.ssh/terraform.pub")
labels = merge(var.tags, { type = "infra" })
}
# resource "talos_cluster_config" "talos_config" {

View File

@@ -5,7 +5,7 @@ resource "hcloud_server" "controlplane" {
name = "master-${count.index + 1}"
image = data.hcloud_image.talos.id
server_type = lookup(var.controlplane, "type", "cpx11")
ssh_keys = [data.hcloud_ssh_key.infra.id]
ssh_keys = [hcloud_ssh_key.infra.id]
keep_disk = true
labels = merge(var.tags, { type = "infra", label = "master" })

View File

@@ -0,0 +1,47 @@
packer {
required_plugins {
docker = {
version = ">= 1.0.0"
source = "github.com/hashicorp/hcloud"
}
}
}
variable "hcloud_token" {
type = string
default = "${env("HCLOUD_TOKEN")}"
sensitive = true
}
variable "talos_version" {
type = string
default = "v0.11.0"
}
source "hcloud" "talos" {
token = var.hcloud_token
rescue = "linux64"
image = "debian-10"
location = "hel1"
server_type = "cx11"
ssh_username = "root"
snapshot_name = "talos system disk"
snapshot_labels = {
type = "infra",
os = "talos",
version = "${var.talos_version}",
}
}
build {
sources = ["source.hcloud.talos"]
provisioner "shell" {
inline = [
"apt-get install -y wget",
"wget -O /tmp/openstack.tar.gz https://github.com/talos-systems/talos/releases/download/${var.talos_version}/openstack-amd64.tar.gz",
"cd /tmp && tar xzf /tmp/openstack.tar.gz && dd if=/tmp/disk.raw of=/dev/sda && sync",
]
}
}