Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion instance.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "google_compute_instance" "app" {
count = var.app_enabled ? 1 : 0

name = "${var.yourname}-${var.env}-app"
machine_type = "n2-highcpu-16" // for memtier/TLS we need a highcpu machine
machine_type = "n2-highcpu-32" // for memtier/TLS we need a highcpu machine
//machine_type = var.machine_type
zone = "${var.region_name}-${var.region_zones[0]}"
tags = ["ssh", "http"]
Expand Down Expand Up @@ -31,6 +31,39 @@ resource "google_compute_instance" "app" {
}
}

resource "google_compute_instance" "monitor" {
count = var.monitor_enabled ? 1 : 0

name = "${var.yourname}-${var.env}-monitor"
machine_type = "e2-standard-4" // for memtier/TLS we need a highcpu machine
//machine_type = var.machine_type
zone = "${var.region_name}-${var.region_zones[0]}"
tags = ["ssh", "http"]
boot_disk {
initialize_params {
image = "ubuntu-minimal-2204-jammy-v20250311" //"ubuntu-minimal-2004-lts"
size = 30 //GB
}
}
labels = {
owner = var.yourname
skip_deletion = "yes"
}
metadata = {
ssh-keys = "ubuntu:${file("~/.ssh/google_compute_engine.pub")}"
startup-script = templatefile("${path.module}/scripts/monitor.sh", {
cluster_dns_suffix = "${var.yourname}-${var.env}.${var.dns_zone_dns_name}",
RS_CLUSTER_DNS = "cluster.${var.yourname}-${var.env}.${var.dns_zone_dns_name}"
})
}
network_interface {
subnetwork = google_compute_subnetwork.public_subnet.name
access_config {
// Ephemeral IP
}
}
}

resource "google_compute_instance" "node1" {
name = "${var.yourname}-${var.env}-1"
machine_type = var.machine_type
Expand Down Expand Up @@ -134,6 +167,18 @@ resource "google_dns_record_set" "app" {

rrdatas = [google_compute_instance.app.0.network_interface.0.access_config.0.nat_ip]
}

resource "google_dns_record_set" "monitor" {
count = var.monitor_enabled ? 1 : 0

name = "monitor.${var.yourname}-${var.env}.${var.dns_zone_dns_name}."
type = "A"
ttl = 300
managed_zone = var.dns_managed_zone

rrdatas = [google_compute_instance.monitor.0.network_interface.0.access_config.0.nat_ip]
}

resource "google_dns_record_set" "node1" {
name = "node1.${var.yourname}-${var.env}.${var.dns_zone_dns_name}."
type = "A"
Expand Down
49 changes: 0 additions & 49 deletions k8s.tf

This file was deleted.

11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ output "rs_ui_dns" {
value = ["https://node1.${var.yourname}-${var.env}.${var.dns_zone_dns_name}:8443",
"https://cluster.${var.yourname}-${var.env}.${var.dns_zone_dns_name}:8443"]
}

output "monitor_grafana" {
value = ["http://monitor.${var.yourname}-${var.env}.${var.dns_zone_dns_name}:3000",
"user = admin , password = secret", "monitor IP:${google_compute_instance.monitor.0.network_interface.0.access_config.0.nat_ip}"]
}

output "monitor_prometheus" {
value = ["http://monitor.${var.yourname}-${var.env}.${var.dns_zone_dns_name}:9090",
"monitor IP:${google_compute_instance.monitor.0.network_interface.0.access_config.0.nat_ip}"]
}

output "rs_ui_ip" {
value = "https://${google_compute_instance.node1.network_interface.0.access_config.0.nat_ip}:8443"
}
Expand Down
73 changes: 73 additions & 0 deletions scripts/monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

set -e

echo "Fetching Redis Enterprise DNS from Terraform outputs..."

echo "Installing Docker and Docker Compose..."
sudo apt-get update
sudo apt-get install -y docker.io docker-compose
sudo systemctl start docker
sudo systemctl enable docker

echo "Creating Prometheus configuration directory..."
mkdir prometheus

echo "Creating prometheus.yml with cluster DNS: $RS_CLUSTER_DNS"

cat > prometheus/prometheus.yml <<EOF
global:
scrape_interval: 15s
evaluation_interval: 15s

external_labels:
monitor: "prometheus-stack-monitor"

scrape_configs:
- job_name: prometheus
scrape_interval: 10s
scrape_timeout: 5s
static_configs:
- targets: ["localhost:9090"]

- job_name: redis-enterprise
scrape_interval: 30s
scrape_timeout: 30s
metrics_path: /
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ["${RS_CLUSTER_DNS}:8070"]
EOF

echo "Creating docker-compose.yml..."
cat > docker-compose.yml <<EOF
version: '3'

services:
prometheus-server:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml


grafana-ui:
image: grafana/grafana
ports:
- 3000:3000
environment:
- GF_SECURITY_ADMIN_PASSWORD=secret
links:
- prometheus-server:prometheus
EOF

echo "Starting Prometheus and Grafana using Docker Compose..."
sudo docker-compose up -d

echo "Done!"
echo "Prometheus: http://<YOUR_VM_PUBLIC_IP>:9090"
echo "Grafana: http://<YOUR_VM_PUBLIC_IP>:3000 (login: admin / admin)"
echo "Metrics are scraped from: https://${RS_CLUSTER_DNS}:8070"
4 changes: 4 additions & 0 deletions variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ variable "app_enabled" {
default = false
}

variable "monitor_enabled" {
default = false
}

// other possible edits ************************************* Kubernetes KGE
// GKE K8s is optional
variable "gke_enabled" {
Expand Down