@@ -5,8 +5,12 @@ locals {
55 # sorted list
66 runner_matcher_config_sorted = [for k in sort (keys (local. runner_matcher_config )) : local . runner_matcher_config [k ]]
77
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 })]))
1014
1115 # Set max chunk size based on SSM tier
1216 # AWS SSM limits:
@@ -16,19 +20,23 @@ locals {
1620 # (e.g., escaped characters or minor overhead could exceed the limit)
1721 max_chunk_size = var. matcher_config_parameter_store_tier == " Advanced" ? 8000 : 4000
1822
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+
1930 # 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 )]
2432}
2533
2634resource "aws_ssm_parameter" "runner_matcher_config" {
27- count = length ( local. matcher_chunks )
35+ count = local. total_chunks
2836
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 } " : " " } "
3038 type = " String"
31- value = local. matcher_chunks [count . index ]
39+ value = local. matcher_json_chunks [count . index ]
3240 tier = var. matcher_config_parameter_store_tier
3341 tags = var. tags
3442}
0 commit comments