Skip to content

Commit 1425558

Browse files
revert: ansible
Stick to tf for meow
1 parent 775f82e commit 1425558

File tree

5 files changed

+112
-16
lines changed

5 files changed

+112
-16
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ override.tf.json
6868
# Ignore CLI configuration files
6969
.terraformrc
7070
terraform.rc
71+
72+
# INCLUDE
73+
!**/*.example
74+
!**/.gitkeep

main.tf

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ resource "docker_container" "prometheus" {
3030
name = docker_network.promgraf_network.name
3131
}
3232

33+
restart = "unless-stopped"
34+
35+
destroy_grace_seconds = 10
36+
3337
depends_on = [
3438
docker_volume.prometheus_data,
3539
local_file.prometheus_config
3640
]
37-
38-
destroy_grace_seconds = 10
3941
}
4042

4143
resource "docker_container" "grafana" {
@@ -78,6 +80,9 @@ resource "docker_container" "grafana" {
7880
networks_advanced {
7981
name = docker_network.promgraf_network.name
8082
}
83+
restart = "unless-stopped"
84+
85+
destroy_grace_seconds = 10
8186

8287
depends_on = [
8388
docker_volume.grafana_data,
@@ -87,8 +92,6 @@ resource "docker_container" "grafana" {
8792
local_file.node_exporter_dashboard,
8893
local_file.grafana_datasource
8994
]
90-
91-
destroy_grace_seconds = 10
9295
}
9396

9497
resource "local_file" "grafana_datasource" {
@@ -108,12 +111,17 @@ resource "docker_container" "node_exporter" {
108111
networks_advanced {
109112
name = docker_network.promgraf_network.name
110113
}
114+
115+
restart = "unless-stopped"
116+
117+
destroy_grace_seconds = 10
111118
}
112119

113120
resource "local_file" "prometheus_config" {
114121
content = templatefile("${path.module}/config/prometheus.yml.tpl", {
115-
prometheus_port = var.prometheus_port
116-
node_exporter_port = var.node_exporter_port
122+
prometheus_port = var.prometheus_port
123+
node_exporter_port = var.node_exporter_port
124+
node_exporter_hosts = var.node_exporter_hosts
117125
})
118126
filename = "${path.module}/config/prometheus.yml"
119127
}
@@ -141,11 +149,7 @@ resource "local_file" "node_exporter_dashboard" {
141149
}
142150

143151
resource "null_resource" "wait_for_containers" {
144-
count = length([
145-
docker_container.prometheus.id,
146-
docker_container.grafana.id,
147-
docker_container.node_exporter.id
148-
])
152+
count = 1
149153

150154
depends_on = [
151155
docker_container.prometheus,
@@ -157,3 +161,13 @@ resource "null_resource" "wait_for_containers" {
157161
command = "sleep 10"
158162
}
159163
}
164+
165+
resource "null_resource" "wait_for_remote_containers" {
166+
depends_on = [
167+
null_resource.run_ansible
168+
]
169+
170+
provisioner "local-exec" {
171+
command = "sleep 10"
172+
}
173+
}

outputs.tf

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,71 @@
1-
# output "output" {
2-
# value = terraform_data.this.output
3-
# description = "This is an example of an output."
4-
# }
1+
# Prometheus outputs
2+
output "prometheus_url" {
3+
description = "URL to access Prometheus UI"
4+
value = "http://localhost:${var.prometheus_port}"
5+
}
6+
7+
output "prometheus_container_id" {
8+
description = "ID of the Prometheus container"
9+
value = docker_container.prometheus.id
10+
}
11+
12+
# Grafana outputs
13+
output "grafana_url" {
14+
description = "URL to access Grafana UI"
15+
value = "http://localhost:${var.grafana_port}"
16+
}
17+
18+
output "grafana_container_id" {
19+
description = "ID of the Grafana container"
20+
value = docker_container.grafana.id
21+
}
22+
23+
output "grafana_credentials" {
24+
description = "Grafana login credentials"
25+
value = {
26+
username = var.grafana_admin_user
27+
password = nonsensitive(var.grafana_admin_password) # Mark as non-sensitive for output
28+
}
29+
sensitive = true
30+
}
31+
32+
# Node Exporter outputs
33+
output "local_node_exporter" {
34+
description = "Local node-exporter details"
35+
value = {
36+
url = "http://localhost:${var.node_exporter_port}/metrics"
37+
container_id = docker_container.node_exporter.id
38+
network = docker_network.promgraf_network.name
39+
}
40+
}
41+
42+
output "remote_node_exporters" {
43+
description = "Remote node-exporter details"
44+
value = {
45+
for host in var.node_exporter_hosts : host.name => {
46+
url = "http://${host.ip}:${var.node_exporter_port}/metrics"
47+
host = host.ip
48+
ssh_user = host.ssh_user
49+
}
50+
}
51+
}
52+
53+
# Network info
54+
output "monitoring_network" {
55+
description = "Docker network details"
56+
value = {
57+
name = docker_network.promgraf_network.name
58+
id = docker_network.promgraf_network.id
59+
}
60+
}
61+
62+
# Configuration files
63+
output "config_files" {
64+
description = "Paths to important configuration files"
65+
value = {
66+
prometheus_config = local_file.prometheus_config.filename
67+
grafana_config = local_file.grafana_config.filename
68+
dashboards_path = "${path.module}/config/grafana/dashboards"
69+
datasources_path = "${path.module}/config/grafana/provisioning/datasources"
70+
}
71+
}

resources.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "docker_image" "grafana" {
2121
}
2222

2323
resource "docker_image" "node_exporter" {
24-
name = "prom/node-exporter:latest"
24+
name = "prom/node-exporter:latest"
25+
keep_locally = true
2526
}
2627

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ variable "node_exporter_port" {
1313
default = 9100
1414
}
1515

16+
variable "node_exporter_hosts" {
17+
description = "List of hosts for node-exporter deployment"
18+
type = list(object({
19+
name = string
20+
ip = string
21+
ssh_user = string
22+
ssh_port = number
23+
}))
24+
}
25+
1626
variable "grafana_admin_user" {
1727
description = "The Grafana admin username"
1828
default = "admin"

0 commit comments

Comments
 (0)