-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
64 lines (53 loc) · 1.47 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
resource "aws_iam_policy" "asustor" {
name_prefix = "asustor-"
description = "Asustor policy for bucket ${aws_s3_bucket.sync.id}"
policy = templatefile("${path.module}/iam_policy.json", {
bucket_arn = aws_s3_bucket.sync.arn
})
}
resource "random_string" "group_suffix" {
length = 16
lower = true
upper = false
numeric = true
special = false
}
resource "aws_iam_group" "asustor" {
name = "asustor-${random_string.group_suffix.result}"
}
resource "aws_iam_group_policy_attachment" "asustor" {
group = aws_iam_group.asustor.name
policy_arn = aws_iam_policy.asustor.arn
}
resource "random_string" "user_suffix" {
length = 16
lower = true
upper = false
numeric = true
special = false
}
resource "aws_iam_user" "asustor" {
name = "asustor-${random_string.user_suffix.result}"
}
resource "aws_iam_user_group_membership" "asustor" {
user = aws_iam_user.asustor.name
groups = [
aws_iam_group.asustor.name
]
}
resource "aws_iam_access_key" "asustor" {
user = aws_iam_user.asustor.name
pgp_key = var.iam_pgp_key
lifecycle {
ignore_changes = ["pgp_key"]
}
}
output "access_key" {
value = aws_iam_access_key.asustor.id
description = "IAM User Access Key"
}
output "access_key_secret" {
sensitive = true
value = var.iam_pgp_key == null ? aws_iam_access_key.asustor.secret : aws_iam_access_key.asustor.encrypted_secret
description = "IAM User Access Key Secret (encrypted if `iam_pgp_key` was set)"
}