@@ -28,6 +28,15 @@ resource "equinix_metal_project_ssh_key" "ssh_key" {
28
28
public_key = var. ssh_public_key
29
29
}
30
30
31
+ resource "equinix_metal_reserved_ip_block" "elastic_ip" {
32
+ for_each = toset (var. elastic_ips )
33
+ project_id = var. equinix_project_id
34
+ type = " public_ipv4"
35
+ metro = var. device_metro
36
+ quantity = 1
37
+ description = each. value
38
+ }
39
+
31
40
resource "equinix_metal_device" "control_plane" {
32
41
hostname = " ${ var . cluster_name } -control-plane"
33
42
plan = var. device_plan
@@ -71,8 +80,9 @@ resource "equinix_metal_device" "worker" {
71
80
depends_on = [equinix_metal_device . control_plane ]
72
81
user_data = << EOF
73
82
#!/bin/bash
83
+ ${ each . value . elastic_ip != " " ? " echo -e \" network:\n version: 2\n renderer: networkd\n ethernets:\n lo:\n addresses: [127.0.0.1/8, '${ join (" /" , [cidrhost (equinix_metal_reserved_ip_block. elastic_ip [each . value . elastic_ip ]. cidr_notation , 0 ), " 32" ])} ']\" > /etc/netplan/01-netcfg.yaml\n netplan apply\n " : " " }
74
84
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL="${ var . k3s_version } " sh -s - agent \
75
- --token "${ var . k3s_token } " \
85
+ ${ each . value . elastic_ip != " " ? " --node-external-ip ${ cidrhost (equinix_metal_reserved_ip_block . elastic_ip [ each . value . elastic_ip ] . cidr_notation , 0 ) } " : " " } --token "${ var . k3s_token } " \
76
86
--server "https://${ equinix_metal_device . control_plane . access_private_ipv4 } :6443" \
77
87
${ join (" \\\n " , [for k , v in each . value . labels : " --node-label ${ k } =${ v } " ])}
78
88
EOF
85
95
}
86
96
}
87
97
98
+ resource "equinix_metal_ip_attachment" "monitoring" {
99
+ device_id = equinix_metal_device. worker [" internal-1" ]. id
100
+ cidr_notation = join (" /" , [cidrhost (equinix_metal_reserved_ip_block. elastic_ip [" monitoring" ]. cidr_notation , 0 ), " 32" ])
101
+ }
102
+
88
103
resource "null_resource" "install_cilium_cni" {
89
104
depends_on = [equinix_metal_device . control_plane ]
90
105
triggers = {
0 commit comments