forked from aehrc/terraform-aws-serverless-beacon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cognito.tf
143 lines (122 loc) · 4.02 KB
/
cognito.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
# Pool and client
#
resource "aws_cognito_user_pool" "BeaconUserPool" {
name = "sbeacon-users"
admin_create_user_config {
allow_admin_create_user_only = true
invite_message_template {
email_subject = "sBeacon registration"
email_message = "Welcome to sBeacon, please use username: {username} and password: {####} to log in."
sms_message = "Welcome to sBeacon, please use username: {username} and password: {####} to log in."
}
}
account_recovery_setting {
recovery_mechanism {
name = "verified_email"
priority = 1
}
}
password_policy {
minimum_length = 6
require_lowercase = false
require_numbers = false
require_symbols = false
require_uppercase = false
temporary_password_validity_days = 7
}
schema {
name = "terraform"
attribute_data_type = "Boolean"
}
}
resource "aws_cognito_user_pool_client" "BeaconUserPool-client" {
name = "sbeacon-users-client"
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
explicit_auth_flows = [
"ALLOW_REFRESH_TOKEN_AUTH",
"ALLOW_ADMIN_USER_PASSWORD_AUTH",
"ALLOW_USER_PASSWORD_AUTH"
]
}
#
# groups
#
resource "aws_cognito_user_group" "record-access" {
name = "record-access-user-group"
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
description = "Group of users who can access 'record' granularity"
}
resource "aws_cognito_user_group" "count-access" {
name = "count-access-user-group"
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
description = "Group of users who can access 'count' granularity"
}
resource "aws_cognito_user_group" "boolean-access" {
name = "boolean-access-user-group"
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
description = "Group of users who can access 'boolean' granularity"
}
#
# default users
#
resource "aws_cognito_user" "guest" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
username = var.beacon-guest-username
password = var.beacon-guest-password
attributes = {
terraform = true
email = var.beacon-guest-username
email_verified = true
}
}
resource "aws_cognito_user" "admin" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
username = var.beacon-admin-username
password = var.beacon-admin-password
attributes = {
terraform = true
email = var.beacon-admin-username
email_verified = true
}
}
#
# group assignments
#
# admin
resource "aws_cognito_user_in_group" "admin-record-access" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
group_name = aws_cognito_user_group.record-access.name
username = aws_cognito_user.admin.username
}
resource "aws_cognito_user_in_group" "admin-count-access" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
group_name = aws_cognito_user_group.count-access.name
username = aws_cognito_user.admin.username
}
resource "aws_cognito_user_in_group" "admin-boolean-access" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
group_name = aws_cognito_user_group.boolean-access.name
username = aws_cognito_user.admin.username
}
# guest
resource "aws_cognito_user_in_group" "guest-count-access" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
group_name = aws_cognito_user_group.count-access.name
username = aws_cognito_user.guest.username
}
resource "aws_cognito_user_in_group" "guest-boolean-access" {
user_pool_id = aws_cognito_user_pool.BeaconUserPool.id
group_name = aws_cognito_user_group.boolean-access.name
username = aws_cognito_user.guest.username
}
#
# authorizers
#
resource "aws_api_gateway_authorizer" "BeaconUserPool-authorizer" {
name = "UserPoolAuthorizer-sbeacon"
type = "COGNITO_USER_POOLS"
rest_api_id = aws_api_gateway_rest_api.BeaconApi.id
provider_arns = [aws_cognito_user_pool.BeaconUserPool.arn]
depends_on = [aws_api_gateway_rest_api.BeaconApi]
}