-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_product.tf
90 lines (72 loc) Β· 1.89 KB
/
s3_product.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
resource "aws_s3_bucket" "repick_product_bucket" {
bucket = "repick-product-bucket"
tags = {
Name = "repick-product-bucket"
}
}
resource "aws_s3_bucket_public_access_block" "repick_product_bucket_public_access_block" {
bucket = aws_s3_bucket.repick_product_bucket.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
depends_on = [aws_s3_bucket.repick_product_bucket]
}
resource "aws_s3_bucket_policy" "repick_product_bucket_policy" {
bucket = aws_s3_bucket.repick_product_bucket.id
policy = data.aws_iam_policy_document.repick_product_bucket_policy.json
depends_on = [aws_s3_bucket.repick_product_bucket]
}
data "aws_iam_policy_document" "repick_product_bucket_policy" {
statement {
actions = [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket",
]
effect = "Allow"
resources = [
"${aws_s3_bucket.repick_product_bucket.arn}",
"${aws_s3_bucket.repick_product_bucket.arn}/*",
]
principals {
type = "AWS"
identifiers = ["*"]
}
}
}
resource "aws_iam_user" "s3_user" {
name = "s3_user"
tags = {
Name = "s3_user"
}
}
resource "aws_iam_access_key" "s3_user_key" {
user = aws_iam_user.s3_user.name
}
resource "aws_iam_user_policy" "s3_user_policy" {
name = "s3_user_policy"
user = aws_iam_user.s3_user.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
EOF
}
resource "aws_secretsmanager_secret" "s3_user_secret" {
name = "s3_user_secret"
}
resource "aws_secretsmanager_secret_version" "s3_user_secret_version" {
secret_id = aws_secretsmanager_secret.s3_user_secret.id
secret_string = jsonencode({
access_key : aws_iam_access_key.s3_user_key.id,
secret_key : aws_iam_access_key.s3_user_key.secret
})
}