resource "aws_s3_bucket" "this" {
  count = var.enabled ? 1 : 0
  bucket = var.bucket_name
  tags   = local.tags
}

resource "aws_s3_bucket_versioning" "this" {
  count = var.enabled ? 1 : 0
  bucket = aws_s3_bucket.this[0].id

  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
  count = var.enabled ? 1 : 0
  bucket = aws_s3_bucket.this[0].id

  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm     = local.sse_algorithm
      kms_master_key_id = var.kms_key_arn
    }
  }
}