First commit
This commit is contained in:
87
terraform/pihole/main.tf
Normal file
87
terraform/pihole/main.tf
Normal file
@@ -0,0 +1,87 @@
|
||||
data "local_file" "ssh_public_key" {
|
||||
filename = "/home/ryuuji/.ssh/id_rsa.pub"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
|
||||
content_type = "iso"
|
||||
datastore_id = "storage"
|
||||
node_name = "talos"
|
||||
url = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||
file_name = "pihole-noble-server-cloudimg-amd64.img"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "user_data_cloud_config" {
|
||||
for_each = var.vms_config
|
||||
content_type = "snippets"
|
||||
datastore_id = "storage"
|
||||
node_name = "talos"
|
||||
|
||||
source_raw {
|
||||
data = <<-EOF
|
||||
#cloud-config
|
||||
hostname: ${each.value.name}
|
||||
users:
|
||||
- default
|
||||
- name: ubuntu
|
||||
groups:
|
||||
- sudo
|
||||
shell: /bin/bash
|
||||
ssh_authorized_keys:
|
||||
- ${trimspace(data.local_file.ssh_public_key.content)}
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
runcmd:
|
||||
- apt update
|
||||
- apt install -y qemu-guest-agent net-tools
|
||||
- timedatectl set-timezone America/Santiago
|
||||
- systemctl enable qemu-guest-agent
|
||||
- systemctl start qemu-guest-agent
|
||||
- echo "done" > /tmp/cloud-config.done
|
||||
EOF
|
||||
|
||||
file_name = "${each.value.name}-user-data-cloud-config.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
|
||||
for_each = var.vms_config
|
||||
name = each.value.name
|
||||
node_name = "talos"
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
cpu {
|
||||
cores = 4
|
||||
type = "host"
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = each.value.ram
|
||||
}
|
||||
|
||||
disk {
|
||||
datastore_id = "storage-lvm"
|
||||
file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
|
||||
interface = "virtio0"
|
||||
iothread = true
|
||||
discard = "on"
|
||||
size = each.value.disk
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
|
||||
initialization {
|
||||
datastore_id = "storage-lvm"
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "${each.value.ip}/${each.value.cidr}"
|
||||
gateway = "192.168.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
user_data_file_id = proxmox_virtual_environment_file.user_data_cloud_config[each.key].id
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user