data "aws_caller_identity" "current" {} data "aws_partition" "current" {} data "aws_region" "current" {} data "aws_iam_policy_document" "cloudwatch" { policy_id = "key-policy-cloudwatch" statement { sid = "Enable IAM User Permissions" actions = [ "kms:*", ] effect = "Allow" principals { type = "AWS" identifiers = [ format( "arn:%s:iam::%s:root", data.aws_partition.current.partition, data.aws_caller_identity.current.account_id ) ] } resources = [format( "arn:%s:kms:%s:%s:key/*", data.aws_partition.current.partition, data.aws_region.current.name, data.aws_caller_identity.current.account_id )] } statement { sid = "AllowCloudWatchLogs" actions = [ "kms:Encrypt*", "kms:Decrypt*", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:Describe*" ] effect = "Allow" principals { type = "Service" identifiers = [ format( "logs.%s.amazonaws.com", data.aws_region.current.name ) ] } resources = [format( "arn:%s:kms:%s:%s:key/*", data.aws_partition.current.partition, data.aws_region.current.name, data.aws_caller_identity.current.account_id )] } }