-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
69 lines (51 loc) · 1.75 KB
/
iam.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
resource "aws_iam_user" "bucket_user" {
count = var.create && var.create_iam_user ? 1 : 0
name = var.bucket_name
tags = local.common_tags
lifecycle {
ignore_changes = [
tags["CreateTimestamp"]
]
}
}
resource "aws_iam_access_key" "bucket_access_key" {
count = var.create && var.create_iam_user ? 1 : 0
user = aws_iam_user.bucket_user[0].name
}
resource "aws_iam_user_policy_attachment" "bucket_user_policy" {
count = var.create && var.create_iam_user ? 1 : 0
user = aws_iam_user.bucket_user[0].name
policy_arn = aws_iam_policy.bucket_rw[0].arn
}
resource "aws_iam_policy" "bucket_rw" {
count = var.create && (var.create_iam_user || length(var.create_iam_eks_role) > 0) ? 1 : 0
name = "${var.bucket_name}-rw"
policy = data.aws_iam_policy_document.allow_read_write[0].json
description = "Provides read-write access to the '${var.bucket_name}' S3 bucket"
tags = local.common_tags
lifecycle {
ignore_changes = [
tags["CreateTimestamp"]
]
}
}
// Extra custom policy
resource "aws_iam_user_policy_attachment" "extra_custom_policy" {
count = var.create && length(var.extra_custom_policy)>0 && var.create_iam_user ? 1 : 0
user = aws_iam_user.bucket_user[0].name
policy_arn = aws_iam_policy.extra_custom_policy[0].arn
}
resource "aws_iam_policy" "extra_custom_policy" {
count = var.create && length(var.extra_custom_policy)>0 && (var.create_iam_user || length(var.create_iam_eks_role) > 0) ? 1 : 0
name = "${var.bucket_name}-extra-custom-policy"
policy = jsonencode(
var.extra_custom_policy
)
description = "Provides extra custom policy to the '${var.bucket_name}' S3 bucket"
tags = local.common_tags
lifecycle {
ignore_changes = [
tags["CreateTimestamp"]
]
}
}