-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
129 lines (116 loc) · 3.54 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
resource "random_password" "graylog_password" {
length = 16
special = true
override_special = "_!%^"
}
resource "aws_secretsmanager_secret" "graylog_password" {
name = "graylog_password"
}
resource "aws_secretsmanager_secret_version" "graylog_password" {
secret_id = aws_secretsmanager_secret.graylog_password.id
secret_string = random_password.graylog_password.result
}
resource "aws_instance" "graylog_instance" {
depends_on = [local_file.keyfile]
ami = var.ami_id
instance_type = var.instance_type
key_name = aws_key_pair.ec2_aws_key_pair.key_name
associate_public_ip_address = true
subnet_id = var.public_subnet_id
vpc_security_group_ids = [aws_security_group.graylog_sg.id]
root_block_device {
volume_size = 30
}
tags = {
Name = "GrayLog"
"Management" = "Terraform"
}
connection {
type = "ssh"
host = self.public_ip
user = "ubuntu"
private_key = tls_private_key.ec2_tls_private_key.private_key_pem
}
//Copy docker_compose.yaml
provisioner "file" {
content = <<EOF
version: "3.8"
services:
mongodb:
image: "mongo:7.0"
volumes:
- "mongodb_data:/data/db"
restart: "on-failure"
opensearch:
image: "opensearchproject/opensearch:2.4.0"
environment:
- "OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g"
- "bootstrap.memory_lock=true"
- "discovery.type=single-node"
- "action.auto_create_index=false"
- "plugins.security.ssl.http.enabled=false"
- "plugins.security.disabled=true"
ulimits:
memlock:
hard: -1
soft: -1
nofile:
soft: 65536
hard: 65536
volumes:
- "os_data:/usr/share/opensearch/data"
restart: "on-failure"
graylog:
hostname: "server"
image: "graylog/graylog:5.0"
depends_on:
opensearch:
condition: "service_started"
mongodb:
condition: "service_started"
entrypoint: "/usr/bin/tini -- wait-for-it opensearch:9200 -- /docker-entrypoint.sh"
environment:
GRAYLOG_NODE_ID_FILE: "/usr/share/graylog/data/config/node-id"
GRAYLOG_PASSWORD_SECRET: "${aws_secretsmanager_secret_version.graylog_password.secret_string}"
GRAYLOG_ROOT_PASSWORD_SHA2: "${sha256(aws_secretsmanager_secret_version.graylog_password.secret_string)}"
GRAYLOG_HTTP_BIND_ADDRESS: "0.0.0.0:9000"
GRAYLOG_HTTP_EXTERNAL_URI: "http://localhost:9000/"
GRAYLOG_ELASTICSEARCH_HOSTS: "http://opensearch:9200"
GRAYLOG_MONGODB_URI: "mongodb://mongodb:27017/graylog"
ports:
- "5044:5044/tcp" # Beats
- "5140:5140/udp" # Syslog
- "5140:5140/tcp" # Syslog
- "5555:5555/tcp" # RAW TCP
- "5555:5555/udp" # RAW TCP
- "80:9000/tcp" # Server API
- "12201:12201/tcp" # GELF TCP
- "12201:12201/udp" # GELF UDP
#- "10000:10000/tcp" # Custom TCP port
#- "10000:10000/udp" # Custom UDP port
- "13301:13301/tcp" # Forwarder data
- "13302:13302/tcp" # Forwarder config
volumes:
- "graylog_data:/usr/share/graylog/data/data"
- "graylog_journal:/usr/share/graylog/data/journal"
restart: "on-failure"
volumes:
mongodb_data:
os_data:
graylog_data:
graylog_journal:
EOF
destination = "/home/ubuntu/docker_compose.yaml"
}
//Copy up.sh
provisioner "file" {
content = var.up_script
destination = "/home/ubuntu/up.sh"
}
//Run up.sh
provisioner "remote-exec" {
inline = [
"sudo sh /home/ubuntu/up.sh"
]
}
}