fix: use native proxmox nocloud config
This commit is contained in:
parent
69e39bd812
commit
67f2edbc4d
|
|
@ -34,48 +34,6 @@ resource "null_resource" "stage_talos_image" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "nocloud_network_config" {
|
||||
for_each = { for node in var.nodes : node.name => node }
|
||||
|
||||
node_name = lookup(each.value, "proxmox_node", var.proxmox_node)
|
||||
datastore_id = var.talos_image_storage
|
||||
content_type = "snippets"
|
||||
|
||||
source_raw {
|
||||
data = local_file.metal_network_config[each.key].content
|
||||
file_name = "${each.key}-network-config.yaml"
|
||||
}
|
||||
|
||||
depends_on = [local_file.metal_network_config]
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "nocloud_metadata" {
|
||||
for_each = { for node in var.nodes : node.name => node }
|
||||
|
||||
node_name = lookup(each.value, "proxmox_node", var.proxmox_node)
|
||||
datastore_id = var.talos_image_storage
|
||||
content_type = "snippets"
|
||||
|
||||
source_raw {
|
||||
data = "instance-id: ${each.key}\nlocal-hostname: ${each.key}\n"
|
||||
file_name = "${each.key}-meta-data.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "nocloud_user_data" {
|
||||
for_each = { for node in var.nodes : node.name => node }
|
||||
|
||||
node_name = lookup(each.value, "proxmox_node", var.proxmox_node)
|
||||
datastore_id = var.talos_image_storage
|
||||
content_type = "snippets"
|
||||
|
||||
source_raw {
|
||||
data = "#cloud-config\n"
|
||||
file_name = "${each.key}-user-data.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Create all required network bridges
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "cluster_bridge" {
|
||||
for_each = local.unique_bridges
|
||||
|
|
@ -162,21 +120,29 @@ resource "proxmox_virtual_environment_vm" "vm" {
|
|||
|
||||
# Talos reads this Proxmox-generated cidata disk through its NoCloud platform.
|
||||
initialization {
|
||||
datastore_id = var.talos_image_storage
|
||||
interface = "ide3"
|
||||
type = "nocloud"
|
||||
meta_data_file_id = proxmox_virtual_environment_file.nocloud_metadata[each.key].id
|
||||
network_data_file_id = proxmox_virtual_environment_file.nocloud_network_config[each.key].id
|
||||
user_data_file_id = proxmox_virtual_environment_file.nocloud_user_data[each.key].id
|
||||
datastore_id = var.talos_image_storage
|
||||
interface = "ide3"
|
||||
type = "nocloud"
|
||||
|
||||
dynamic "ip_config" {
|
||||
for_each = each.value.networks[0].ip != null ? [each.value.networks[0]] : []
|
||||
content {
|
||||
ipv4 {
|
||||
address = "${ip_config.value.ip}/${split("/", ip_config.value.cidr)[1]}"
|
||||
gateway = ip_config.value.gateway
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dns {
|
||||
servers = var.dns_servers
|
||||
}
|
||||
}
|
||||
|
||||
# Ensure image staging and bridge setup complete before VMs
|
||||
depends_on = [
|
||||
proxmox_virtual_environment_network_linux_bridge.cluster_bridge,
|
||||
null_resource.stage_talos_image,
|
||||
proxmox_virtual_environment_file.nocloud_network_config,
|
||||
proxmox_virtual_environment_file.nocloud_metadata,
|
||||
proxmox_virtual_environment_file.nocloud_user_data,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,6 @@ resource "local_file" "talconfig" {
|
|||
})
|
||||
}
|
||||
|
||||
resource "local_file" "metal_network_config" {
|
||||
for_each = { for node in var.nodes : node.name => node }
|
||||
|
||||
filename = "${path.module}/../generated/metal-network/${each.key}.yaml"
|
||||
content = templatefile("${path.module}/templates/talos-metal-network.yaml.tpl", {
|
||||
node = each.value
|
||||
dns_servers = var.dns_servers
|
||||
})
|
||||
}
|
||||
|
||||
# (The output block is already correct from the last fix)
|
||||
output "node_organization" {
|
||||
description = "How your nodes are organized for Talos configuration"
|
||||
|
|
@ -85,4 +75,4 @@ output "node_organization" {
|
|||
name = node.name, ip = node.networks[0].ip, tags = lookup(node, "tags", [])
|
||||
} if node.role == "worker" && contains(lookup(node, "tags", []), "gpu")]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
version: 2
|
||||
ethernets:
|
||||
%{ for i, net in node.networks ~}
|
||||
eth${i}:
|
||||
match:
|
||||
macaddress: "${net.mac_address}"
|
||||
dhcp4: false
|
||||
%{ if i == 0 && net.vlan_id == 0 ~}
|
||||
addresses:
|
||||
- ${net.ip}/${split("/", net.cidr)[1]}
|
||||
gateway4: ${net.gateway}
|
||||
nameservers:
|
||||
addresses:
|
||||
%{ for dns in dns_servers ~}
|
||||
- ${dns}
|
||||
%{ endfor ~}
|
||||
%{ endif ~}
|
||||
%{ endfor ~}
|
||||
%{ if node.networks[0].vlan_id > 0 ~}
|
||||
vlans:
|
||||
eth0.${node.networks[0].vlan_id}:
|
||||
id: ${node.networks[0].vlan_id}
|
||||
link: eth0
|
||||
addresses:
|
||||
- ${node.networks[0].ip}/${split("/", node.networks[0].cidr)[1]}
|
||||
gateway4: ${node.networks[0].gateway}
|
||||
nameservers:
|
||||
addresses:
|
||||
%{ for dns in dns_servers ~}
|
||||
- ${dns}
|
||||
%{ endfor ~}
|
||||
%{ endif ~}
|
||||
Loading…
Reference in a new issue