-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
69 lines (63 loc) · 1.79 KB
/
main.tf
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
/**
* ## Usage
*
* Creates a KMS key used to encrypt data-at-rest stored in ECR.
*
* ```hcl
* module "ecr_kms_key" {
* source = "dod-iac/ecr-kms-key/aws"
*
* tags = {
* Application = var.application
* Environment = var.environment
* Automation = "Terraform"
* }
* }
* ```
*
* ## Terraform Version
*
* Terraform 0.12. Pin module version to ~> 1.0.0 . Submit pull-requests to master branch.
*
* Terraform 0.11 is 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" {}
// See https://docs.aws.amazon.com/AmazonECR/latest/userguide/encryption-at-rest.html
data "aws_iam_policy_document" "ecr" {
policy_id = "key-policy-ecr"
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 = ["*"]
}
}
resource "aws_kms_key" "ecr" {
description = var.description
deletion_window_in_days = var.key_deletion_window_in_days
enable_key_rotation = "true"
policy = data.aws_iam_policy_document.ecr.json
tags = var.tags
}
resource "aws_kms_alias" "ecr" {
name = var.name
target_key_id = aws_kms_key.ecr.key_id
}