add template vm in proxmox [ci skip]
This commit is contained in:
parent
52638b3783
commit
9831fe1bc3
5 changed files with 68 additions and 18 deletions
40
main.tf
40
main.tf
|
|
@ -2,9 +2,11 @@ variable "prod" {
|
||||||
type = bool
|
type = bool
|
||||||
default = false
|
default = false
|
||||||
}
|
}
|
||||||
variable "vsphere_password" {}
|
variable "proxmox_pm_api_url" { type = string }
|
||||||
variable "vsphere_user" {}
|
variable "proxmox_pm_api_token_id" { type = string }
|
||||||
variable "vsphere_server" {}
|
variable "proxmox_pm_api_token_secret" { type = string }
|
||||||
|
variable "vm_wizard_password" { type = string }
|
||||||
|
variable "proxmox_host" { type = string }
|
||||||
variable "tls_secret_name" {}
|
variable "tls_secret_name" {}
|
||||||
variable "tls_crt" {
|
variable "tls_crt" {
|
||||||
default = ""
|
default = ""
|
||||||
|
|
@ -114,9 +116,6 @@ variable "onlyoffice_jwt_token" { type = string }
|
||||||
variable "xray_reality_clients" { type = list(map(string)) }
|
variable "xray_reality_clients" { type = list(map(string)) }
|
||||||
variable "xray_reality_private_key" { type = string }
|
variable "xray_reality_private_key" { type = string }
|
||||||
variable "xray_reality_short_ids" { type = list(string) }
|
variable "xray_reality_short_ids" { type = list(string) }
|
||||||
variable "proxmox_pm_api_url" { type = string }
|
|
||||||
variable "proxmox_pm_api_token_id" { type = string }
|
|
||||||
variable "proxmox_pm_api_token_secret" { type = string }
|
|
||||||
|
|
||||||
|
|
||||||
# data "terraform_remote_state" "foo" {
|
# data "terraform_remote_state" "foo" {
|
||||||
|
|
@ -156,28 +155,33 @@ provider "proxmox" {
|
||||||
# comment = "VLAN 99"
|
# comment = "VLAN 99"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
locals {
|
||||||
|
vm_template_name = "ubuntu-2404-cloudinit-template"
|
||||||
|
vm_cloud_init_snippet_name = "cloud_init.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
# Main module to init infra from
|
# Main module to init infra from
|
||||||
module "template-vm" {
|
module "template-vm" {
|
||||||
source = "./modules/create-template-vm"
|
source = "./modules/create-template-vm"
|
||||||
proxmox_host = "192.168.1.127"
|
proxmox_host = var.proxmox_host
|
||||||
proxmox_user = "root" # SSH user on Proxmox host
|
proxmox_user = "root" # SSH user on Proxmox host
|
||||||
cloud_image_url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
|
cloud_image_url = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||||
image_path = "/var/lib/vz/template/iso/jammy-server-cloudimg-amd64.img"
|
image_path = "/var/lib/vz/template/iso/noble-server-cloudimg-amd64.img"
|
||||||
template_id = 8000
|
template_id = 8000
|
||||||
template_name = "ubuntu-2204-cloudinit-template"
|
template_name = local.vm_template_name
|
||||||
|
|
||||||
|
snippet_name = local.vm_cloud_init_snippet_name
|
||||||
|
user_passwd = var.vm_wizard_password
|
||||||
}
|
}
|
||||||
|
|
||||||
# module "pxe-server" {
|
# module "pxe-server" {
|
||||||
# source = "./modules/create-vm"
|
# template_name = local.vm_template_name
|
||||||
# vm_name = "pxe-server"
|
# source = "./modules/create-vm"
|
||||||
# network = "dManagementVMs"
|
# vm_name = "pxe-server"
|
||||||
# # provisioner_command = "${var.ansible_prefix} -t linux/pxe-server/add-distro"
|
|
||||||
# provisioner_command = "# no provisioner needed #" # Noop until ubuntu autoinstall is setup
|
|
||||||
|
|
||||||
# cdrom_path = "ISO/ubuntu-server-20.04.1.iso"
|
|
||||||
# vm_disk_size = 50
|
# vm_disk_size = 50
|
||||||
# vm_mac_address = "00:50:56:87:4a:2d"
|
# cisnippet_name = local.vm_cloud_init_snippet_name
|
||||||
|
|
||||||
|
# # vm_mac_address = "00:50:56:87:4a:2d"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# module "k8s_master" {
|
# module "k8s_master" {
|
||||||
|
|
|
||||||
22
modules/create-template-vm/cloud_init.yaml
Normal file
22
modules/create-template-vm/cloud_init.yaml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#cloud-config
|
||||||
|
hostname: terraform-vm
|
||||||
|
users:
|
||||||
|
- name: wizard
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- ${authorized_ssh_key}
|
||||||
|
passwd: ${passwd}
|
||||||
|
lock_passwd: false # enable passwd login
|
||||||
|
package_update: true
|
||||||
|
package_upgrade: true
|
||||||
|
packages:
|
||||||
|
- htop
|
||||||
|
- vim
|
||||||
|
- curl
|
||||||
|
- jq
|
||||||
|
- tcpdump
|
||||||
|
- tree
|
||||||
|
- tmux
|
||||||
|
- wget
|
||||||
|
- net-tools
|
||||||
|
- zsh
|
||||||
|
|
@ -7,6 +7,8 @@ variable "template_id" {
|
||||||
default = 8000
|
default = 8000
|
||||||
}
|
}
|
||||||
variable "template_name" { type = string }
|
variable "template_name" { type = string }
|
||||||
|
variable "snippet_name" { type = string }
|
||||||
|
variable "user_passwd" { type = string } # hashed pw
|
||||||
|
|
||||||
# SSH connection to Proxmox
|
# SSH connection to Proxmox
|
||||||
resource "null_resource" "create_template_remote" {
|
resource "null_resource" "create_template_remote" {
|
||||||
|
|
@ -39,3 +41,25 @@ resource "null_resource" "create_template_remote" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "null_resource" "upload_cloud_init" {
|
||||||
|
connection {
|
||||||
|
type = "ssh"
|
||||||
|
host = var.proxmox_host
|
||||||
|
user = var.proxmox_user
|
||||||
|
private_key = file("~/.ssh/id_ed25519")
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "remote-exec" {
|
||||||
|
inline = ["mkdir -p /var/lib/vz/snippets"]
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "file" {
|
||||||
|
destination = "/var/lib/vz/snippets/${var.snippet_name}"
|
||||||
|
content = templatefile("${path.module}/cloud_init.yaml", { authorized_ssh_key = file("~/.ssh/id_ed25519.pub"), passwd = var.user_passwd })
|
||||||
|
}
|
||||||
|
|
||||||
|
triggers = {
|
||||||
|
file_hash = filesha256("${path.module}/cloud_init.yaml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
terraform.tfvars
BIN
terraform.tfvars
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue