File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ data "aws_iam_policy_document" "kms_policy" {
2
+ statement {
3
+ actions = [
4
+ " kms:*"
5
+ ]
6
+
7
+ resources = [
8
+ " *"
9
+ ]
10
+
11
+ principals {
12
+ type = " AWS"
13
+ identifiers = [
14
+ " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" ,
15
+ " ${ data . aws_caller_identity . current . arn } "
16
+ ]
17
+ }
18
+ }
19
+
20
+ statement {
21
+ effect = " ${ var . admin_can_decrypt == " true" ? " Allow" : " Deny" } "
22
+
23
+ actions = [
24
+ " Decrypt"
25
+ ]
26
+
27
+ principals {
28
+ type = " AWS"
29
+ identifiers = [
30
+ " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" ,
31
+ " ${ data . aws_caller_identity . current . arn } "
32
+ ]
33
+ }
34
+ }
35
+
36
+ statement {
37
+ actions = [
38
+ " kms:Encrypt" ,
39
+ " kms:Decrypt" ,
40
+ " kms:ReEncrypt" ,
41
+ " kms:GenerateDataKey*" ,
42
+ " kms:DescribeKey"
43
+ ]
44
+
45
+ resources = [
46
+ " *"
47
+ ]
48
+
49
+ principals {
50
+ type = " AWS"
51
+ identifiers = [
52
+ " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/${ var . lambda_role } "
53
+ ]
54
+ }
55
+ }
56
+ }
57
+
58
+ resource "aws_kms_key" "key" {
59
+ enable_key_rotation = " ${ var . key_autorotate } "
60
+ policy = " ${ data . aws_iam_policy_document . kms_policy . json } "
61
+ }
62
+
63
+ resource "aws_kms_alias" "key_alias" {
64
+ name = " alias/${ var . key_alias } "
65
+ target_key_id = " ${ aws_kms_key . key . key_id } "
66
+ }
Original file line number Diff line number Diff line change
1
+ data "aws_caller_identity" "current" {}
2
+
3
+ variable "lambda_role" {}
4
+ variable "key_alias" {}
5
+
6
+ variable "key_autorotate" {
7
+ default = true
8
+ }
9
+
10
+ variable "admin_can_decrypt" {
11
+ default = false
12
+ }
You can’t perform that action at this time.
0 commit comments