-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
72 lines (62 loc) · 1.41 KB
/
s3.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
70
71
###########################
#--- S3 Backend Bucket ---#
###########################
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "4.1.0"
bucket = "tf-${var.name}-${random_integer.random.id}-state"
acl = "private"
object_lock_enabled = true
control_object_ownership = true
object_ownership = "ObjectWriter"
allowed_kms_key_arn = aws_kms_key.objects.arn
server_side_encryption_configuration = {
rule = {
apply_server_side_encryption_by_default = {
kms_master_key_id = aws_kms_key.objects.arn
sse_algorithm = "aws:kms"
}
}
}
force_destroy = true
versioning = {
enabled = true
}
attach_policy = true
policy = <<POLICY
{
"Statement": [
{
"Sid": "bucket-delete-protection",
"Action": [
"s3:DeleteBucketPolicy",
"s3:DeleteBucket"
],
"Effect": "Deny",
"Resource": "arn:aws:s3:::tf-${var.name}-${random_integer.random.id}-state",
"Principal": {
"AWS": [
"*"
]
}
}
]
}
POLICY
tags = merge(
var.tags,
{
"Name" = format("%s", var.name)
},
)
}
resource "aws_kms_key" "objects" {
description = "KMS key is used to encrypt bucket objects"
deletion_window_in_days = 7
tags = merge(
var.tags,
{
"Name" = format("%s", var.name)
},
)
}