Skip to content

Commit 8f9da01

Browse files
Create ec2.tf
1 parent a23e394 commit 8f9da01

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

ec2.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
resource "aws_key_pair" "deployer" {
2+
key_name = "terra-automate-key"
3+
public_key = file("terra-key.pub")
4+
}
5+
6+
resource "aws_default_vpc" "default" {
7+
8+
}
9+
10+
resource "aws_security_group" "allow_user_to_connect" {
11+
name = "allow TLS"
12+
description = "Allow user to connect"
13+
vpc_id = aws_default_vpc.default.id
14+
ingress {
15+
description = "port 22 allow"
16+
from_port = 22
17+
to_port = 22
18+
protocol = "tcp"
19+
cidr_blocks = ["0.0.0.0/0"]
20+
}
21+
22+
egress {
23+
description = " allow all outgoing traffic "
24+
from_port = 0
25+
to_port = 0
26+
protocol = "-1"
27+
cidr_blocks = ["0.0.0.0/0"]
28+
}
29+
30+
ingress {
31+
description = "port 80 allow"
32+
from_port = 80
33+
to_port = 80
34+
protocol = "tcp"
35+
cidr_blocks = ["0.0.0.0/0"]
36+
}
37+
38+
ingress {
39+
description = "port 443 allow"
40+
from_port = 443
41+
to_port = 443
42+
protocol = "tcp"
43+
cidr_blocks = ["0.0.0.0/0"]
44+
}
45+
46+
tags = {
47+
Name = "mysecurity"
48+
}
49+
}
50+
51+
resource "aws_instance" "testinstance" {
52+
ami = var.ami_id
53+
instance_type = var.instance_type
54+
key_name = aws_key_pair.deployer.key_name
55+
security_groups = [aws_security_group.allow_user_to_connect.name]
56+
tags = {
57+
Name = "Terra-Automate"
58+
}
59+
root_block_device {
60+
volume_size = 10
61+
volume_type = "gp3"
62+
}
63+
}

0 commit comments

Comments
 (0)