-
Notifications
You must be signed in to change notification settings - Fork 3
/
cognito-auth-redirect.tf
87 lines (83 loc) · 2.74 KB
/
cognito-auth-redirect.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
resource "aws_iam_role" "cognito_auth_redirect" {
count = var.users_management_type == "cognito" ? 1 : 0
name = "${local.name}-cognito-auth-redirect"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_policy" "cognito_auth_redirect" {
count = var.users_management_type == "cognito" ? 1 : 0
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "cognito_auth_redirect" {
count = var.users_management_type == "cognito" ? 1 : 0
policy_arn = aws_iam_policy.cognito_auth_redirect[0].arn
role = aws_iam_role.cognito_auth_redirect[0].name
}
module "cognito_auth_redirect" {
count = var.users_management_type == "cognito" ? 1 : 0
source = "terraform-aws-modules/lambda/aws"
version = "2.7.0"
create_package = true
create_role = false
create = true
create_layer = false
create_function = true
publish = true
function_name = "${local.name}-cognito-auth-redirect"
runtime = "python3.9"
handler = "app.handler"
memory_size = 512
timeout = 30
lambda_role = aws_iam_role.cognito_auth_redirect[0].arn
package_type = "Zip"
source_path = "${path.module}/lambdas/cognito-auth-redirect"
}
module "redirect_2cognito" {
count = var.users_management_type == "cognito" ? 1 : 0
source = "terraform-aws-modules/lambda/aws"
version = "2.7.0"
create_package = true
create_role = true
create = true
create_layer = false
create_function = true
publish = true
function_name = "${local.name}-redirect-2cognito"
runtime = "python3.9"
handler = "app.handler"
memory_size = 512
timeout = 30
package_type = "Zip"
source_path = "${path.module}/lambdas/redirect-2cognito"
environment_variables = {
COGNITO_USER_POOL_CLIENT_ID = var.cognito_user_pool_id != null ? var.cognito_user_pool_id : aws_cognito_user_pool_client.wg-vpn[0].id
COGNITO_POOL_NAME = var.cognito_user_pool_id != null ? var.project-name : "${local.name}-wg-user-pool"
COGNITO_REGION = data.aws_region.current.name
}
}