Created
May 13, 2019 02:35
-
-
Save mschirbel/052baa3608f37a22e6062d513e091da3 to your computer and use it in GitHub Desktop.
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_security_group" "nat" { | |
name = "vpc_nat" | |
description = "Can access both subnets" | |
ingress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["${var.private_subnet_cidr}"] | |
} | |
ingress { | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["${var.private_subnet_cidr}"] | |
} | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = -1 | |
to_port = -1 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["${var.vpc_cidr}"] | |
} | |
egress { | |
from_port = -1 | |
to_port = -1 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
tags { | |
Name = "NATSG" | |
} | |
} | |
resource "aws_security_group" "web" { | |
name = "vpc_web" | |
description = "Allow incoming HTTP connections." | |
ingress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = -1 | |
to_port = -1 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { # MySQL | |
from_port = 3306 | |
to_port = 3306 | |
protocol = "tcp" | |
cidr_blocks = ["${var.private_subnet_cidr}"] | |
} | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
tags { | |
Name = "WebServerSG" | |
} | |
} | |
resource "aws_security_group" "db" { | |
name = "vpc_db" | |
description = "Allow incoming database connections." | |
ingress { # MySQL | |
from_port = 3306 | |
to_port = 3306 | |
protocol = "tcp" | |
security_groups = ["${aws_security_group.web.id}"] | |
} | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["${var.vpc_cidr}"] | |
} | |
ingress { | |
from_port = -1 | |
to_port = -1 | |
protocol = "icmp" | |
cidr_blocks = ["${var.vpc_cidr}"] | |
} | |
egress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
tags { | |
Name = "DBServerSG" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment