-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiam.tf
55 lines (41 loc) · 1.23 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
resource "aws_iam_service_linked_role" "aos" {
count = var.create_service_role ? 1 : 0
aws_service_name = "opensearchservice.amazonaws.com"
}
data "aws_iam_policy_document" "aos_access_policy" {
#checkov:skip=CKV_AWS_283
statement {
sid = "admin"
effect = "Allow"
principals {
type = "AWS"
identifiers = var.admin_identifiers
}
actions = ["es:*"]
resources = ["arn:aws:es:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:domain/${var.domain_name}/*"]
}
dynamic "statement" {
for_each = length(var.subnet_ids) == 0 ? [1] : []
content {
sid = "client"
effect = "Allow"
principals {
type = "*"
identifiers = ["*"]
}
actions = ["es:ESHttp*"]
resources = ["arn:aws:es:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:domain/${var.domain_name}/*"]
condition {
test = "IpAddress"
variable = "aws:SourceIp"
values = distinct(compact(var.whitelist_ips))
}
}
}
}
data "aws_iam_policy_document" "combined" {
source_policy_documents = [
data.aws_iam_policy_document.aos_access_policy.json,
var.access_policies,
]
}