-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprometheus-node_exporter-setup.tf
More file actions
89 lines (80 loc) · 2.21 KB
/
prometheus-node_exporter-setup.tf
File metadata and controls
89 lines (80 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
provider "aws" {
region = "us-east-1"
}
locals {
instance_type = "t2.micro"
}
resource "aws_instance" "node-exporter" {
ami = var.ami_id
instance_type = local.instance_type
key_name = "myec2keypair"
vpc_security_group_ids = [aws_security_group.node_exp_sg.id]
associate_public_ip_address = true
user_data = file("node-exporter.sh")
tags = {
Name = "node-exporter-tf"
}
}
resource "aws_instance" "prometheus" {
ami = var.ami_id
instance_type = local.instance_type
key_name = "myec2keypair"
vpc_security_group_ids = [aws_security_group.prom_sg.id]
associate_public_ip_address = true
user_data = <<-EOF
#!/bin/bash
sudo apt update -y
sudo apt-get update
sudo apt-get -y upgrade
cd /opt
sudo wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz
sudo tar xf prometheus-2.43.0.linux-amd64.tar.gz
sudo sed -i 's/- targets: \["localhost:9090"\]/- targets: \["localhost:9090", ${aws_instance.node-exporter.public_ip}:9100\]/' /opt/prometheus-2.43.0.linux-amd64/prometheus.yml
sudo ./prometheus
EOF
tags = {
Name = "prometheus-tf"
}
}
resource "aws_security_group" "node_exp_sg" {
name_prefix = "node_exp_sg"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 9100
to_port = 9100
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "prom_sg" {
name_prefix = "prom_sg"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 9090
to_port = 9090
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}