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
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
|
||||
}
|
||||
variable "template_name" { type = string }
|
||||
variable "snippet_name" { type = string }
|
||||
variable "user_passwd" { type = string } # hashed pw
|
||||
|
||||
# SSH connection to Proxmox
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue