forked from langfuse/langfuse-terraform-aws
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paths3.tf
More file actions
111 lines (96 loc) · 2.78 KB
/
s3.tf
File metadata and controls
111 lines (96 loc) · 2.78 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
locals {
# Convert domain to bucket-friendly format (e.g., company.com -> company-com)
bucket_prefix = replace(var.domain, ".", "-")
}
resource "aws_s3_bucket" "langfuse" {
bucket = "${local.bucket_prefix}-${var.name}"
# Add tags for better resource management
tags = {
Name = "${local.bucket_prefix}-${var.name}"
Domain = var.domain
Service = "langfuse"
}
}
resource "aws_s3_bucket_versioning" "langfuse" {
bucket = aws_s3_bucket.langfuse.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_public_access_block" "langfuse" {
bucket = aws_s3_bucket.langfuse.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# Add lifecycle rules for cost optimization
resource "aws_s3_bucket_lifecycle_configuration" "langfuse" {
bucket = aws_s3_bucket.langfuse.id
# https://aws.amazon.com/s3/storage-classes/
# Transition to "STANDARD Infrequent Access" after 90 days, and
# to "GLACIER Instant Retrieval" after 180 days
rule {
id = "langfuse_lifecycle"
status = "Enabled"
filter {
prefix = "" # Empty prefix matches all objects
}
transition {
days = 90
storage_class = "STANDARD_IA"
}
transition {
days = 180
storage_class = "GLACIER_IR"
}
}
}
# Create IRSA role for Langfuse service account
resource "aws_iam_role" "langfuse_irsa" {
name = "langfuse"
path = "/kubernetes/"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRoleWithWebIdentity"
Effect = "Allow"
Principal = {
Federated = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${replace(aws_eks_cluster.langfuse.identity[0].oidc[0].issuer, "https://", "")}"
}
Condition = {
StringEquals = {
"${replace(aws_eks_cluster.langfuse.identity[0].oidc[0].issuer, "https://", "")}:sub" : "system:serviceaccount:langfuse:langfuse"
"${replace(aws_eks_cluster.langfuse.identity[0].oidc[0].issuer, "https://", "")}:aud" : "sts.amazonaws.com"
}
}
}
]
})
}
# S3 access policy for the IRSA role
resource "aws_iam_role_policy" "langfuse_s3_access" {
name = "s3-access"
role = aws_iam_role.langfuse_irsa.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject"
]
Resource = [
aws_s3_bucket.langfuse.arn,
"${aws_s3_bucket.langfuse.arn}/*"
]
}
]
})
}
# Get current AWS account ID
data "aws_caller_identity" "current" {}