This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
forked from deanillfeld/terraform-aws-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam_policy.tf
73 lines (62 loc) · 1.83 KB
/
iam_policy.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
data "aws_iam_policy_document" "iam-role-policy-restricted" {
count = length(var.workspace_prefixes)
statement {
actions = ["s3:ListBucket"]
resources = ["arn:aws:s3:::${aws_s3_bucket.backend.id}"]
}
statement {
actions = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]
resources = ["arn:aws:s3:::${aws_s3_bucket.backend.id}/env:/${element(var.workspace_prefixes, count.index)}*"]
}
statement {
actions = ["dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:DeleteItem"]
resources = ["arn:aws:dynamodb:*:*:table/${var.resource_prefix}-terraform-lock"]
}
}
data "aws_iam_policy_document" "iam-role-policy" {
statement {
actions = ["s3:ListBucket"]
resources = ["arn:aws:s3:::${aws_s3_bucket.backend.id}"]
}
statement {
actions = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]
resources = ["arn:aws:s3:::${aws_s3_bucket.backend.id}/*"]
}
statement {
actions = ["dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:DeleteItem"]
resources = ["arn:aws:dynamodb:*:*:table/${var.resource_prefix}-terraform-lock"]
}
}
data "aws_iam_policy_document" "backend-assume-role-all" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = split(
",",
lookup(
var.assume_policy,
"all",
data.aws_caller_identity.current.account_id,
),
)
}
}
}
data "aws_iam_policy_document" "backend-assume-role-restricted" {
count = length(var.workspace_prefixes)
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = split(
",",
lookup(
var.assume_policy,
element(var.workspace_prefixes, count.index),
data.aws_caller_identity.current.account_id,
),
)
}
}
}