-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.tf
74 lines (67 loc) · 2.32 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
# ---------------------------------------------------------------------------------------------------------------------
# data
# ---------------------------------------------------------------------------------------------------------------------
# get default vpc id
data "aws_vpc" "default" {
default = true
}
# get subnet ids
data "aws_subnet_ids" "subnets" {
vpc_id = data.aws_vpc.default.id
}
# get latest ubuntu 18 ami
data "aws_ami" "ami" {
owners = ["099720109477"] # canonical
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
# get my external ip
data "http" "myip" {
url = "http://ifconfig.me"
}
# ---------------------------------------------------------------------------------------------------------------------
# security group
# ---------------------------------------------------------------------------------------------------------------------
module "security-group" {
source = "terraform-aws-modules/security-group/aws"
version = "3.17.0"
name = "${var.prefix_name}-elk"
vpc_id = data.aws_vpc.default.id
ingress_cidr_blocks = ["${data.http.myip.body}/32"]
ingress_rules = [
"elasticsearch-rest-tcp",
"elasticsearch-java-tcp",
"kibana-tcp",
"logstash-tcp",
"ssh-tcp"
]
ingress_with_self = [{ rule = "all-all" }]
egress_rules = ["all-all"]
}
# ---------------------------------------------------------------------------------------------------------------------
# ec2
# ---------------------------------------------------------------------------------------------------------------------
module "ec2-instance" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "2.16.0"
instance_count = var.instance_count
name = "${var.prefix_name}-elk"
instance_type = "t3.medium"
ami = data.aws_ami.ami.id
key_name = var.ssh_key_name
subnet_id = tolist(data.aws_subnet_ids.subnets.ids)[0]
vpc_security_group_ids = [module.security-group.this_security_group_id]
associate_public_ip_address = true
user_data = file("./userdata.sh")
tags = {
Terraform = "true"
Environment = "dev"
}
}