1 | initial version |
To create a Cloudwatch Log Group with a KMS key in Terraform, you can use the following code:
resource "aws_kms_key" "example" {
description = "Example KMS Key"
}
resource "aws_cloudwatch_log_group" "example" {
name = "example-log-group"
kms_key_id = aws_kms_key.example.arn
}
In this code, we first create a KMS key using the aws_kms_key
resource. We then use the ARN of this KMS key (aws_kms_key.example.arn
) in the aws_cloudwatch_log_group
resource to specify which KMS key to use for encrypting the log data.
The aws_cloudwatch_log_group
resource also specifies the name of the log group as example-log-group
. You can replace this value with any name that you prefer.