@@ -5,8 +5,12 @@ locals {
5
5
# sorted list
6
6
runner_matcher_config_sorted = [for k in sort (keys (local. runner_matcher_config )) : local . runner_matcher_config [k ]]
7
7
8
- # Encode the sorted matcher config as JSON
9
- matcher_json = jsonencode (local. runner_matcher_config_sorted )
8
+ # Define worst-case dummy ARN/ID lengths
9
+ worst_case_arn = join (" " , [for i in range (0 , 127 ) : " X" ]) # ARN length assuming 80-char queue name, longest partition & region
10
+ worst_case_id = join (" " , [for i in range (0 , 135 ) : " Y" ]) # SQS URL length for same worst-case scenario
11
+
12
+ # Compute worst-case JSON length
13
+ worst_case_json_length = length (jsonencode ([for r in local . runner_matcher_config_sorted : merge (r, { arn = local.worst_case_arn, id = local.worst_case_id })]))
10
14
11
15
# Set max chunk size based on SSM tier
12
16
# AWS SSM limits:
@@ -16,19 +20,23 @@ locals {
16
20
# (e.g., escaped characters or minor overhead could exceed the limit)
17
21
max_chunk_size = var. matcher_config_parameter_store_tier == " Advanced" ? 8000 : 4000
18
22
23
+ # Calculate total number of chunks
24
+ total_chunks = ceil (local. worst_case_json_length / local. max_chunk_size )
25
+
26
+ # Encode the sorted matcher config as JSON
27
+ matcher_json = jsonencode (local. runner_matcher_config_sorted )
28
+ chunk_size = ceil (length (local. matcher_json ) / local. total_chunks )
29
+
19
30
# Split JSON into chunks safely under the SSM limit
20
- matcher_chunks = [
21
- for i in range (0 , length (local. matcher_json ), local. max_chunk_size ) :
22
- substr (local. matcher_json , i, local. max_chunk_size )
23
- ]
31
+ matcher_json_chunks = [for i in range (0 , length (local. matcher_json ), local. chunk_size ) : substr (local. matcher_json , i, local. chunk_size )]
24
32
}
25
33
26
34
resource "aws_ssm_parameter" "runner_matcher_config" {
27
- count = length ( local. matcher_chunks )
35
+ count = local. total_chunks
28
36
29
- name = " ${ var . ssm_paths . root } /${ var . ssm_paths . webhook } /runner-matcher-config${ length ( local. matcher_chunks ) > 1 ? " -${ count . index } " : " " } "
37
+ name = " ${ var . ssm_paths . root } /${ var . ssm_paths . webhook } /runner-matcher-config${ local . total_chunks > 1 ? " -${ count . index } " : " " } "
30
38
type = " String"
31
- value = local. matcher_chunks [count . index ]
39
+ value = local. matcher_json_chunks [count . index ]
32
40
tier = var. matcher_config_parameter_store_tier
33
41
}
34
42
0 commit comments