▰▰IaC Bazaar

AWS · AWS · AWS VPC

Security Group with Rule Presets

Terraform / OpenTofuLive-tested

Security groups with named rule presets (https, postgres, redis...) using modern standalone rule resources.

Verification

Live-tested

Really deployed, verified, idempotent and destroyed in a cloud sandbox.

Conformance

  • Static validation (fmt · validate · tflint)
  • Security scan: findings disclosed (Checkov)
  • Plan tests (mocked: validation rules · outputs)

Provenance

  • SHA-256 checksum
  • Signature (pending)

Functional

  • Live-tested — applied, verified, destroyed

Last verified 2026-06-11 · how we verify

Details

Type
tf_module
Provider / collection
hashicorp/aws
Target clouds
aws
Target OS
Version
v1.0.0
License
LicenseRef-IaCBazaar-Commercial

$49.00

one-time · perpetual license + 12 months of updates

Included in the builder+ subscription.

Documentation

aws-security-group — Security Group with Rule Presets

Security groups with named rule presets (https, postgres, redis, ...) using the modern standalone rule resources (aws_vpc_security_group_ingress_rule / _egress_rule) instead of legacy inline blocks — every rule is its own API object with its own ID and tags, so rule changes never trigger whole-group diff churn. create_before_destroy and name-prefixing are wired in so the group can be replaced without breaking attached ENIs.

Works with Terraform and OpenTofu (>= 1.6), AWS provider >= 6.0, < 7.0.

Usage

module "app_sg" {
  source = "./aws-security-group"

  name        = "app"
  description = "Application tier"
  vpc_id      = module.vpc.vpc_id

  ingress_rules = [
    { preset = "https", cidr_ipv4 = "0.0.0.0/0" },
    { preset = "ssh", cidr_ipv4 = "10.0.0.0/8", description = "SSH from corp" },
    { preset = "postgres", referenced_security_group_id = module.db_sg.security_group_id },
    { from_port = 9000, to_port = 9010, ip_protocol = "tcp", self = true },
  ]

  tags = { Environment = "prod" }
}

Each rule sets a preset or explicit from_port/to_port/ip_protocol, plus exactly one source/destination: cidr_ipv4, cidr_ipv6, prefix_list_id, referenced_security_group_id, or self = true.

Presets
PresetPort/ProtoPresetPort/Proto
ssh22/tcpmysql3306/tcp
http80/tcpmssql1433/tcp
https443/tcporacle-db1521/tcp
http-alt8080/tcpredis6379/tcp
https-alt8443/tcpmemcached11211/tcp
dns-tcp / dns-udp53mongodb27017/tcp
ntp123/udprabbitmq5672/tcp
smtp-tls587/tcpkafka9092/tcp
ldap / ldaps389/636 tcpelasticsearch9200/tcp
nfs2049/tcpprometheus9090/tcp
postgres5432/tcpnode-exporter9100/tcp
grafana3000/tcpkubernetes-api6443/tcp
rdp3389/tcpwinrm-http / winrm-https5985/5986 tcp
all-icmpicmpall-traffic-1 (all)

Inputs

NameTypeDefaultDescription
namestringGroup name / Name tag (required)
vpc_idstringVPC ID (required)
descriptionstring"Managed by Terraform (IaC Bazaar)"Group description (forces replacement on change)
use_name_prefixbooltrueRandom-suffix the name for safe replacement
ingress_ruleslist(object)[]Ingress rules (preset or explicit, see above)
egress_ruleslist(object)[]Egress rules, same shape
allow_all_egressbooltrueCreate allow-all IPv4+IPv6 egress; set false for least-privilege egress
revoke_rules_on_deleteboolfalseRevoke rules before delete (cross-referencing groups)
tagsmap(string){}Tags for the group and every rule

Outputs

NameDescription
security_group_id / security_group_arn / security_group_nameGroup identifiers
ingress_rule_ids / egress_rule_idsRule-index => rule-ID maps
allow_all_egress_rule_idsIDs of the default egress rules

Notes

  • Rules are keyed by list index: reordering ingress_rules re-creates the affected rules. That is a fast, zero-downtime API operation.
  • self = true is implemented as referenced_security_group_id pointing at the group itself (the standalone-rule equivalent of legacy self).

Requirements

  • Terraform or OpenTofu >= 1.6
  • hashicorp/aws >= 6.0, < 7.0

Verification

Static-validated (fmt, validate, tflint). Live apply/destroy testing pending cloud sandbox availability — see catalog status.

License

Commercial — IaC Bazaar EULA. © IaC Bazaar. Original work (not derived from a third-party module).