-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
94 lines (77 loc) · 1.91 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
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_key_pair" "qcard-keypair" {
key_name = "qcard-kafka-key"
public_key = file("${path.module}/ssh/id_rsa.pub")
}
output "key_pair_name" {
value = aws_key_pair.qcard-keypair.key_name
}
resource "aws_security_group" "kafka-security-group" {
name = "qcardKafkaSecurityGroup"
description = "Security Group for Kafka"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 9092
to_port = 9092
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_instance" "qcard-kafka" {
ami = "ami-09eb4311cbaecf89d"
instance_type = "t2.micro"
key_name = aws_key_pair.qcard-keypair.key_name
vpc_security_group_ids = [aws_security_group.kafka-security-group.id]
associate_public_ip_address = true
root_block_device {
volume_type = "gp2"
volume_size = 30
}
tags = {
Name = "qcard-kafka"
}
provisioner "file" {
source = "./kafka/docker-compose.yaml"
destination = "/home/ubuntu/docker-compose.yaml"
connection {
type = "ssh"
user = "ubuntu"
private_key = file("${path.module}/ssh/id_rsa")
host = aws_instance.qcard-kafka.public_ip
}
}
provisioner "remote-exec" {
inline = [
"sudo apt update",
"sudo snap install docker",
"sudo service docker start",
"sudo usermod -aG docker $USER",
"sudo docker-compose -f ./docker-compose.yaml up -d"
]
connection {
type = "ssh"
user = "ubuntu"
private_key = file("${path.module}/ssh/id_rsa")
host = aws_instance.qcard-kafka.public_ip
}
}
}