forked from pythianali/TF-Ansible-ELK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.tf
109 lines (80 loc) · 2.7 KB
/
instance.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
# Logstash
resource "aws_instance" "Logstash" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
# the VPC subnet
subnet_id = "${aws_subnet.Subnet-Public-TF-Ansible-ELK.id}"
# the security group
vpc_security_group_ids = ["${aws_security_group.TF-Ansible-ELK-SG.id}"]
# the public SSH key
key_name = "${var.KEY_NAME}"
tags {
Name = "Logstash-TF-Ansible-ELK"
AccountID = "${data.aws_caller_identity.current.account_id}"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"sudo apt-get install python python-apt python-pip python-pycurl openjdk-8-jdk-headless -y",
]
}
provisioner "local-exec" {
command = "ansible-playbook ansible/playbooks/logstash.yaml --ssh-common-args='-o StrictHostKeyChecking=no' -u ${var.INSTANCE_USERNAME} --private-key ${var.LOCAL_KEY_NAME} -i terraform.py/terraform.py"
}
connection {
user = "${var.INSTANCE_USERNAME}"
private_key = "${file("${var.LOCAL_KEY_NAME}")}"
}
}
# Kibana
resource "aws_instance" "Kibana" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
# the VPC subnet
subnet_id = "${aws_subnet.Subnet-Public-TF-Ansible-ELK.id}"
# the security group
vpc_security_group_ids = ["${aws_security_group.TF-Ansible-ELK-SG.id}"]
# the public SSH key
key_name = "${var.KEY_NAME}"
tags {
Name = "Kibana-TF-Ansible-ELK"
AccountID = "${data.aws_caller_identity.current.account_id}"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get install python python-apt -y",
]
}
connection {
user = "${var.INSTANCE_USERNAME}"
private_key = "${file("${var.LOCAL_KEY_NAME}")}"
}
}
# Elasticsearch
resource "aws_instance" "Elasticsearch" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
# the VPC subnet
subnet_id = "${aws_subnet.Subnet-Public-TF-Ansible-ELK.id}"
# the security group
vpc_security_group_ids = ["${aws_security_group.TF-Ansible-ELK-SG.id}"]
# the public SSH key
key_name = "${var.KEY_NAME}"
tags {
Name = "Elasticsearch-TF-Ansible-ELK"
AccountID = "${data.aws_caller_identity.current.account_id}"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"sudo apt-get install python python-apt python-pip python-pycurl -y",
]
}
provisioner "local-exec" {
command = "ansible-playbook ansible/playbooks/elasticsearch.yaml --ssh-common-args='-o StrictHostKeyChecking=no' -u ${var.INSTANCE_USERNAME} --private-key ${var.LOCAL_KEY_NAME} -i terraform.py/terraform.py"
}
connection {
user = "${var.INSTANCE_USERNAME}"
private_key = "${file("${var.LOCAL_KEY_NAME}")}"
}
}