# main.tf — DAT violations fixture
# Triggers all 9 DAT policy violations

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "ap-south-1"
}

# DAT-001 + DAT-002 + DAT-003 + DAT-004 + DAT-005
resource "aws_db_instance" "bad_rds" {
  identifier                 = "bad-rds"
  engine                     = "mysql"
  engine_version             = "8.0"
  instance_class             = "db.t3.micro"
  allocated_storage          = 20
  username                   = "admin"
  password                   = "Badpassword123"
  publicly_accessible        = true
  storage_encrypted          = false
  deletion_protection        = false
  auto_minor_version_upgrade = false
  skip_final_snapshot        = true
}

# DAT-006 — DynamoDB without PITR
resource "aws_dynamodb_table" "bad_table" {
  name         = "bad-table"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "id"

  attribute {
    name = "id"
    type = "S"
  }

  point_in_time_recovery {
    enabled = false
  }
}

# DAT-007 + DAT-008 — Redshift publicly accessible, no logging resource
resource "aws_redshift_cluster" "bad_redshift" {
  cluster_identifier  = "bad-redshift"
  database_name       = "baddb"
  master_username     = "admin"
  master_password     = "Badpassword123"
  node_type           = "dc2.large"
  cluster_type        = "single-node"
  publicly_accessible = true
  skip_final_snapshot = true
}

# No aws_redshift_logging resource = DAT-008 violation

# DAT-009 — ElastiCache without encryption
resource "aws_elasticache_replication_group" "bad_redis" {
  replication_group_id       = "bad-redis"
  description                = "bad redis"
  node_type                  = "cache.t3.micro"
  num_cache_clusters         = 1
  transit_encryption_enabled = false
  at_rest_encryption_enabled = false
}
