module_alpine_prometheus_no.../main.tf

50 lines
1.8 KiB
HCL

#
# module "node_exporter" {
# source = "git::https://git.dalembert.upmc.fr/terraform/module_alpine_prometheus_node_exporter"
# connection_ip = var.eth0_ip
# connection_private_key = file(var.pm_private_key)
# node_exporter_version = var.node_exporter_version
# }
resource "null_resource" "alpine_prometheus_node_exporter" {
triggers = {
source = filesha256("${path.module}/node_exporter.initd")
}
connection {
type = "ssh"
user = "root"
host = var.connection_ip
private_key = var.connection_private_key
}
provisioner "file" {
source = "${path.module}/node_exporter.initd"
destination = "/tmp/node_exporter.initd"
}
provisioner "remote-exec" {
inline = [
"echo '#--------------------------------'",
"echo '# module prometheus_node_exporter'",
"echo '#--------------------------------'",
"wget -nc -q https://github.com/prometheus/node_exporter/releases/download/v${var.node_exporter_version}/node_exporter-${var.node_exporter_version}.linux-amd64.tar.gz",
"tar xzf node_exporter-${var.node_exporter_version}.linux-amd64.tar.gz node_exporter-${var.node_exporter_version}.linux-amd64/node_exporter",
"echo '# install node_exporter in /usr/sbin'",
"install -Dm755 node_exporter-${var.node_exporter_version}.linux-amd64/node_exporter /usr/sbin",
#
"echo '# install service node_exporter'",
"install -Dm755 /tmp/node_exporter.initd /etc/init.d/node_exporter",
#
"echo '# enable service node_exporter'",
"rc-update add node_exporter",
"rc-service node_exporter start",
#
"echo '# clean'",
"rm -rf node_exporter-${var.node_exporter_version}.linux-amd64.tar.gz node_exporter-${var.node_exporter_version}.linux-amd64",
"echo '# module DONE'",
]
}
}