This template creates a CloudFront public key and a key group that includes the public key.

Terraform Template

resource "aws_cloudfront_key_group" "example" {
  comment = "example key group"
  items = [aws_cloudfront_public_key.example.id]
  name = "example-key-group"
}

resource "aws_cloudfront_public_key" "example" {
  comment = "example public key"
  encoded_key = file("public_key.pem")
  name = "example-key"
}