Skip to content

Instantly share code, notes, and snippets.

@snassr
Last active November 12, 2023 02:00
Show Gist options
  • Save snassr/1809db0ed6a889161e300e4c9e9dbd50 to your computer and use it in GitHub Desktop.
Save snassr/1809db0ed6a889161e300e4c9e9dbd50 to your computer and use it in GitHub Desktop.
medium_blog_652A1BBE_awsnetworking_vpc_subnet02_ec2.tf
resource "aws_instance" "awsnetblog_vpc_01-subnet_02_private-ec2_01" {
ami = "ami-03f65b8614a860c29"
instance_type = "t2.micro"
subnet_id = aws_subnet.awsnetblog_vpc_01-subnet_02_private.id
key_name = aws_key_pair.awsnetblog_vpc_01-keypair_01.key_name
vpc_security_group_ids = [
aws_security_group.awsnetblog_vpc_01-subnet_02_private-sg_01.id
]
tags = {
"Name" = "awsnetblog_vpc_01-subnet_02_private-ec2_01"
"Project" = var.project
}
}
resource "aws_security_group" "awsnetblog_vpc_01-subnet_02_private-sg_01" {
name = "awsnetblog_vpc_01-subnet_02_private-sg_01"
description = "Allow private EC2 traffic"
vpc_id = aws_vpc.awsnetblog_vpc_01.id
tags = {
"Name" = "awsnetblog_vpc_01-subnet_02_private-sg_01"
"Project" = var.project
}
}
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_02_private-sg_01-sgrule_01" {
type = "ingress"
description = "Allow ingress SSH"
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_02_private-sg_01.id
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.1.0.0/16"]
}
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_02_private-sg_01-sgrule_02" {
type = "egress"
description = "Allow egress SSH"
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_02_private-sg_01.id
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.1.0.0/16"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment