This repository was archived by the owner on May 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
95 lines (89 loc) · 2.62 KB
/
Copy pathmain.tf
File metadata and controls
95 lines (89 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* ## Usage
*
* Creates a KMS key used to encrypt data-at-rest stored in CloudWatch Logs
*
* ```hcl
* module "cloudwatch_kms_key" {
* source = "dod-iac/cloudwatch-kms-key/aws"
*
* name = "alias/name"
*
* tags = {
* Application = var.application
* Environment = var.environment
* Automation = "Terraform"
* }
* }
* ```
*
* ## Testing
*
* Run all terratest tests using the `terratest` script. If using `aws-vault`, you could use `aws-vault exec $AWS_PROFILE -- terratest`. The `AWS_DEFAULT_REGION` environment variable is required by the tests. Use `TT_SKIP_DESTROY=1` to not destroy the infrastructure created during the tests. Use `TT_VERBOSE=1` to log all tests as they are run. The go test command can be executed directly, too.
*
* ## Terraform Version
*
* Terraform 0.13. Pin module version to ~> 1.0.0 . Submit pull-requests to main branch.
*
* Terraform 0.11 and 0.12 are not supported.
*
* ## License
*
* This project constitutes a work of the United States Government and is not subject to domestic copyright protection under 17 USC § 105. However, because the project utilizes code licensed from contributors and other third parties, it therefore is licensed under the MIT License. See LICENSE file for more information.
*/
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 = ["*"]
}
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 = ["*"]
}
}
resource "aws_kms_key" "cloudwatch" {
description = var.description
deletion_window_in_days = var.key_deletion_window_in_days
enable_key_rotation = "true"
policy = data.aws_iam_policy_document.cloudwatch.json
tags = var.tags
}
resource "aws_kms_alias" "cloudwatch" {
name = var.name
target_key_id = aws_kms_key.cloudwatch.key_id
}