forked from opsworks-co/vector-eks-s3-opensearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
75 lines (65 loc) · 1.87 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
72
73
74
75
locals {
bucket_name = coalesce(var.s3_bucket_name, lower("${var.name}-${var.eks_cluster_name}-logs"))
}
data "aws_iam_policy_document" "s3_bucket_policy" {
statement {
sid = "AccessForVectorAgentRole"
principals {
type = "AWS"
identifiers = [module.vector_agent_role.iam_role_arn]
}
actions = ["s3:ListBucket", "s3:PutObject"]
resources = ["arn:aws:s3:::${local.bucket_name}", "arn:aws:s3:::${local.bucket_name}/*"]
}
statement {
sid = "AccessForVectorAggregatorRole"
principals {
type = "AWS"
identifiers = [module.vector_aggregator_role.iam_role_arn]
}
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${local.bucket_name}/*"]
}
}
module "vector_s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "4.1.0"
bucket = local.bucket_name
acl = null
force_destroy = var.s3_force_destroy
versioning = {
enabled = false
}
lifecycle_rule = [
{
id = "expiration"
enabled = true
expiration = {
days = var.s3_expiration_days
}
abort_incomplete_multipart_upload_days = "1"
},
{
id = "remove_delete_markers"
enabled = true
expiration = {
expired_object_delete_marker = true
}
}
]
policy = coalesce(var.s3_bucket_policy, data.aws_iam_policy_document.s3_bucket_policy.json)
attach_policy = true
attach_deny_insecure_transport_policy = true
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
tags = var.tags
}
resource "aws_s3_bucket_notification" "object_created" {
bucket = module.vector_s3_bucket.s3_bucket_id
queue {
queue_arn = module.vector_sqs.queue_arn
events = ["s3:ObjectCreated:*"]
}
}