-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
73 lines (63 loc) · 1.31 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
data "aws_ami" "amazon-linux-2" {
owners = ["amazon"]
most_recent = true
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "name"
values = ["amzn2-ami-kernel-5.10-hvm*"]
}
}
data "template_file" "userdata" {
template = file("${abspath(path.module)}/userdata.sh")
vars = {
server-name = var.server-name
}
}
resource "aws_instance" "tfmyec2" {
ami = data.aws_ami.amazon-linux-2.id
instance_type = var.instance_type
count = var.num_of_instance
key_name = var.key_name
vpc_security_group_ids = [aws_security_group.tf-sec-gr.id]
user_data = data.template_file.userdata.rendered
tags = {
Name = var.tag
}
}
resource "aws_security_group" "tf-sec-gr" {
name = "${var.tag}-terraform-sec-grp"
tags = {
Name = var.tag
}
dynamic "ingress" {
for_each = var.docker-instance-ports
iterator = port
content {
from_port = port.value
to_port = port.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port =0
protocol = "-1"
to_port =0
cidr_blocks = ["0.0.0.0/0"]
}
}