Skip to content

Commit 686cdad

Browse files
committed
Add Terraform
1 parent 121532d commit 686cdad

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

.terraform.lock.hcl

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform.tf

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
variable "key_name" {}
2+
3+
provider "aws" {
4+
region = "us-east-2"
5+
}
6+
7+
resource "tls_private_key" "example" {
8+
algorithm = "RSA"
9+
rsa_bits = 4096
10+
}
11+
12+
resource "aws_key_pair" "generated_key" {
13+
key_name = var.key_name
14+
public_key = tls_private_key.example.public_key_openssh
15+
}
16+
17+
resource "aws_security_group" "elk_sg" {
18+
name_prefix = "elk-sg"
19+
20+
ingress {
21+
from_port = 22
22+
to_port = 22
23+
protocol = "tcp"
24+
cidr_blocks = ["0.0.0.0/0"]
25+
}
26+
27+
ingress {
28+
from_port = 80
29+
to_port = 80
30+
protocol = "tcp"
31+
cidr_blocks = ["0.0.0.0/0"]
32+
}
33+
34+
ingress {
35+
from_port = 5601
36+
to_port = 5601
37+
protocol = "tcp"
38+
cidr_blocks = ["0.0.0.0/0"]
39+
}
40+
41+
ingress {
42+
from_port = 9200
43+
to_port = 9200
44+
protocol = "tcp"
45+
cidr_blocks = ["0.0.0.0/0"]
46+
}
47+
48+
ingress {
49+
from_port = 5044
50+
to_port = 5044
51+
protocol = "tcp"
52+
cidr_blocks = ["0.0.0.0/0"]
53+
}
54+
55+
egress {
56+
from_port = 0
57+
to_port = 0
58+
protocol = "-1"
59+
cidr_blocks = ["0.0.0.0/0"]
60+
}
61+
}
62+
63+
resource "aws_instance" "elk_instance" {
64+
ami = "ami-00eeedc4036573771"
65+
instance_type = "t2.micro"
66+
key_name = aws_key_pair.generated_key.key_name
67+
security_groups = [aws_security_group.elk_sg.name]
68+
69+
user_data = <<-EOF
70+
#!/bin/bash
71+
sudo yum update -y
72+
sudo yum install docker -y
73+
sudo service docker start
74+
sudo usermod -a -G docker ec2-user
75+
sudo docker run -d -p 5601:5601 -p 9200:9200 -p 5044:5044 --name elk sebp/elk:781
76+
sudo docker run -d -p 80:8080 --name api -e ELK_HOST=http://localhost:9200 abhishek/webapp-golang-elk
77+
EOF
78+
79+
tags = {
80+
Name = "ELK-with-API"
81+
}
82+
}

tfplan

26.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)