This template sets up an S3 bucket with Object Lock configuration in compliance mode for 5 days.

Terraform Template

resource "aws_s3_bucket" "example" {
  bucket = "mybucket"
}

resource "aws_s3_bucket_object_lock_configuration" "example" {
  bucket = aws_s3_bucket.example.id

  rule {

    default_retention {
      days = 5
      mode = "COMPLIANCE"
    }
  }
}

resource "aws_s3_bucket_versioning" "example" {
  bucket = aws_s3_bucket.example.id

  versioning_configuration {
    status = "Enabled"
  }
}