module_alpine_prometheus_no.../main.tf

39 lines
1.4 KiB
HCL

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",
"/etc/init.d/node_exporter start",
#
"echo '# module DONE'",
]
}
}