
data "aws_iam_policy_document" "ownership_ingestion_rw_policy_document" {
  statement {
    effect = "Allow"

    actions = [
      "s3:ListBucket",
      "s3:GetBucketLocation"
    ]

    resources = [
      module.s3_bucket.s3_bucket_arn_output
    ]
  }

  statement {
    effect = "Allow"

    actions = [
      "s3:GetObject",
      "s3:PutObject",
      "s3:DeleteObject",
      "s3:ListObjectsV2",
    ]

    resources = [
      "${module.s3_bucket.s3_bucket_arn_output}/ownership/ingestion/*",
    ]
  }
}

resource "aws_iam_policy" "ownership_ingestion_rw_policy" {
  name        = "S3-${module.s3_bucket.s3_bucket_name_output}-ownership-ingestion-RW"
  description = "Read Write access to ownership/ingestion folder in neighbouring rights bucket"
  policy      = data.aws_iam_policy_document.ownership_ingestion_rw_policy_document.json
}


data "aws_iam_policy_document" "ownership_migration_putonly_policy_document" {
  statement {
    effect = "Allow"

    actions = [
      "s3:PutObject",
    ]

    resources = [
      "${module.s3_bucket.s3_bucket_arn_output}/ownership/migration/*",
    ]
  }
}

resource "aws_iam_policy" "ownership_migration_putonly_policy" {
  name        = "S3-${module.s3_bucket.s3_bucket_name_output}-ownership-migration-WO"
  description = "Write access to ownership/migration folder in neighbouring rights bucket"
  policy      = data.aws_iam_policy_document.ownership_migration_putonly_policy_document.json
}
