Skip to content

Commit 4058ca7

Browse files
committed
(ELI-597) fixing escaping error
1 parent 5f5bf78 commit 4058ca7

1 file changed

Lines changed: 23 additions & 93 deletions

File tree

Lines changed: 23 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
resource "aws_sfn_state_machine" "rotation_machine" {
2-
#checkov:skip=CKV_AWS_284: No x-ray needed for this resource
32
name = "SecretRotationWorkflow"
43
role_arn = aws_iam_role.rotation_sfn_role.arn
54

@@ -12,42 +11,45 @@ resource "aws_sfn_state_machine" "rotation_machine" {
1211
definition = jsonencode({
1312
Comment = "Secret Rotation: Create -> Manual Pause -> Promote -> Manual Pause",
1413
StartAt = "CreatePendingVersion",
15-
States = {
16-
"CreatePendingVersion" : {
14+
States = {
15+
CreatePendingVersion = {
1716
Type = "Task",
1817
Resource = aws_lambda_function.create_secret_lambda.arn,
1918
Catch = [{ ErrorEquals = ["States.ALL"], Next = "NotifyFailure" }],
2019
Next = "WaitFor_AddNewHashes"
2120
},
22-
"WaitFor_AddNewHashes" : {
21+
22+
WaitFor_AddNewHashes = {
2323
Type = "Task",
2424
Resource = "arn:aws:states:::sns:publish.waitForTaskToken",
2525
TimeoutSeconds = 86400,
2626
Parameters = {
27-
Subject = "Action required: AWSPENDING secret created (Environment: ${var.environment})",
28-
TopicArn = aws_sns_topic.secret_rotation.arn,
29-
"Message.$" = local.add_jobs_message
27+
Subject = "Action required: AWSPENDING secret created (Environment: ${var.environment})",
28+
TopicArn = aws_sns_topic.secret_rotation.arn,
29+
"Message.$" = "States.Format('======================================================\nAction required: AWSPENDING secret created (Environment: ${var.environment})\n======================================================\n\nA manual action is required to proceed.\n\nCONTEXT:\nSecret Name: ${module.secrets_manager.aws_hashing_secret_name}\n\nINSTRUCTIONS:\n1. Run the \"Add New Hashes (elid_add_new_salt)\" job.\n2. Ensure the new hashes are working as expected.\n3. Run the command below to approve and resume the workflow:\n\naws stepfunctions send-task-success --task-token {} --task-output {}\n\n======================================================\n', $$.Task.Token, '{}')"
3030
},
3131
Catch = [
3232
{ ErrorEquals = ["States.Timeout"], Next = "NotifyTimeout" },
3333
{ ErrorEquals = ["States.ALL"], Next = "NotifyFailure" }
3434
],
3535
Next = "PromoteToCurrent"
3636
},
37-
"PromoteToCurrent" : {
37+
38+
PromoteToCurrent = {
3839
Type = "Task",
3940
Resource = aws_lambda_function.promote_secret_lambda.arn,
4041
Catch = [{ ErrorEquals = ["States.ALL"], Next = "NotifyFailure" }],
4142
Next = "WaitFor_DelOldHashes"
4243
},
43-
"WaitFor_DelOldHashes" : {
44+
45+
WaitFor_DelOldHashes = {
4446
Type = "Task",
4547
Resource = "arn:aws:states:::sns:publish.waitForTaskToken",
4648
TimeoutSeconds = 86400,
4749
Parameters = {
48-
Subject = "Action required: Secret AWSPENDING promoted to AWSCURRENT (Environment: ${var.environment})",
49-
TopicArn = aws_sns_topic.secret_rotation.arn,
50-
"Message.$" = local.delete_jobs_message
50+
Subject = "Action required: Secret AWSPENDING promoted to AWSCURRENT (Environment: ${var.environment})",
51+
TopicArn = aws_sns_topic.secret_rotation.arn,
52+
"Message.$" = "States.Format('======================================================\nAction required: Secret AWSPENDING promoted to AWSCURRENT (Environment: ${var.environment})\n======================================================\n\nA manual action is required to proceed.\n\nCONTEXT:\nSecret Name: ${module.secrets_manager.aws_hashing_secret_name}\n\nINSTRUCTIONS:\n1. Run the \"Delete Old Hashes (elid_delete_old_salt)\" job.\n2. Ensure the old hashes have been removed successfully.\n3. Run the command below to approve and resume the workflow:\n\naws stepfunctions send-task-success --task-token {} --task-output {}\n\n======================================================\n', $$.Task.Token, '{}')"
5153
},
5254
Catch = [
5355
{ ErrorEquals = ["States.Timeout"], Next = "NotifyTimeout" },
@@ -56,23 +58,24 @@ resource "aws_sfn_state_machine" "rotation_machine" {
5658
End = true
5759
},
5860

59-
"NotifyTimeout" : {
61+
NotifyTimeout = {
6062
Type = "Task",
6163
Resource = "arn:aws:states:::sns:publish",
6264
Parameters = {
63-
TopicArn = aws_sns_topic.secret_rotation.arn,
64-
Subject = "Warning: Secret rotation timed out (Environment: ${var.environment})",
65-
"Message.$" = local.timeout_message
65+
TopicArn = aws_sns_topic.secret_rotation.arn,
66+
Subject = "Warning: Secret rotation timed out (Environment: ${var.environment})",
67+
Message = local.timeout_message
6668
},
6769
Next = "Fail_Timeout"
6870
},
6971

70-
"Fail_Timeout" : {
72+
Fail_Timeout = {
7173
Type = "Fail",
7274
Error = "ManualActionTimedOut",
7375
Cause = "User did not respond within 24 hours."
7476
},
75-
"NotifyFailure" : {
77+
78+
NotifyFailure = {
7679
Type = "Task",
7780
Resource = "arn:aws:states:::sns:publish",
7881
Parameters = {
@@ -82,58 +85,15 @@ resource "aws_sfn_state_machine" "rotation_machine" {
8285
},
8386
Next = "Fail_Generic"
8487
},
85-
"Fail_Generic" : {
88+
89+
Fail_Generic = {
8690
Type = "Fail"
8791
}
8892
}
8993
})
9094
}
9195

9296
locals {
93-
add_jobs_message = <<EOT
94-
States.Format('
95-
======================================================
96-
Action required: AWSPENDING secret created (Environment: ${var.environment})
97-
======================================================
98-
99-
A manual action is required to proceed.
100-
101-
CONTEXT:
102-
Secret Name: ${module.secrets_manager.aws_hashing_secret_name}
103-
104-
INSTRUCTIONS:
105-
1. Run the "Add New Hashes (elid_add_new_salt)" job.
106-
2. Ensure the new hashes are working as expected.
107-
3. Run the command below to approve and resume the workflow:
108-
109-
aws stepfunctions send-task-success --task-token {} --task-output {{}}
110-
111-
======================================================
112-
', $$.Task.Token)
113-
EOT
114-
115-
delete_jobs_message = <<EOT
116-
States.Format('
117-
======================================================
118-
Action required: Secret AWSPENDING promoted to AWSCURRENT (Environment: ${var.environment})
119-
======================================================
120-
121-
A manual action is required to proceed.
122-
123-
CONTEXT:
124-
Secret Name: ${module.secrets_manager.aws_hashing_secret_name}
125-
126-
INSTRUCTIONS:
127-
1. Run the "Delete Old Hashes (elid_delete_old_salt)" job.
128-
2. Ensure the old hashes have been removed successfully.
129-
3. Run the command below to approve and resume the workflow:
130-
131-
aws stepfunctions send-task-success --task-token {} --task-output {{}}
132-
133-
======================================================
134-
', $$.Task.Token)
135-
EOT
136-
13797
failure_message = <<EOT
13898
States.Format('
13999
======================================================
@@ -148,48 +108,18 @@ Secret Name: ${module.secrets_manager.aws_hashing_secret_name}
148108
ERROR DETAILS:
149109
{}
150110
151-
------------------------------------------------------
152-
HOW TO FIX: "Pending Version Exists" Error
153-
------------------------------------------------------
154-
If the error above indicates a pending version already exists,
155-
you must clean it up manually.
156-
157-
1. Find the Version ID of the pending secret:
158-
aws secretsmanager list-secret-version-ids --secret-id ${module.secrets_manager.aws_hashing_secret_name}
159-
160-
2. Remove the AWSPENDING label:
161-
aws secretsmanager update-secret-version-stage --secret-id ${module.secrets_manager.aws_hashing_secret_name} --version-stage AWSPENDING --remove-from-version-id <OLD_PENDING_VERSION_ID>
162-
163111
======================================================
164112
', $.Cause)
165113
EOT
166114

167115
timeout_message = <<EOT
168-
States.Format('
169116
======================================================
170117
Warning: Rotation timed out (Environment: ${var.environment})
171118
======================================================
172119
173120
The manual verification step was not completed within the 24-hour limit.
174-
The rotation workflow has been stopped.
175121
176-
CONTEXT:
177122
Secret Name: ${module.secrets_manager.aws_hashing_secret_name}
178-
179-
IMPACT:
180-
No immediate impact. Your applications are still using the current secret.
181-
However, a "Pending" version may have been left behind.
182-
183-
ACTION REQUIRED:
184-
Before the next rotation run, you must remove the pending version:
185-
186-
1. Find the Version ID:
187-
aws secretsmanager list-secret-version-ids --secret-id ${module.secrets_manager.aws_hashing_secret_name}
188-
189-
2. Remove the AWSPENDING label:
190-
aws secretsmanager update-secret-version-stage --secret-id ${module.secrets_manager.aws_hashing_secret_name} --version-stage AWSPENDING --remove-from-version-id <OLD_PENDING_VERSION_ID>
191-
192123
======================================================
193-
')
194124
EOT
195125
}

0 commit comments

Comments
 (0)