// terraform-aws-security-baseline

Comprehensive AWS account security baseline with GuardDuty, Security Hub, AWS Config, CloudTrail, Macie, IAM Access Analyzer, Detective, and IAM hardening.

Terraform ≥ 1.5.0 AWS ≥ 5.20.0 MIT License

Executive Summary

This module establishes a production-grade security baseline for AWS accounts. It enables and configures eight core security services: GuardDuty for threat detection (S3, EKS, malware), Security Hub for centralized findings with CIS and FSBP standards, AWS Config for resource compliance, CloudTrail for API audit logging with KMS encryption and CloudWatch integration, Macie for sensitive data discovery, IAM Access Analyzer for external access detection, Detective for investigation, and IAM password policy enforcement. All services are toggleable and every resource follows consistent naming and tagging.

Overview

8

Security Services

GuardDuty, Security Hub, Config, CloudTrail, Macie, Access Analyzer, Detective, IAM Policy

6

Compliance Frameworks

CIS 1.4, FSBP, SOC 2, PCI DSS, HIPAA, NIST 800-53

3

Sub-Modules

guardduty-org, scp-baseline, iam-baseline

30+

Input Variables

Granular control over every security service and policy setting

Architecture Diagram

GuardDutyS3, EKS, Malware
DetectiveInvestigation
Security HubCIS 1.4, FSBP
AWS ConfigResource compliance
CloudTrailAPI logging + KMS
MacieS3 sensitive data
Access AnalyzerExternal access
CloudWatch Logs365-day retention
S3 BucketsConfig + CloudTrail delivery
KMS KeyCloudTrail encryption
IAM Password PolicyCIS Controls
Break-Glass Useriam-baseline module
Audit Rolesiam-baseline module

Component Breakdown

ServiceResource(s)Purpose
GuardDutyaws_guardduty_detectorContinuous threat detection with S3, EKS, and malware protection
Security Hubaws_securityhub_account, standards_subscriptionCentralized security findings with CIS and FSBP standards
AWS Configaws_config_configuration_recorder, delivery_channelResource inventory, configuration history, compliance auditing
CloudTrailaws_cloudtrail, aws_cloudwatch_log_group, aws_kms_keyMulti-region API logging with KMS encryption and CloudWatch integration
Macieaws_macie2_accountAutomated sensitive data discovery in S3 buckets
Access Analyzeraws_accessanalyzer_analyzerIdentifies resources shared with external entities (ACCOUNT or ORGANIZATION)
Detectiveaws_detective_graphSecurity investigation and root cause analysis
IAM Password Policyaws_iam_account_password_policyEnforces min 14 char, symbols, numbers, 90-day max age, 24 reuse prevention

Data Flow

API Calls
CloudTrail
CloudWatch Logs
Security Hub
GuardDuty Findings

All security services feed findings into Security Hub for centralized visibility. CloudTrail logs are encrypted with KMS and stored in both CloudWatch and S3. Config compliance results feed into Security Hub standards checks.

Security Controls

Multi-Region CloudTrail

API logging across all regions with log file integrity validation and CloudTrail Insights

KMS Encryption

CloudTrail logs encrypted with dedicated KMS key, auto-created if not provided

CIS Benchmark 1.4

Maps to CIS controls 1.5-1.11, 2.1-2.3, 3.1-3.7, 4.1-4.15, 5.1

IAM Hardening

14-char minimum password, 90-day rotation, 24-password reuse prevention

Threat Intelligence

GuardDuty S3 protection, EKS audit logs, malware scanning for EBS

Data Protection

Macie discovers PII/sensitive data in S3, Access Analyzer detects external sharing

Industry Adaptation

FrameworkCoverage
CIS AWS Foundations 1.4Automated controls for IAM, logging, monitoring, networking
AWS FSBPAWS-defined security standards via Security Hub
SOC 2 Type IILogging, monitoring, and access control controls
PCI DSSEncryption, access logging, and change detection
HIPAAAudit logging, encryption, and access controls
NIST 800-53Security and privacy controls via Security Hub mapping

Production Readiness Checklist

Configuration Reference

Required Variables

VariableTypeDescription
name_prefixstringPrefix for all named resources

Key Optional Variables

VariableDefaultDescription
enable_guarddutytrueEnable GuardDuty
enable_security_hubtrueEnable Security Hub
enable_configtrueEnable AWS Config
enable_cloudtrailtrueEnable CloudTrail
enable_macietrueEnable Macie
enable_access_analyzertrueEnable IAM Access Analyzer
enable_detectivefalseEnable Detective
enable_iam_password_policytrueConfigure IAM password policy
password_policy_min_length14Minimum password length
cloudtrail_is_multi_regiontrueMulti-region trail

Deployment

module "security_baseline" {
  source = "kogunlowo123/security-baseline/aws"

  name_prefix               = "myapp"
  config_delivery_s3_bucket = "myapp-config-bucket"
  cloudtrail_s3_bucket_name = "myapp-cloudtrail-bucket"

  tags = {
    Project   = "security-baseline"
    ManagedBy = "terraform"
  }
}

Links

Amazon GuardDuty
AWS Security Hub
AWS Config
AWS CloudTrail
CIS AWS Foundations Benchmark