module "transporter_logs_bucket" {
  source = "git@github.com:theorchard/terraform-s3.git//modules/s3_bucket?ref=3.13.0"

  env                = var.environment
  bucket_name        = "transporter-logs"
  application_family = var.application_family

  apply_server_side_encryption_by_default = {
    sse_algorithm = "AES256"
  }

  lifecycle_rules_options_noncurrent_version_expiration = [
    {
      prefix        = ""
      enabled       = true
      days          = 180
      storage_class = "GLACIER"
    }
  ]

  lifecycle_rules_options_current_version_expiration = [
    {
      prefix        = ""
      enabled       = true
      days          = 180
      storage_class = "GLACIER"
    }
  ]
}

data "aws_iam_policy_document" "transporter_logs_bucket_rw_policy_document" {
  statement {
    actions = [
      "s3:GetObject",
      "s3:PutObject",
      "s3:DeleteObject",
    ]

    resources = [
      "${module.transporter_logs_bucket.s3_bucket_arn_output}/*",
    ]
  }
}

resource "aws_iam_policy" "transporter_logs_bucket_rw_policy" {
  name   = "S3-transporter-logs-RW"
  policy = data.aws_iam_policy_document.transporter_logs_bucket_rw_policy_document.json
}
