@@ -28,6 +28,14 @@ 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 = " global_ipv4"
35
+ quantity = 1
36
+ description = each. value
37
+ }
38
+
31
39
resource "equinix_metal_device" "control_plane" {
32
40
hostname = " ${ var . cluster_name } -control-plane"
33
41
plan = var. device_plan
@@ -71,8 +79,9 @@ resource "equinix_metal_device" "worker" {
71
79
depends_on = [equinix_metal_device . control_plane ]
72
80
user_data = << EOF
73
81
#!/bin/bash
82
+ ${ 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
83
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL="${ var . k3s_version } " sh -s - agent \
75
- --token "${ var . k3s_token } " \
84
+ ${ 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
85
--server "https://${ equinix_metal_device . control_plane . access_private_ipv4 } :6443" \
77
86
${ join (" \\\n " , [for k , v in each . value . labels : " --node-label ${ k } =${ v } " ])}
78
87
EOF
85
94
}
86
95
}
87
96
97
+ resource "equinix_metal_ip_attachment" "monitoring" {
98
+ device_id = equinix_metal_device. worker [" internal-1" ]. id
99
+ cidr_notation = join (" /" , [cidrhost (equinix_metal_reserved_ip_block. elastic_ip [" monitoring" ]. cidr_notation , 0 ), " 32" ])
100
+ }
101
+
88
102
resource "null_resource" "install_cilium_cni" {
89
103
depends_on = [equinix_metal_device . control_plane ]
90
104
triggers = {
0 commit comments