feat: cloudinit issues kinda resolved
This commit is contained in:
parent
3326622634
commit
303601de94
4 changed files with 48 additions and 17 deletions
|
@ -31,22 +31,26 @@ in
|
||||||
services.cloud-init = {
|
services.cloud-init = {
|
||||||
enable = true;
|
enable = true;
|
||||||
network.enable = true;
|
network.enable = true;
|
||||||
|
settings = {
|
||||||
|
datasource = {
|
||||||
|
NoCloud = { };
|
||||||
|
ConfigDrive = { };
|
||||||
|
};
|
||||||
|
system_info = {
|
||||||
|
default_user = {
|
||||||
|
name = "nixos";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
environment.etc."cloud/cloud.cfg.d/99_pve.cfg".text = ''
|
|
||||||
datasource_list: [ NoCloud, ConfigDrive ]
|
|
||||||
'';
|
|
||||||
|
|
||||||
# USER MANAGEMENT
|
# USER MANAGEMENT
|
||||||
# TODO: Should this be in cloud-init?
|
|
||||||
security.sudo.wheelNeedsPassword = false;
|
security.sudo.wheelNeedsPassword = false;
|
||||||
nix.settings.trusted-users = [ "nixos" ];
|
nix.settings.trusted-users = [ "nixos" ];
|
||||||
users.users.nixos = {
|
users.users.nixos = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
password = "hunter2";
|
password = "hunter2";
|
||||||
extraGroups = [ "wheel" ];
|
extraGroups = [ "wheel" ];
|
||||||
openssh.authorizedKeys.keys = [
|
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICXAlzwziqfUUb2qmFwNF/nrBYc5MNT1MMOx81ohBmB+ tine@little.sys.tjo.space"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# SSH
|
# SSH
|
||||||
|
@ -61,6 +65,7 @@ in
|
||||||
services.tailscale = {
|
services.tailscale = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
systemd.services.qemu-guest-agent.enable = false;
|
||||||
|
|
||||||
# FIREWALL
|
# FIREWALL
|
||||||
networking.useNetworkd = true;
|
networking.useNetworkd = true;
|
||||||
|
|
|
@ -55,7 +55,23 @@ resource "proxmox_virtual_environment_file" "ingress" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_file" "cloudinit" {
|
resource "proxmox_virtual_environment_file" "metadata" {
|
||||||
|
for_each = local.nodes
|
||||||
|
|
||||||
|
node_name = each.value.host
|
||||||
|
content_type = "snippets"
|
||||||
|
datastore_id = var.common_storage
|
||||||
|
|
||||||
|
source_raw {
|
||||||
|
data = <<-EOF
|
||||||
|
hostname: ${each.value.hostname}
|
||||||
|
id: ${each.value.id}
|
||||||
|
EOF
|
||||||
|
file_name = "${each.value.hostname}.metadata.yaml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "proxmox_virtual_environment_file" "userdata" {
|
||||||
for_each = local.nodes
|
for_each = local.nodes
|
||||||
|
|
||||||
node_name = each.value.host
|
node_name = each.value.host
|
||||||
|
@ -65,14 +81,15 @@ resource "proxmox_virtual_environment_file" "cloudinit" {
|
||||||
source_raw {
|
source_raw {
|
||||||
data = <<-EOF
|
data = <<-EOF
|
||||||
#cloud-config
|
#cloud-config
|
||||||
|
ssh_authorized_keys:
|
||||||
|
%{for key in var.ssh_keys~}
|
||||||
|
- ${key}
|
||||||
|
%{endfor}
|
||||||
runcmd:
|
runcmd:
|
||||||
- echo "hello world"
|
- /run/current-system/sw/bin/tailscale up --accept-routes --ssh --authkey ${tailscale_tailnet_key.ingress.key}
|
||||||
- [ 'tailscale', 'up', '--authkey', '${tailscale_tailnet_key.ingress.key}',
|
- systemctl enable --now qemu-guest-agent
|
||||||
'--hostname', '${each.value.name}',
|
|
||||||
'--accept-routes', 'true',
|
|
||||||
'--ssh' ]
|
|
||||||
EOF
|
EOF
|
||||||
file_name = "${each.value.hostname}.cloudconfig.yaml"
|
file_name = "${each.value.hostname}.userconfig.yaml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +102,7 @@ resource "proxmox_virtual_environment_vm" "nodes" {
|
||||||
|
|
||||||
description = "Node ${each.value.name} for ingress.tjo.cloud."
|
description = "Node ${each.value.name} for ingress.tjo.cloud."
|
||||||
tags = concat(
|
tags = concat(
|
||||||
["tjo-space"],
|
["ingress-tjo-cloud"],
|
||||||
[each.value.name]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
stop_on_destroy = true
|
stop_on_destroy = true
|
||||||
|
@ -136,7 +152,9 @@ resource "proxmox_virtual_environment_vm" "nodes" {
|
||||||
}
|
}
|
||||||
|
|
||||||
initialization {
|
initialization {
|
||||||
|
interface = "sata0"
|
||||||
datastore_id = each.value.storage
|
datastore_id = each.value.storage
|
||||||
user_data_file_id = proxmox_virtual_environment_file.cloudinit[each.key].id
|
user_data_file_id = proxmox_virtual_environment_file.userdata[each.key].id
|
||||||
|
meta_data_file_id = proxmox_virtual_environment_file.metadata[each.key].id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,8 @@ nodes = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssh_keys = [
|
||||||
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICXAlzwziqfUUb2qmFwNF/nrBYc5MNT1MMOx81ohBmB+ tine@little.sys.tjo.space"
|
||||||
|
]
|
||||||
|
|
||||||
common_storage = "proxmox-backup-tjo-cloud"
|
common_storage = "proxmox-backup-tjo-cloud"
|
||||||
|
|
|
@ -15,6 +15,10 @@ variable "nodes" {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "ssh_keys" {
|
||||||
|
type = list(string)
|
||||||
|
}
|
||||||
|
|
||||||
variable "common_storage" {
|
variable "common_storage" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue