Skip to content

Commit 05571b9

Browse files
authored
Merge pull request #69 from rossf7/feat/elastic-ip
feat: Add elastic ip for Grafana
2 parents 077407a + 0a847c8 commit 05571b9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

infrastructure/equinix-metal/main.tf

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ 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 = "global_ipv4"
35+
quantity = 1
36+
description = each.value
37+
}
38+
3139
resource "equinix_metal_device" "control_plane" {
3240
hostname = "${var.cluster_name}-control-plane"
3341
plan = var.device_plan
@@ -71,8 +79,9 @@ resource "equinix_metal_device" "worker" {
7179
depends_on = [equinix_metal_device.control_plane]
7280
user_data = <<EOF
7381
#!/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\nnetplan apply\n" : ""}
7483
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}" \
7685
--server "https://${equinix_metal_device.control_plane.access_private_ipv4}:6443" \
7786
${join(" \\\n", [for k, v in each.value.labels : "--node-label ${k}=${v}"])}
7887
EOF
@@ -85,6 +94,11 @@ EOF
8594
}
8695
}
8796

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+
88102
resource "null_resource" "install_cilium_cni" {
89103
depends_on = [equinix_metal_device.control_plane]
90104
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)