Skip to content

Commit dccc14b

Browse files
committed
updates to dbt sso modules
1 parent 8eb6d56 commit dccc14b

File tree

15 files changed

+304
-214
lines changed

15 files changed

+304
-214
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,8 @@ payload.zip
593593
*.crt
594594
*.cert
595595
*.key
596-
*.ovpn
596+
*.ovpn
597+
598+
# NPM
599+
package-lock.json
600+
.node_install*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
locals {
2+
resource_name_prefix = var.use_env_code_flag ? "${lower(var.env_code)}-${lower(var.project_code)}-${lower(var.project_code)}" : "${lower(var.project_code)}-${lower(var.project_code)}"
3+
}

dbt-docs/terraform/cloudfront-microsoft-sso/main.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
module "sso_auth" {
33
source = "../modules/cloudfront-microsoft-sso"
44

5-
env_code = var.env_code
6-
project_code = var.project_code
7-
app_code = var.app_code
8-
aws_region = var.aws_region
9-
use_env_code_flag = var.use_env_code_flag
10-
enable_auth_flag = var.enable_auth_flag
5+
name_prefix = local.resource_name_prefix
6+
app_code = "dbt-docs"
7+
enable_auth_flag = true
118

12-
lambda_runtime = var.lambda_runtime
9+
lambda_runtime = "nodejs18.x"
1310
sso_config_arn = aws_secretsmanager_secret.sso_config.arn
14-
}
11+
}

dbt-docs/terraform/cloudfront-microsoft-sso/secretsmanager.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ resource "aws_secretsmanager_secret" "sso_config" {
77
resource "aws_secretsmanager_secret_version" "sso_config_version" {
88
secret_id = aws_secretsmanager_secret.sso_config.id
99
secret_string = jsonencode({
10-
tenant = var.sso_tenant_id
11-
client_id = var.sso_client_id
12-
client_secret = var.sso_client_secret
13-
redirect_uri = var.sso_redirect_uri
10+
tenant = var.dbt_sso_tenant_id
11+
client_id = var.dbt_sso_client_id
12+
client_secret = var.dbt_sso_client_secret
13+
redirect_uri = var.dbt_sso_redirect_uri
1414
})
1515
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
env_code = "dev"
22
project_code = "entechlog"
3-
app_code = "dbt-docs"
43
aws_region = "us-east-1"
54
use_env_code_flag = true
6-
enable_auth_flag = true
75

8-
sso_tenant_id = ""
9-
sso_client_id = ""
10-
sso_client_secret = ""
11-
sso_redirect_uri = ""
6+
dbt_sso_tenant_id = ""
7+
dbt_sso_client_id = ""
8+
dbt_sso_client_secret = ""
9+
dbt_sso_redirect_uri = ""
1210

13-
lambda_runtime = "nodejs16.x"
11+
lambda_runtime = "nodejs18.x"

dbt-docs/terraform/cloudfront-microsoft-sso/variables.tf

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ variable "project_code" {
1010
default = "entechlog"
1111
}
1212

13-
variable "app_code" {
14-
type = string
15-
description = "Application code used as a prefix for resource names"
16-
default = "dbt-docs"
17-
}
18-
1913
variable "aws_region" {
2014
type = string
2115
description = "Primary region for all AWS resources"
@@ -28,37 +22,24 @@ variable "use_env_code_flag" {
2822
default = true
2923
}
3024

31-
variable "enable_auth_flag" {
32-
type = bool
33-
description = "Toggle on/off the SSO authentication"
34-
default = true
35-
}
36-
3725
# -- SSO details: you will store these in Secrets Manager outside the module
38-
variable "sso_tenant_id" {
26+
variable "dbt_sso_tenant_id" {
3927
type = string
4028
description = "Tenant ID for the SSO config"
4129
}
4230

43-
variable "sso_client_id" {
31+
variable "dbt_sso_client_id" {
4432
type = string
4533
description = "Client ID for the SSO config"
4634
}
4735

48-
variable "sso_client_secret" {
36+
variable "dbt_sso_client_secret" {
4937
type = string
5038
description = "Client Secret for the SSO config"
5139
sensitive = true
5240
}
5341

54-
variable "sso_redirect_uri" {
42+
variable "dbt_sso_redirect_uri" {
5543
type = string
5644
description = "Redirect URI for the SSO flow"
5745
}
58-
59-
# Optional override for Node.js runtime (the module defaults to nodejs18.x if not specified)
60-
variable "lambda_runtime" {
61-
type = string
62-
description = "Runtime for the Lambda functions"
63-
default = "nodejs18.x"
64-
}

dbt-docs/terraform/modules/cloudfront-microsoft-sso/iam.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data "aws_iam_policy_document" "lambda_edge_assume_role" {
88
effect = "Allow"
99
actions = ["sts:AssumeRole"]
1010
principals {
11-
type = "Service"
11+
type = "Service"
1212
identifiers = [
1313
"lambda.amazonaws.com",
1414
"edgelambda.amazonaws.com"
@@ -50,7 +50,7 @@ data "aws_iam_policy_document" "lambda_edge_secrets_access" {
5050
###############################
5151

5252
resource "aws_iam_role" "lambda_edge" {
53-
name = "${local.resource_name_prefix}-lambda-edge-role"
53+
name = "${lower(var.name_prefix)}-${var.app_code}-lambda-edge-role"
5454
assume_role_policy = data.aws_iam_policy_document.lambda_edge_assume_role.json
5555
}
5656

@@ -68,7 +68,7 @@ resource "aws_iam_role_policy_attachment" "lambda_edge_logs" {
6868
###############################
6969

7070
resource "aws_iam_role_policy" "lambda_edge_secrets_access" {
71-
name = "${local.resource_name_prefix}-edge-secrets-policy"
71+
name = "${lower(var.name_prefix)}-${var.app_code}-edge-secrets-policy"
7272
role = aws_iam_role.lambda_edge.id
7373
policy = data.aws_iam_policy_document.lambda_edge_secrets_access.json
7474
}
Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
locals {
2-
# If you want to track code changes in .js/.json:
32
sso_authenticator_files = fileset(local.sso_authenticator_dir, "*.{js,json}")
4-
sso_authenticator_sha = sha256(join(",", [
3+
sso_authenticator_sha = sha256(join(",", [
54
for file in local.sso_authenticator_files : filesha256("${local.sso_authenticator_dir}/${file}")
65
]))
76

87
sso_callback_files = fileset(local.sso_callback_dir, "*.{js,json}")
9-
sso_callback_sha = sha256(join(",", [
8+
sso_callback_sha = sha256(join(",", [
109
for file in local.sso_callback_files : filesha256("${local.sso_callback_dir}/${file}")
1110
]))
1211
}
1312

14-
###############################
15-
# Package & deploy SSO Authenticator
16-
###############################
17-
18-
resource "null_resource" "sso_authenticator" {
19-
# No local-exec block here anymore
13+
resource "null_resource" "prepare_lambda_dirs" {
2014
triggers = {
21-
deployable_dir = local.sso_authenticator_sha
15+
authenticator_dir_sha = local.sso_authenticator_sha
16+
callback_dir_sha = local.sso_callback_sha
2217
}
2318
}
2419

2520
data "archive_file" "sso_authenticator" {
26-
depends_on = [null_resource.sso_authenticator]
21+
depends_on = [null_resource.prepare_lambda_dirs]
2722
type = "zip"
2823
source_dir = local.sso_authenticator_dir
2924
output_path = "${local.sso_authenticator_dir}/payload.zip"
@@ -32,7 +27,7 @@ data "archive_file" "sso_authenticator" {
3227
}
3328

3429
resource "aws_lambda_function" "sso_authenticator" {
35-
function_name = "${lower(var.project_code)}-sso-authenticator"
30+
function_name = "${lower(var.name_prefix)}-${lower(var.app_code)}-sso-authenticator"
3631
role = aws_iam_role.lambda_edge.arn
3732
filename = data.archive_file.sso_authenticator.output_path
3833
runtime = var.lambda_runtime
@@ -41,19 +36,8 @@ resource "aws_lambda_function" "sso_authenticator" {
4136
publish = true
4237
}
4338

44-
###############################
45-
# Package & deploy SSO Callback
46-
###############################
47-
48-
resource "null_resource" "sso_callback" {
49-
# No local-exec block here anymore
50-
triggers = {
51-
deployable_dir = local.sso_callback_sha
52-
}
53-
}
54-
5539
data "archive_file" "sso_callback" {
56-
depends_on = [null_resource.sso_callback]
40+
depends_on = [null_resource.prepare_lambda_dirs]
5741
type = "zip"
5842
source_dir = local.sso_callback_dir
5943
output_path = "${local.sso_callback_dir}/payload.zip"
@@ -62,11 +46,11 @@ data "archive_file" "sso_callback" {
6246
}
6347

6448
resource "aws_lambda_function" "sso_callback" {
65-
function_name = "${lower(var.project_code)}-sso-callback"
49+
function_name = "${lower(var.name_prefix)}-${lower(var.app_code)}-sso-callback"
6650
role = aws_iam_role.lambda_edge.arn
6751
filename = data.archive_file.sso_callback.output_path
6852
runtime = var.lambda_runtime
6953
handler = "callback-handler.handler"
7054
source_code_hash = data.archive_file.sso_callback.output_base64sha256
7155
publish = true
72-
}
56+
}

dbt-docs/terraform/modules/cloudfront-microsoft-sso/locals.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
locals {
22
account_id = data.aws_caller_identity.current.account_id
33

4-
resource_name_prefix = var.use_env_code_flag ? "${lower(var.env_code)}-${lower(var.project_code)}-${lower(var.app_code)}" : "${lower(var.project_code)}-${lower(var.app_code)}"
5-
64
# Hard-coded directories for Lambda code
75
sso_authenticator_dir = "../uploads/lambda/sso_authenticator"
86
sso_callback_dir = "../uploads/lambda/sso_callback"

dbt-docs/terraform/modules/cloudfront-microsoft-sso/s3.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data "aws_iam_policy_document" "s3_read_only_access" {
1414
}
1515

1616
resource "aws_s3_bucket" "app" {
17-
bucket = local.resource_name_prefix
17+
bucket = "${var.name_prefix}-${var.app_code}"
1818
force_destroy = true
1919
}
2020

0 commit comments

Comments
 (0)