This template configures an S3 bucket with server-side encryption using an AWS KMS key.

Terraform Template

resource "aws_kms_key" "mykey" {
  deletion_window_in_days = 10
  description = "This key is used to encrypt bucket objects"
}

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

resource "aws_s3_bucket_server_side_encryption_configuration" "example" {
  bucket = aws_s3_bucket.mybucket.id

  rule {

    apply_server_side_encryption_by_default {
      kms_master_key_id = aws_kms_key.mykey.arn
      sse_algorithm = "aws:kms"
    }
  }
}