Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JML project for lambda-secrets-other modules #4636

Merged
merged 28 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f72b92b
added module to execute jml
murad-ali-MoJ Jan 17, 2024
14791f8
added the iam policy document for lambda
murad-ali-MoJ Jan 17, 2024
f711f9d
fix the resources
murad-ali-MoJ Jan 17, 2024
0eea7ae
fix the resources with variable
murad-ali-MoJ Jan 17, 2024
ec89d02
fix the error
murad-ali-MoJ Jan 17, 2024
96746f6
WIP
Jan 17, 2024
92c8e0d
added events
murad-ali-MoJ Jan 18, 2024
e7befc5
sorted arn
murad-ali-MoJ Jan 18, 2024
6e1b873
event trigger sorted
murad-ali-MoJ Jan 19, 2024
d2a379f
delete unnecessery lambda and IAM
murad-ali-MoJ Jan 19, 2024
a645238
jml_lambda_trigger fixed
murad-ali-MoJ Jan 19, 2024
b969214
image added as arn
murad-ali-MoJ Jan 19, 2024
5125794
trigger sorted
murad-ali-MoJ Jan 19, 2024
3b98cea
change with module name
murad-ali-MoJ Jan 19, 2024
422f144
fix the event bridge arn
murad-ali-MoJ Jan 19, 2024
48a0572
arn added for auth0, govuk,email
murad-ali-MoJ Jan 19, 2024
aa050b9
arn typo fix
murad-ali-MoJ Jan 19, 2024
aacdcf0
count argument set to gouk_notify
murad-ali-MoJ Jan 19, 2024
a807f59
secret key added through the console
murad-ali-MoJ Jan 19, 2024
8097e96
data file fix
murad-ali-MoJ Jan 19, 2024
594d1dd
Merge remote-tracking branch 'origin/main' into jml_lambda_module
murad-ali-MoJ Jan 19, 2024
312515f
added count index
murad-ali-MoJ Jan 19, 2024
8382ee4
add index 1
murad-ali-MoJ Jan 19, 2024
f17673c
update lambda and all variables
murad-ali-MoJ Jan 19, 2024
b713c19
fix the string issue
murad-ali-MoJ Jan 19, 2024
cb33613
hotfix for PowerBI AMI
Jan 19, 2024
1ca45bb
Update lambda function configuration
Jan 19, 2024
16c81d8
Fix some styling
Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_cloudwatch_event_rule" "jml_lambda_trigger" {
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

name = "jml-lambda-trigger"
schedule_expression = "cron(0 2 1 * ? *)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_cloudwatch_event_target" "jml_lambda_trigger" {
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

rule = aws_cloudwatch_event_rule.jml_lambda_trigger[0].name
target_id = "jml-lambda-trigger"
arn = module.jml_extract_lambda[0].lambda_function_arn
}
18 changes: 17 additions & 1 deletion terraform/environments/data-platform-apps-and-tools/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,20 @@ data "aws_secretsmanager_secret_version" "openmetadata_entra_id_client_id" {

data "aws_secretsmanager_secret_version" "openmetadata_entra_id_tenant_id" {
secret_id = "openmetadata/entra-id/tenant-id"
}
}

##################################################
# Data Platform Apps and Tools JML
##################################################

data "aws_secretsmanager_secret_version" "govuk_notify_api_key" {
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

secret_id = aws_secretsmanager_secret.govuk_notify_api_key[0].id
}

data "aws_secretsmanager_secret_version" "jml_email" {
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

secret_id = aws_secretsmanager_secret.jml_email[0].id
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module "jml_extract_lambda" {
#checkov:skip=CKV_TF_1:Module is from Terraform registry
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

source = "terraform-aws-modules/lambda/aws"
version = "~> 6.0"

publish = true
create_package = false

function_name = "data_platform_jml_extract"
description = "Generates a JML report and sends it to JMLv4"
package_type = "Image"
image_uri = "374269020027.dkr.ecr.eu-west-2.amazonaws.com/data-platform-jml-extract-lambda-ecr-repo:1.0.1"

environment_variables = {
SECRET_ID = data.aws_secretsmanager_secret_version.govuk_notify_api_key[0].secret_string
LOG_GROUP_NAMES = module.auth0_log_streams["alpha-analytics-moj"].cloudwatch_log_group_name
EMAIL_SECRET = data.aws_secretsmanager_secret_version.jml_email[0].secret_string
TEMPLATE_ID = "de618989-db86-4d9a-aa55-4724d5485fa5"
}

attach_policy_statements = true
policy_statements = {
"cloudwatch" = {
sid = "CloudWatch"
effect = "Allow"
actions = [
"cloudwatch:GenerateQuery",
"logs:DescribeLogStreams",
"logs:DescribeLogGroups",
"logs:GetLogEvents"
]
resources = [
"${module.auth0_log_streams["alpha-analytics-moj"].cloudwatch_log_group_arn}/*"
]
}
"secretsmanager" = {
sid = "SecretsManager"
effect = "Allow"
actions = [
"secretsmanager:DescribeSecret",
"secretsmanager:GetSecretValue",
"secretsmanager:ListSecrets"
]
resources = [
aws_secretsmanager_secret.govuk_notify_api_key[0].arn,
aws_secretsmanager_secret.jml_email[0].arn
]
}
}

allowed_triggers = {
"eventbridge" = {
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.jml_lambda_trigger[0].arn
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "cloudwatch_log_group_arn" {
value = aws_cloudwatch_log_group.this.arn
}

output "cloudwatch_log_group_name" {
value = local.cloudwatch_log_group_name
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ module "powerbi_gateway" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "v5.6.0"

name = local.environment_configuration.powerbi_gateway_ec2.instance_name
ami = data.aws_ami.windows_server_2022.id
name = local.environment_configuration.powerbi_gateway_ec2.instance_name
# ami = data.aws_ami.windows_server_2022.id
ami = "ami-00ffeb610527f540b" # Hardcoded AMI ID for Windows Server 2022
instance_type = local.environment_configuration.powerbi_gateway_ec2.instance_type
key_name = aws_key_pair.powerbi_gateway_keypair.key_name
monitoring = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ resource "aws_secretsmanager_secret" "govuk_notify_api_key" {
}

# Email secret for Lambda function
resource "aws_secretsmanager_secret" "email_secret" {
resource "aws_secretsmanager_secret" "jml_email" {
count = terraform.workspace == "data-platform-apps-and-tools-production" ? 1 : 0

name = "jml/email"
}
Loading