homelab/tf/cloud-init.tf

85 lines
1.6 KiB
HCL

data "local_file" "ssh_pub_key" {
filename = "${path.module}/data/id_rsa.pub"
}
locals {
common_cloud_init = <<EOF
#cloud-config
chpasswd:
list: |
ubuntu:ubuntu
${var.username}:${var.username}
expire: false
packages:
- qemu-guest-agent
- nfs-common
- avahi-daemon
timezone: America/Vancouver
users:
- default
- name: ubuntu
groups: sudo
shell: /bin/bash
ssh-authorized-keys:
- ${trimspace(data.local_file.ssh_pub_key.content)}
sudo: ALL=(ALL) NOPASSWD:ALL
- name: ${var.username}
groups: sudo
shell: /bin/bash
ssh_import_id:
- ${var.ssh_import_id}
sudo: ALL=(ALL) NOPASSWD:ALL
power_state:
delay: now
mode: reboot
message: Rebooting after cloud-init completion
condition: true
EOF
}
resource "proxmox_virtual_environment_file" "common_cloud_init" {
content_type = "snippets"
datastore_id = var.proxmox_image_storage
node_name = "pve"
source_raw {
data = <<EOF
#cloud-config
chpasswd:
list: |
ubuntu:ubuntu
${var.username}:${var.username}
expire: false
packages:
- qemu-guest-agent
- nfs-common
- avahi-daemon
timezone: America/Vancouver
users:
- default
- name: ubuntu
groups: sudo
shell: /bin/bash
ssh-authorized-keys:
- ${trimspace(data.local_file.ssh_pub_key.content)}
sudo: ALL=(ALL) NOPASSWD:ALL
- name: ${var.username}
groups: sudo
shell: /bin/bash
ssh_import_id:
- ${var.ssh_import_id}
sudo: ALL=(ALL) NOPASSWD:ALL
power_state:
delay: now
mode: reboot
message: Rebooting after cloud-init completion
condition: true
EOF
file_name = "common-cloud-init.cloud-config.yaml"
}
}