-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.tf
More file actions
57 lines (53 loc) · 1.23 KB
/
Copy pathmain.tf
File metadata and controls
57 lines (53 loc) · 1.23 KB
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
resource "aws_security_group" "sg" {
name = "${var.name}-sg"
vpc_id = var.vpc_id
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 = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.0.0.0/8"]
}
ingress {
from_port = -1
to_port = -1
protocol = "ICMP"
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" "instance" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_size
key_name = aws_key_pair.key.key_name
subnet_id = var.subnet_id
associate_public_ip_address = var.public_ip
security_groups = [aws_security_group.sg.id]
user_data = var.user_data
lifecycle {
ignore_changes = [security_groups]
}
tags = {
Name = "${var.name}-srv"
}
}
resource "aws_key_pair" "key" {
key_name = "${var.name}-key"
public_key = var.ssh_key
}