forked from lgallard/terraform-aws-cognito-user-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource-server.tf
41 lines (35 loc) · 1.45 KB
/
resource-server.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
resource "aws_cognito_resource_server" "resource" {
count = length(local.resource_servers)
name = lookup(element(local.resource_servers, count.index), "name")
identifier = lookup(element(local.resource_servers, count.index), "identifier")
#scope
dynamic "scope" {
for_each = lookup(element(local.resource_servers, count.index), "scope")
content {
scope_name = lookup(scope.value, "scope_name")
scope_description = lookup(scope.value, "scope_description")
}
}
user_pool_id = aws_cognito_user_pool.pool.id
}
locals {
resource_server_default = [
{
name = var.resource_server_name
identifier = var.resource_server_identifier
scope = [
{
scope_name = var.resource_server_scope_name
scope_description = var.resource_server_scope_description
}]
}
]
# This parses var.user_groups which is a list of objects (map), and transforms it to a tupple of elements to avoid conflict with the ternary and local.groups_default
resource_servers_parsed = [for e in var.resource_servers : {
name = lookup(e, "name", null)
identifier = lookup(e, "identifier", null)
scope = lookup(e, "scope", [])
}
]
resource_servers = length(var.resource_servers) == 0 && (var.resource_server_name == null || var.resource_server_name == "") ? [] : (length(var.resource_servers) > 0 ? local.resource_servers_parsed : local.resource_server_default)
}