Last active
November 12, 2023 02:00
-
-
Save snassr/710dcac2856eb83de78b8249ef4b4c37 to your computer and use it in GitHub Desktop.
medium_blog_652A1BBE_awsnetworking_vpc_subnet01_ec2.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_instance" "awsnetblog_vpc_01-subnet_01_public-ec2_01" { | |
ami = "ami-03f65b8614a860c29" | |
instance_type = "t2.micro" | |
subnet_id = aws_subnet.awsnetblog_vpc_01-subnet_01_public.id | |
key_name = aws_key_pair.awsnetblog_vpc_01-keypair_01.key_name | |
vpc_security_group_ids = [ | |
aws_security_group.awsnetblog_vpc_01-subnet_01_public-sg_01.id | |
] | |
tags = { | |
"Name" = "awsnetblog_vpc_01-subnet_01_public-ec2_01" | |
"Project" = var.project | |
} | |
} | |
resource "aws_eip" "awsnetblog_vpc_01-subnet_01_public-ec2_01-eip_01" { | |
tags = { | |
"Name" = "awsnetblog_vpc_01-subnet_01_public-ec2_01-eip_01" | |
"Project" = var.project | |
} | |
} | |
resource "aws_eip_association" "awsnetblog_vpc_01-subnet_01_public-ec2_01-eip_01-ec2_assoc" { | |
instance_id = aws_instance.awsnetblog_vpc_01-subnet_01_public-ec2_01.id | |
allocation_id = aws_eip.awsnetblog_vpc_01-subnet_01_public-ec2_01-eip_01.id | |
} | |
resource "aws_security_group" "awsnetblog_vpc_01-subnet_01_public-sg_01" { | |
name = "awsnetblog_vpc_01-subnet_01_public-sg_01" | |
description = "Allow public EC2 traffic" | |
vpc_id = aws_vpc.awsnetblog_vpc_01.id | |
tags = { | |
"Name" = "awsnetblog_vpc_01-subnet_01_public-sg_01" | |
"Project" = var.project | |
} | |
} | |
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_01_public-sg_01-sgrule_01" { | |
type = "egress" | |
description = "Allow egress HTTP on 80" | |
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_01_public-sg_01.id | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_01_public-sg_01-sgrule_02" { | |
type = "egress" | |
description = "Allow egress HTTP 443" | |
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_01_public-sg_01.id | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_01_public-sg_01-sgrule_05" { | |
type = "ingress" | |
description = "Allow ingress SSH" | |
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_01_public-sg_01.id | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
resource "aws_security_group_rule" "awsnetblog_vpc_01-subnet_01_public-sg_01-sgrule_06" { | |
type = "egress" | |
description = "Allow egress SSH" | |
security_group_id = aws_security_group.awsnetblog_vpc_01-subnet_01_public-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