-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
87 lines (70 loc) · 2.76 KB
/
__main__.py
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
"""An AWS Python Pulumi program"""
import json
import pulumi
import pulumi_minio as minio
from pulumi_kubernetes.core.v1 import Secret
from pulumi_kubernetes.meta.v1 import ObjectMetaArgs
config = pulumi.Config()
serviceName = config.require("Name")
serviceNamespace = config.require("Namespace")
releaseName = config.require("ReleaseName")
secret_labels = {
"epinio.io/configuration": "true",
"epinio.io/configuration-origin": serviceName,
"epinio.io/configuration-type": "service",
"app.kubernetes.io/instance": releaseName,
"app.kubernetes.io/managed-by": "pulumi",
"app.kubernetes.io/name": "minio-bucket"
}
user = minio.IamUser(f"minio-iam-user",
name=f"{serviceNamespace}-{serviceName}",
force_destroy=True)
bucket = minio.S3Bucket(f"minio-s3-bucket",
bucket=f"{serviceNamespace}-{releaseName}")
pulumi.export("bucket_arn",bucket.arn)
def iam_user_policy(bucket_arn):
return pulumi.Output.all(bucket_arn).apply(
lambda args: json.dumps(
{
"Version":"2012-10-17",
"Statement": [
{
"Sid":"ListAllBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Principal":"*",
"Resource": [
f"{args[0]}",
f"{args[0]}/*"
]
}
]
}
)
)
iam_policy = minio.IamPolicy("minio-iam-policy",
name=f"{serviceNamespace}-{serviceName}",
policy=bucket.arn.apply(iam_user_policy)
)
iam_user_policy_attachment = minio.IamUserPolicyAttachment("minio-user-policy",
user_name=user.name,
policy_name=iam_policy.name)
service_account = minio.IamServiceAccount("service-account",
target_user=user.name,
policy=bucket.arn.apply(iam_user_policy))
service_account_secret = Secret("service-account-secret",
metadata=ObjectMetaArgs(
name=f"{releaseName}-minio",
namespace=serviceNamespace,
labels=secret_labels),
string_data = {
"ACCESS_KEY": service_account.access_key,
"SECRET_KEY": service_account.secret_key
}
)
pulumi.export("secret_name",service_account_secret.metadata["name"])