-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam-user.tf
44 lines (39 loc) · 1011 Bytes
/
iam-user.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
resource "aws_iam_user" "s3_user" {
name = "s3_full_access_user_for_${var.name}"
}
resource "aws_iam_access_key" "s3_user_key" {
user = aws_iam_user.s3_user.name
}
resource "aws_iam_user_policy" "s3_full_access" {
name = "s3_full_access"
user = aws_iam_user.s3_user.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "s3:*"
Effect = "Allow"
Resource = [
aws_s3_bucket.static_bucket.arn,
"${aws_s3_bucket.static_bucket.arn}/*"
]
}
]
})
}
resource "aws_s3_bucket_policy" "s3policyforOAI" {
bucket = aws_s3_bucket.static_bucket.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["s3:GetObject"],
Effect = "Allow",
Resource = "${aws_s3_bucket.static_bucket.arn}/*",
Principal = {
AWS = "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${module.cloudfront.oai_id}"
}
}
]
})
}