Skip to content

Commit

Permalink
Merge pull request #69 from ChristianLempa/7-migrate-promox-project
Browse files Browse the repository at this point in the history
deleted pull request script
  • Loading branch information
ChristianLempa authored Sep 8, 2023
2 parents 6b9eb53 + fc87b5b commit 2cfc9bf
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 33 deletions.
25 changes: 2 additions & 23 deletions .github/workflows/proxmox-update-vms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ env:

jobs:
terraform:
name: "test, plan, and apply terraform changes"

runs-on: "self-hosted"
steps:

Expand Down Expand Up @@ -58,29 +60,6 @@ jobs:
run: terraform plan -no-color -input=false
continue-on-error: true

- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
**/terraform.tfstate
**/terraform.tfstate.backup
**/*.auto.tfvars

**/*.auto.pkrvars.hcl
packer-*.log
packer_cache/
*.iso
*.box
*.ova
41 changes: 41 additions & 0 deletions proxmox/prx-prod-2/packer/pkr-ubuntu-jammy/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
build {

name = "pkr-ubuntu-jammy"
sources = [
"source.proxmox-iso.eval-1",
"source.proxmox-iso.prod-1"
]

# Waiting for Cloud-Init to finish
provisioner "shell" {
inline = ["cloud-init status --wait"]
}

# Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
provisioner "shell" {
execute_command = "echo -e '<user>' | sudo -S -E bash '{{ .Path }}'"
inline = [
"echo 'Starting Stage: Provisioning the VM Template for Cloud-Init Integration in Proxmox'",
"sudo rm /etc/ssh/ssh_host_*",
"sudo truncate -s 0 /etc/machine-id",
"sudo apt -y autoremove --purge",
"sudo apt -y clean",
"sudo apt -y autoclean",
"sudo cloud-init clean",
"sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
"sudo rm -f /etc/netplan/00-installer-config.yaml",
"sudo sync",
"echo 'Done Stage: Provisioning the VM Template for Cloud-Init Integration in Proxmox'"
]
}

# Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
provisioner "file" {
source = "pkr-ubuntu-jammy/files/99-pve.cfg"
destination = "/tmp/99-pve.cfg"
}
provisioner "shell" {
inline = ["sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg"]
}

}
29 changes: 29 additions & 0 deletions proxmox/prx-prod-2/packer/pkr-ubuntu-jammy/config.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
packer {
required_plugins {
proxmox = {
version = ">= 1.1.3"
source = "github.com/hashicorp/proxmox"
}
}
}

variable "proxmox_api_url" {
type = string
}

variable "proxmox_api_token_id" {
type = string
}

variable "proxmox_api_token_secret" {
type = string
sensitive = true
}

variable "ssh_username" {
type = string
}

variable "ssh_private_key_file" {
type = string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
datasource_list: [ConfigDrive, NoCloud]
Empty file.
42 changes: 42 additions & 0 deletions proxmox/prx-prod-2/packer/pkr-ubuntu-jammy/http/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#cloud-config
autoinstall:
version: 1
locale: en_US
refresh-installer:
update: false
keyboard:
layout: de
ssh:
install-server: true
allow-pw: true
disable_root: true
ssh_quiet_keygen: true
allow_public_ssh_keys: true
storage:
layout:
name: direct
swap:
size: 0
network:
network:
version: 2
ethernets:
ens18:
dhcp4: yes
user-data:
package_upgrade: true
timezone: Europe/Berlin
users:
- name: xcad
groups: [adm, sudo]
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCsYvxYCpI90al2rJiyccPYNrvjHKLhvgTJVDssAL29jAPhl46gQctL98yZ+Rx9E3dLiHhs8SP14X2m50XbxX+QnjEjq2ywCqu359YMiitvaOgWMzKIaeiwnDngHc5NY+eC8t88bhhKmQPjejmdLSApLu7ObJ/9by2fjWptmqrkkhc1WQs58oYwNDenOd9UNaWcXtyPf2AGIIze2r1cFaEwAPyNtTlzCeqj41jKHLYorvU0CU5KUqgcgswXSgOC+moYac4WIUJCZCCU/s354NpKcJMYN/eiEpK1nZR/jhIe/pEsG4oIbCHy7f+PZruNhF6hi8UvhT+MHS0wwID/gj+UQPyg9GVieiQ1hv+NpLImkTdVJKemMf02548jEPhcrgLowuBemvtf4NHJE0FUH3chTu/Ioi66XKiedWdHMGLTBlWIUMuIYzHeFWLzCg8BqpQK0D7H48W7aku6JgWfhBdy5COvaglpRxlTAac8KURNtR1FRjxX9Lh1hHU+i5nLhIc= WSL2/XWIN
packages:
- qemu-guest-agent
- sudo
- vim
- zip
- unzip
65 changes: 65 additions & 0 deletions proxmox/prx-prod-2/packer/pkr-ubuntu-jammy/tpl-eval-1.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
source "proxmox-iso" "eval-1" {
proxmox_url = "${var.proxmox_api_url}"
username = "${var.proxmox_api_token_id}"
token = "${var.proxmox_api_token_secret}"
insecure_skip_tls_verify = false

node = "prx-prod-2"
vm_id = "90001"
vm_name = "pkr-ubuntu-jammy-eval-1"
template_description = "test"

iso_file = "local:iso/ubuntu-22.04.3-live-server-amd64.iso"
iso_storage_pool = "local"
unmount_iso = true
qemu_agent = true

scsi_controller = "virtio-scsi-pci"

cores = "1"
sockets = "1"
memory = "2048"

cloud_init = true
cloud_init_storage_pool = "local-lvm"

vga {
type = "virtio"
}

disks {
disk_size = "20G"
format = "raw"
storage_pool = "local-lvm"
type = "virtio"
}

network_adapters {
model = "virtio"
bridge = "vmbr1"
firewall = "false"
}

boot_command = [
"<esc><wait>",
"e<wait>",
"<down><down><down><end>",
"<bs><bs><bs><bs><wait>",
"autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
"<f10><wait>"
]

boot = "c"
boot_wait = "6s"
communicator = "ssh"

http_directory = "pkr-ubuntu-jammy/http"

ssh_username = "${var.ssh_username}"
ssh_private_key_file = "${var.ssh_private_key_file}"

# Raise the timeout, when installation takes longer
ssh_timeout = "30m"
ssh_pty = true
ssh_handshake_attempts = 15
}
65 changes: 65 additions & 0 deletions proxmox/prx-prod-2/packer/pkr-ubuntu-jammy/tpl-prod-1.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
source "proxmox-iso" "prod-1" {
proxmox_url = "${var.proxmox_api_url}"
username = "${var.proxmox_api_token_id}"
token = "${var.proxmox_api_token_secret}"
insecure_skip_tls_verify = false

node = "prx-prod-2"
vm_id = "90002"
vm_name = "pkr-ubuntu-jammy-prod-1"
template_description = "test"

iso_file = "local:iso/ubuntu-22.04.3-live-server-amd64.iso"
iso_storage_pool = "local"
unmount_iso = true
qemu_agent = true

scsi_controller = "virtio-scsi-pci"

cores = "1"
sockets = "1"
memory = "2048"

cloud_init = true
cloud_init_storage_pool = "local-lvm"

vga {
type = "virtio"
}

disks {
disk_size = "20G"
format = "raw"
storage_pool = "local-lvm"
type = "virtio"
}

network_adapters {
model = "virtio"
bridge = "vmbr1"
firewall = "false"
}

boot_command = [
"<esc><wait>",
"e<wait>",
"<down><down><down><end>",
"<bs><bs><bs><bs><wait>",
"autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
"<f10><wait>"
]

boot = "c"
boot_wait = "6s"
communicator = "ssh"

http_directory = "pkr-ubuntu-jammy/http"

ssh_username = "${var.ssh_username}"
ssh_private_key_file = "${var.ssh_private_key_file}"

# Raise the timeout, when installation takes longer
ssh_timeout = "30m"
ssh_pty = true
ssh_handshake_attempts = 15
}
21 changes: 11 additions & 10 deletions proxmox/prx-prod-2/terraform/_provider.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
terraform {

required_version = ">= 0.13.0"

required_providers {
proxmox = {
source = "telmate/proxmox"
source = "telmate/proxmox"
version = "=2.9.14"
}
}

cloud {
organization = "clcreative"

workspaces {
name = "prx-prod-2"
}
}
}

variable "PRX_PROD_2_URL" {
type = string
type = string
}

variable "PRX_PROD_2_USER" {
type = string
type = string
}

variable "PRX_PROD_2_TOKEN" {
type = string
sensitive = true
type = string
sensitive = true
}

provider "proxmox" {
pm_api_url = var.PRX_PROD_2_URL
pm_api_token_id = var.PRX_PROD_2_USER
pm_api_token_secret = var.PRX_PROD_2_TOKEN
pm_tls_insecure = false
pm_api_url = var.PRX_PROD_2_URL
pm_api_token_id = var.PRX_PROD_2_USER
pm_api_token_secret = var.PRX_PROD_2_TOKEN
pm_tls_insecure = false
}

0 comments on commit 2cfc9bf

Please sign in to comment.