-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1201 from UKHSA-Internal/task/add-infra-cognito-d…
…b/CDD-2443 CDD-2443 Create cognito and api gateway modules using terraform
- Loading branch information
Showing
22 changed files
with
870 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module "api_gateway" { | ||
source = "../modules/api-gateway" | ||
name = "${local.prefix}-api-gateway" | ||
description = "API Gateway for ${local.prefix}" | ||
api_gateway_stage_name = var.api_gateway_stage_name | ||
lambda_role_arn = module.cognito.cognito_lambda_role_arn | ||
cognito_user_pool_arn = module.cognito.cognito_user_pool_arn | ||
region = local.region | ||
resource_path_part = "{proxy+}" | ||
lambda_invoke_arn = module.api_gateway.lambda_alias_arn | ||
lambda_function_arn = module.api_gateway.api_gateway_lambda_arn | ||
prefix = local.prefix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module "cognito" { | ||
source = "../modules/cognito" | ||
sns_role_arn = aws_iam_role.cognito_sns_role.arn | ||
user_pool_name = "${local.prefix}-user-pool" | ||
client_name = "${local.prefix}-client" | ||
user_pool_domain = "${local.prefix}-domain" | ||
callback_urls = concat( | ||
["https://${terraform.workspace}.dev.ukhsa-dashboard.data.gov.uk/api/auth/callback/cognito"], | ||
local.is_dev ? ["http://localhost:3000/api/auth/callback/cognito", "http://localhost:3001/api/auth/callback/cognito"] : [] | ||
) | ||
logout_urls = concat( | ||
["https://${terraform.workspace}.dev.ukhsa-dashboard.data.gov.uk"], | ||
local.is_dev ? ["http://localhost:3000", "http://localhost:3001"] : [] | ||
) | ||
region = local.region | ||
|
||
ukhsa_oidc_client_id = "ukhsa-oidc-client-id" | ||
ukhsa_oidc_client_secret = "ukhsa-oidc-client-secret" | ||
ukhsa_oidc_issuer_url = "https://example.com/issuer" | ||
ukhsa_oidc_attributes_url = "https://example.com/attributes" | ||
|
||
lambda_role_arn = aws_iam_role.cognito_lambda_role.arn | ||
prefix = local.prefix | ||
} | ||
|
||
module "app_security_group" { | ||
source = "terraform-aws-modules/security-group/aws" | ||
version = "~> 5.0" | ||
|
||
name = "${local.prefix}-security-group" | ||
description = "Security group for the application" | ||
vpc_id = module.vpc.vpc_id | ||
|
||
computed_ingress_with_source_security_group_id = [ | ||
{ | ||
rule = "postgresql-tcp" | ||
source_security_group_id = module.aurora_db_app.security_group_id | ||
} | ||
] | ||
number_of_computed_ingress_with_source_security_group_id = 1 | ||
|
||
egress_rules = ["all-all"] | ||
|
||
tags = { | ||
project_name = local.project | ||
env = terraform.workspace | ||
} | ||
} | ||
|
||
output "cognito_user_pool_id" { | ||
description = "Cognito User Pool ID" | ||
value = module.cognito.cognito_user_pool_id | ||
sensitive = true | ||
} | ||
|
||
output "cognito_user_pool_client_id" { | ||
description = "Cognito User Pool Client ID" | ||
value = module.cognito.cognito_user_pool_client_id | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ terraform { | |
key = "app/state.tfstate" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,4 @@ output "lambda" { | |
ingestion_lambda_arn = module.lambda_ingestion.lambda_function_arn | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module "cognito_sns" { | ||
source = "terraform-aws-modules/sns/aws" | ||
version = "6.1.2" | ||
|
||
name = "${local.prefix}-cognito-topic" | ||
|
||
subscriptions = [ | ||
{ | ||
protocol = "email" | ||
endpoint = var.cognito_admin_email | ||
} | ||
] | ||
} | ||
|
||
resource "aws_iam_role" "cognito_sns_role" { | ||
name = "${local.prefix}-cognito-sns-role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "cognito-idp.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_policy" "cognito_sns_policy" { | ||
name = "${local.prefix}-cognito-sns-policy" | ||
description = "Allows Cognito to publish messages to the SNS topic" | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Sid = "AllowCognitoToPublish", | ||
Effect = "Allow", | ||
Action = ["sns:Publish"], | ||
Resource = module.cognito_sns.topic_arn | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "cognito_sns_policy_attachment" { | ||
role = aws_iam_role.cognito_sns_role.id | ||
policy_arn = aws_iam_policy.cognito_sns_policy.arn | ||
} | ||
|
||
resource "aws_iam_role" "cognito_lambda_role" { | ||
name = "${local.prefix}-lambda-execution-role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "lambda.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
} | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,15 @@ variable "single_nat_gateway" { | |
} | ||
|
||
variable "halo_account_type" {} | ||
|
||
variable "api_gateway_stage_name" { | ||
description = "The stage name for API Gateway (e.g. dev or live)" | ||
type = string | ||
default = "dev" | ||
} | ||
|
||
variable "cognito_admin_email" { | ||
description = "Admin email address for Cognito SNS notifications" | ||
type = string | ||
default = "[email protected]" | ||
} |
Oops, something went wrong.