-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
66 lines (57 loc) · 1.21 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
data "aws_ami" "amazon-linux-2023" {
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 = ["al2023-ami-2023*"]
}
}
resource "aws_instance" "tfmyec2" {
ami = data.aws_ami.amazon-linux-2023.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 = templatefile("${abspath(path.module)}/userdata.sh", {myserver = var.server-name})
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"]
}
}