This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
100 lines (84 loc) · 2.28 KB
/
main.tf
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
90
91
92
93
94
95
96
97
98
99
100
data "aws_vpc" "environment" {
id = "${var.vpc_id}"
}
data "aws_ami" "base_ami" {
filter {
name = "tag:Role"
values = ["base"]
}
most_recent = true
}
data "aws_security_group" "prometheus" {
filter {
name = "tag:Name"
values = ["${var.environment}-prometheus-sg"]
}
}
data "aws_route53_zone" "domain" {
name = "${var.domain}."
}
resource "aws_iam_instance_profile" "prometheus" {
name_prefix = "${var.environment}-prometheus"
roles = ["PrometheusRead"]
}
resource "aws_instance" "prometheus" {
ami = "${data.aws_ami.base_ami.id}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${var.public_subnet_id}"
user_data = "${file("${path.module}/files/prometheus_bootstrap.sh")}"
iam_instance_profile = "${aws_iam_instance_profile.prometheus.name}"
vpc_security_group_ids = [
"${aws_security_group.prometheus_host_sg.id}",
"${data.aws_security_group.prometheus.id}",
]
tags {
Name = "${var.environment}-${var.app}-${var.role}"
Role = "${var.role}"
}
}
resource "aws_eip" "prometheus" {
instance = "${aws_instance.prometheus.id}"
vpc = true
}
resource "aws_route53_record" "web" {
zone_id = "${data.aws_route53_zone.domain.zone_id}"
name = "prometheus.${data.aws_route53_zone.domain.name}"
type = "A"
ttl = "300"
records = ["${aws_eip.prometheus.public_ip}"]
}
resource "aws_security_group" "prometheus_host_sg" {
name = "${var.environment}-${var.app}-${var.role}-host"
description = "Allow SSH and HTTP to Prometheus"
vpc_id = "${data.aws_vpc.environment.id}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${data.aws_vpc.environment.cidr_block}"]
}
# Collectd exporter
ingress {
from_port = 25826
to_port = 25826
protocol = "udp"
cidr_blocks = ["${data.aws_vpc.environment.cidr_block}"]
}
# HTTP access from the VPC
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"]
}
tags {
Name = "${var.environment}-${var.app}-${var.role}-host-sg"
}
}