PSA-compliant 3-tier security group architecture with mandatory rule descriptions and zero-egress database defaults.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Full auto-generated documentation of inputs, outputs, and resources: TERRAFORM-DOCS.md
Table of Contents
This module implements a hardened 3-tier network security architecture (Web, App, Database) plus a dedicated Management tier. It enforces mandatory descriptions for all firewall rules to ensure auditability and PSA compliance.
- 3-Tier Isolation: Pre-configured flows between tiers (Web -> App -> DB).
- Mandatory Descriptions: Every ingress/egress rule must have a human-readable description.
- Zero-Egress Database: The database tier is configured with NO outbound rules by default.
- HTTPS Enforcement: Web tier defaults to port 443 with optional port 80.
- Management Tier: Dedicated SG for restricted SSH/RDP access.
- Custom Rules: Support for injecting project-specific rules while maintaining the base security posture.
module "security_groups" {
source = "./terraform-aws-security-groups"
project_name = "myapp"
environment = "prod"
vpc_id = "vpc-12345678"
name_prefix = "myapp-prod"
allowed_web_cidrs = ["0.0.0.0/0"]
allowed_management_cidrs = ["203.0.113.0/24"]
app_port = 8080
db_port = 5432
}module "sg" {
source = "./terraform-aws-security-groups"
project_name = "complex-app"
environment = "prod"
vpc_id = module.vpc.vpc_id
name_prefix = "complex-app"
allowed_management_cidrs = ["203.0.113.0/24"]
web_custom_ingress = [
{
from_port = 8443
to_port = 8443
protocol = "tcp"
cidr_blocks = ["1.2.3.4/32"]
description = "Custom management webhook"
}
]
}- Description Enforcement: Prevents the creation of "blind" firewall rules.
- Lateral Movement Protection: Rules are strictly limited to the necessary target security groups.
- No Wide-Open Egress: All tiers have scoped egress; DB tier has NONE.
- Management Lockdown: SSH/RDP access is disabled by default and requires explicit CIDR whitelisting.
- ICMP Disabled: Standard ping/discovery is disabled by default to reduce the attack surface.
This module implements the following PSA compliance features (referencing 10-Strukturierte_PSA_Anforderungen_Netzwerk_LLM.pdf):
- Req 6 (Access Control): Strict ACL-like protection for management interfaces.
- Req 14 (L7 Inspection): Designed to sit behind ALB/WAF for deep inspection.
- Req 3.66-04 (Isolation): Consistent naming and tagging for multi-tenant isolation.
- Auditability: Mandatory descriptions ensure every rule is traceable to a requirement.
- Verify the
app_portordb_portmatches your application configuration. - Check that the resources (e.g., EC2, RDS) are actually assigned to the correct security group IDs output by this module.
- Ensure your IP is included in
allowed_management_cidrs. - Verify the
create_management_sg = true.
| Name | Version |
|---|---|
| terraform | >=1.3 |
| Name | Version |
|---|---|
| aws | n/a |
No modules.
| Name | Type |
|---|---|
| aws_security_group.app_tier | resource |
| aws_security_group.db_tier | resource |
| aws_security_group.management | resource |
| aws_security_group.web_tier | resource |
| aws_security_group_rule.app_custom | resource |
| aws_security_group_rule.app_from_web_ingress | resource |
| aws_security_group_rule.app_https_egress | resource |
| aws_security_group_rule.app_to_db_egress | resource |
| aws_security_group_rule.db_from_app_ingress | resource |
| aws_security_group_rule.mgmt_https_egress | resource |
| aws_security_group_rule.mgmt_rdp_ingress | resource |
| aws_security_group_rule.mgmt_ssh_egress | resource |
| aws_security_group_rule.mgmt_ssh_ingress | resource |
| aws_security_group_rule.web_custom | resource |
| aws_security_group_rule.web_http_ingress | resource |
| aws_security_group_rule.web_https_egress | resource |
| aws_security_group_rule.web_https_ingress | resource |
| aws_security_group_rule.web_to_app_egress | resource |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| allow_http | Allow HTTP (port 80) traffic - HTTPS (443) is always enabled | bool |
false |
no |
| allow_rdp | Allow RDP (port 3389) for Windows management | bool |
false |
no |
| allowed_https_egress_cidrs | CIDR blocks allowed for HTTPS egress from managed security groups | list(string) |
[ |
no |
| allowed_management_cidrs | CIDR blocks allowed for management access | list(string) |
n/a | yes |
| allowed_web_cidrs | CIDR blocks allowed to access the web tier | list(string) |
[ |
no |
| app_custom_ingress | List of custom ingress rules for app tier | list(object({ |
[] |
no |
| app_port | Port for application tier communication | number |
8080 |
no |
| app_tier_sg_ids | List of application tier security group IDs (if not creating app tier SG) | list(string) |
[] |
no |
| create_app_tier_sg | Create security group for application tier | bool |
true |
no |
| create_db_tier_sg | Create security group for database tier | bool |
true |
no |
| create_management_sg | Create security group for management/bastion access | bool |
true |
no |
| create_web_tier_sg | Create security group for web tier | bool |
true |
no |
| db_port | Port for database communication | number |
5432 |
no |
| db_tier_sg_ids | List of database tier security group IDs (if not creating db tier SG) | list(string) |
[] |
no |
| environment | Environment (e.g., prod, dev, test) | string |
n/a | yes |
| internal_cidrs | Internal CIDR blocks for management access | list(string) |
[ |
no |
| name_prefix | Prefix for resource names (if not provided, will use project-environment pattern) | string |
"" |
no |
| project_name | Name of the project | string |
n/a | yes |
| tags | Additional tags for all resources | map(string) |
{} |
no |
| vpc_id | ID of the VPC where security groups will be created | string |
n/a | yes |
| web_custom_ingress | List of custom ingress rules for web tier | list(object({ |
[] |
no |
| web_tier_sg_ids | List of web tier security group IDs (if not creating web tier SG) | list(string) |
[] |
no |
| Name | Description |
|---|---|
| app_tier_sg_arn | The ARN of the application tier security group |
| app_tier_sg_id | The ID of the application tier security group |
| app_tier_sg_name | The name of the application tier security group |
| db_tier_sg_arn | The ARN of the database tier security group |
| db_tier_sg_id | The ID of the database tier security group |
| db_tier_sg_name | The name of the database tier security group |
| management_sg_arn | The ARN of the management security group |
| management_sg_id | The ID of the management security group |
| management_sg_name | The name of the management security group |
| security_group_ids | Map of managed security group IDs |
| security_group_names | Map of managed security group names |
| web_tier_sg_arn | The ARN of the web tier security group |
| web_tier_sg_id | The ID of the web tier security group |
| web_tier_sg_name | The name of the web tier security group |