Multiple Ingress Sources
Security groups that accept traffic from multiple sources including CIDR blocks, security groups, and prefix lists.
Multiple Security Group Sources
module "backend_sg" {
source = "registry.patterneddesigns.ca/patterneddesigns/security-group/aws"
version = "1.2.0"
name = "backend-api"
vpc_id = module.vpc.vpc_id
ingress_rules = [
{
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [module.web_sg.security_group_id]
description = "API from web tier"
},
{
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [module.worker_sg.security_group_id]
description = "API from worker nodes"
},
{
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [module.lambda_sg.security_group_id]
description = "API from Lambda functions"
}
]
egress_rules = [
{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
]
}
Mixed Source Types
module "mixed_source_sg" {
source = "registry.patterneddesigns.ca/patterneddesigns/security-group/aws"
version = "1.2.0"
name = "mixed-access"
vpc_id = module.vpc.vpc_id
ingress_rules = [
{
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTPS from internet"
},
{
from_port = 8080
to_port = 8080
protocol = "tcp"
security_groups = [module.internal_sg.security_group_id]
description = "Internal API access"
},
{
from_port = 22
to_port = 22
protocol = "tcp"
prefix_list_ids = [data.aws_ec2_managed_prefix_list.admin.id]
description = "SSH from admin networks"
}
]
egress_rules = [
{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
]
}
Port Range with Multiple CIDRs
module "port_range_sg" {
source = "registry.patterneddesigns.ca/patterneddesigns/security-group/aws"
version = "1.2.0"
name = "ephemeral-ports"
vpc_id = module.vpc.vpc_id
ingress_rules = [
{
from_port = 32768
to_port = 65535
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
description = "Ephemeral ports from private networks"
}
]
egress_rules = [
{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
]
}