@@ -291,45 +291,37 @@ func convertDynamicRepSpecsWithDynamicConfig(resourceb *hclwrite.Body, dSpec, dC
291291 exprStr .WriteString (" region_configs = [\n " )
292292 exprStr .WriteString (fmt .Sprintf (" for %s in %s : {\n " , nRegion , configForEach ))
293293
294- // Add regular attributes first (provider_name, region_name, priority)
294+ // Add all attributes generically in alphabetical order
295295 attrs := dConfig .content .Body ().Attributes ()
296- if providerName := attrs ["provider_name" ]; providerName != nil {
297- exprStr .WriteString (fmt .Sprintf (" provider_name = %s\n " , hcl .GetAttrExpr (providerName )))
296+ attrNames := make ([]string , 0 , len (attrs ))
297+ for name := range attrs {
298+ attrNames = append (attrNames , name )
298299 }
299- if regionName := attrs [ "region_name" ]; regionName != nil {
300- exprStr . WriteString ( fmt . Sprintf ( " region_name = %s \n " , hcl . GetAttrExpr ( regionName )))
301- }
302- if priority := attrs ["priority" ]; priority != nil {
303- exprStr .WriteString (fmt .Sprintf (" priority = %s\n " , hcl .GetAttrExpr (priority )))
300+ slices . Sort ( attrNames )
301+
302+ for _ , name := range attrNames {
303+ attr := attrs [name ]
304+ exprStr .WriteString (fmt .Sprintf (" %s = %s\n " , name , hcl .GetAttrExpr (attr )))
304305 }
305306
306- // Add spec blocks as objects with correct formatting and ordering
307- // Look for the original blocks before they were converted
307+ // Add all blocks generically as objects
308308 for _ , block := range dConfig .content .Body ().Blocks () {
309- if block .Type () == "electable_specs" {
310- exprStr .WriteString (" electable_specs = {\n " )
311- blockAttrs := block .Body ().Attributes ()
312- // Write in specific order: instance_size first, then node_count
313- if instanceSize := blockAttrs ["instance_size" ]; instanceSize != nil {
314- exprStr .WriteString (fmt .Sprintf (" instance_size = %s\n " , hcl .GetAttrExpr (instanceSize )))
315- }
316- if nodeCount := blockAttrs ["node_count" ]; nodeCount != nil {
317- exprStr .WriteString (fmt .Sprintf (" node_count = %s\n " , hcl .GetAttrExpr (nodeCount )))
318- }
319- exprStr .WriteString (" }\n " )
309+ blockType := block .Type ()
310+ exprStr .WriteString (fmt .Sprintf (" %s = {\n " , blockType ))
311+
312+ // Add block attributes in alphabetical order
313+ blockAttrs := block .Body ().Attributes ()
314+ blockAttrNames := make ([]string , 0 , len (blockAttrs ))
315+ for name := range blockAttrs {
316+ blockAttrNames = append (blockAttrNames , name )
320317 }
321- if block .Type () == "read_only_specs" {
322- exprStr .WriteString (" read_only_specs = {\n " )
323- blockAttrs := block .Body ().Attributes ()
324- // Write in specific order: instance_size first, then node_count
325- if instanceSize := blockAttrs ["instance_size" ]; instanceSize != nil {
326- exprStr .WriteString (fmt .Sprintf (" instance_size = %s\n " , hcl .GetAttrExpr (instanceSize )))
327- }
328- if nodeCount := blockAttrs ["node_count" ]; nodeCount != nil {
329- exprStr .WriteString (fmt .Sprintf (" node_count = %s\n " , hcl .GetAttrExpr (nodeCount )))
330- }
331- exprStr .WriteString (" }\n " )
318+ slices .Sort (blockAttrNames )
319+
320+ for _ , attrName := range blockAttrNames {
321+ attr := blockAttrs [attrName ]
322+ exprStr .WriteString (fmt .Sprintf (" %s = %s\n " , attrName , hcl .GetAttrExpr (attr )))
332323 }
324+ exprStr .WriteString (" }\n " )
333325 }
334326
335327 exprStr .WriteString (" }\n " )
0 commit comments