-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWS_KMS.tf
56 lines (51 loc) · 1.25 KB
/
AWS_KMS.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
resource "aws_iam_policy" "access_control_policy" {
name = "AccessControlPolicy"
description = "IAM policy for access control"
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"s3:GetObject",
"s3:PutObject"
],
"Resource" : "*"
},
{
"Effect" : "Allow",
"Action" : [
"kms:Encrypt",
"kms:Decrypt",
"kms:GenerateDataKey"
],
"Resource" : "*"
}
]
})
}
resource "aws_iam_role" "access_control_role" {
name = "AccessControlRole"
assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "sts:AssumeRole",
"Effect" : "Allow",
"Principal" : {
"Service" : "ec2.amazonaws.com"
}
}
]
})
}
# Attach the policy to the role
resource "aws_iam_role_policy_attachment" "access_control_policy_attachment" {
role = aws_iam_role.access_control_role.name
policy_arn = aws_iam_policy.access_control_policy.arn
}
# Create a KMS key
resource "aws_kms_key" "data_encryption_key" {
description = "KMS key for data encryption"
deletion_window_in_days = 10
}