@@ -19,34 +19,49 @@ locals {
1919 secret_name = join (" -" , slice (split (" -" , local. full_secret_part ), 0 , length (split (" -" , local. full_secret_part )) - 1 ))
2020}
2121
22- # Track changes to trigger rebuilds only when necessary
23- resource "null_resource" "prepare_triggers" {
22+ # Prepare authenticator code in temporary directory - always runs
23+ resource "null_resource" "prepare_authenticator" {
24+ # Using triggers that change every time ensures this always runs
2425 triggers = {
25- authenticator_dir_sha = local.sso_authenticator_sha
26- callback_dir_sha = local.sso_callback_sha
27- secret_name = local.secret_name
26+ always_run = timestamp ()
2827 }
29- }
30-
31- # Prepare authenticator code in temporary directory
32- resource "null_resource" "prepare_authenticator" {
33- # depends_on = [null_resource.prepare_triggers]
3428
35- # Use single-line command to avoid line ending issues
3629 provisioner "local-exec" {
3730 interpreter = [" /bin/bash" , " -c" ]
38- command = " mkdir -p ${ local . temp_authenticator_dir } && cp -r ${ local . sso_authenticator_dir } /* ${ local . temp_authenticator_dir } / && sed -i 's/const SECRET_NAME = \" SECRET-NAME-PLACEHOLDER\" ;/const SECRET_NAME = \" ${ local . secret_name } \" ;/g' ${ local . temp_authenticator_dir } /authenticator.js"
31+ command = " rm -rf ${ local . temp_authenticator_dir } && mkdir -p ${ local . temp_authenticator_dir } && cp -r ${ local . sso_authenticator_dir } /* ${ local . temp_authenticator_dir } / && sed -i 's/const SECRET_NAME = \" SECRET-NAME-PLACEHOLDER\" ;/const SECRET_NAME = \" ${ local . secret_name } \" ;/g' ${ local . temp_authenticator_dir } /authenticator.js"
3932 }
4033}
4134
42- # Prepare callback code in temporary directory
35+ # Prepare callback code in temporary directory - always runs
4336resource "null_resource" "prepare_callback" {
44- # depends_on = [null_resource.prepare_triggers]
37+ # Using triggers that change every time ensures this always runs
38+ triggers = {
39+ always_run = timestamp ()
40+ }
4541
46- # Use single-line command to avoid line ending issues
4742 provisioner "local-exec" {
4843 interpreter = [" /bin/bash" , " -c" ]
49- command = " mkdir -p ${ local . temp_callback_dir } && cp -r ${ local . sso_callback_dir } /* ${ local . temp_callback_dir } / && sed -i 's/const SECRET_NAME = \" SECRET-NAME-PLACEHOLDER\" ;/const SECRET_NAME = \" ${ local . secret_name } \" ;/g' ${ local . temp_callback_dir } /callback-handler.js"
44+ command = " rm -rf ${ local . temp_callback_dir } && mkdir -p ${ local . temp_callback_dir } && cp -r ${ local . sso_callback_dir } /* ${ local . temp_callback_dir } / && sed -i 's/const SECRET_NAME = \" SECRET-NAME-PLACEHOLDER\" ;/const SECRET_NAME = \" ${ local . secret_name } \" ;/g' ${ local . temp_callback_dir } /callback-handler.js"
45+ }
46+ }
47+
48+ # Create explicit dependency for authenticator
49+ resource "terraform_data" "wait_for_authenticator" {
50+ depends_on = [null_resource. prepare_authenticator ]
51+
52+ input = {
53+ source_id = null_resource.prepare_authenticator.id
54+ source_dir = local.temp_authenticator_dir
55+ }
56+ }
57+
58+ # Create explicit dependency for callback
59+ resource "terraform_data" "wait_for_callback" {
60+ depends_on = [null_resource. prepare_callback ]
61+
62+ input = {
63+ source_id = null_resource.prepare_callback.id
64+ source_dir = local.temp_callback_dir
5065 }
5166}
5267
@@ -56,12 +71,10 @@ resource "null_resource" "prepare_callback" {
5671
5772data "archive_file" "sso_authenticator" {
5873 type = " zip"
59- source_dir = " ${ local . temp_authenticator_dir } "
74+ source_dir = terraform_data . wait_for_authenticator . input . source_dir
6075 output_path = " ${ local . temp_authenticator_dir } /payload.zip"
6176 excludes = [" payload.zip" ]
6277 output_file_mode = " 0666"
63-
64- depends_on = [null_resource. prepare_triggers , null_resource. prepare_authenticator ]
6578}
6679
6780resource "aws_lambda_function" "sso_authenticator" {
@@ -80,12 +93,10 @@ resource "aws_lambda_function" "sso_authenticator" {
8093
8194data "archive_file" "sso_callback" {
8295 type = " zip"
83- source_dir = " ${ local . temp_callback_dir } "
96+ source_dir = terraform_data . wait_for_callback . input . source_dir
8497 output_path = " ${ local . temp_callback_dir } /payload.zip"
8598 excludes = [" payload.zip" ]
8699 output_file_mode = " 0666"
87-
88- depends_on = [null_resource. prepare_triggers , null_resource. prepare_callback ]
89100}
90101
91102resource "aws_lambda_function" "sso_callback" {
0 commit comments