Skip to content

Commit 27e7784

Browse files
committed
feat: Add elastic ip for Grafana
Signed-off-by: Ross Fairbanks <[email protected]>
1 parent 077407a commit 27e7784

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

infrastructure/equinix-metal/main.tf

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ resource "equinix_metal_project_ssh_key" "ssh_key" {
2828
public_key = var.ssh_public_key
2929
}
3030

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+
3140
resource "equinix_metal_device" "control_plane" {
3241
hostname = "${var.cluster_name}-control-plane"
3342
plan = var.device_plan
@@ -71,8 +80,9 @@ resource "equinix_metal_device" "worker" {
7180
depends_on = [equinix_metal_device.control_plane]
7281
user_data = <<EOF
7382
#!/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\nnetplan apply\n" : ""}
7484
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}" \
7686
--server "https://${equinix_metal_device.control_plane.access_private_ipv4}:6443" \
7787
${join(" \\\n", [for k, v in each.value.labels : "--node-label ${k}=${v}"])}
7888
EOF
@@ -85,6 +95,11 @@ EOF
8595
}
8696
}
8797

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+
88103
resource "null_resource" "install_cilium_cni" {
89104
depends_on = [equinix_metal_device.control_plane]
90105
triggers = {

infrastructure/equinix-metal/variables.tf

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ variable "device_plan" {
3434
default = "m3.small.x86"
3535
}
3636

37+
variable "elastic_ips" {
38+
description = "List of Equinix Metal elastic ip names"
39+
type = list(string)
40+
default = ["monitoring"]
41+
}
42+
3743
variable "equinix_auth_token" {
3844
description = "Authentication token for Equinix Metal"
3945
type = string
@@ -103,18 +109,21 @@ variable "ssh_private_key_path" {
103109
variable "worker_nodes" {
104110
description = "Map of worker nodes and config"
105111
type = map(object({
112+
elastic_ip = string
106113
labels = map(string)
107114
plan = string
108115
}))
109116
default = {
110117
internal-1 = {
118+
elastic_ip = "monitoring"
111119
labels = {
112120
cncf-project = "wg-green-reviews"
113121
cncf-project-sub = "internal"
114122
},
115123
plan = "m3.small.x86"
116124
},
117125
falco-a = {
126+
elastic_ip = ""
118127
labels = {
119128
cncf-project = "falco"
120129
cncf-project-sub = "falco-driver-modern-ebpf"

0 commit comments

Comments
 (0)