Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8b6fb84

Browse files
committedJan 4, 2023
creating the EC2 instance
1 parent 6a176fd commit 8b6fb84

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
 

‎ec2_instance.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
resource "aws_instance" "web" {
2+
ami = var.aws_ami
3+
instance_type = var.instance_type
4+
key_name = aws_key_pair.key.key_name
5+
subnet_id = aws_subnet.my_subnet.id
6+
//security_groups = aws_security_group.my_security_group.name
7+
vpc_security_group_ids = [aws_security_group.my_security_group.id]
8+
associate_public_ip_address = true
9+
10+
tags = {
11+
Name = "Amaury"
12+
managed_by = "terraform"
13+
}
14+
}
15+
16+
resource "aws_security_group" "my_security_group" {
17+
name = "security_group_terraform"
18+
vpc_id = aws_vpc.my_vpc.id
19+
20+
ingress {
21+
//description = "SSH from VPC"
22+
from_port = 22
23+
to_port = 22
24+
protocol = "tcp"
25+
cidr_blocks = ["0.0.0.0/0"]
26+
}
27+
28+
egress {
29+
from_port = 0
30+
to_port = 0
31+
protocol = "-1"
32+
cidr_blocks = ["0.0.0.0/0"]
33+
}
34+
}
35+
36+
resource "aws_key_pair" "key" {
37+
key_name = "aws-key"
38+
public_key = file("./aws-key.pub")
39+
40+
tags = {
41+
Name = "my-key-aws"
42+
managed_by = "terraform"
43+
}
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.