Skip to content

feat: keep the architecture file format when marking the root as existing - #154

Open
Git-PrinceNagar wants to merge 2 commits into
mainfrom
fix/4069-architecture-file-format
Open

Git-PrinceNagar wants to merge 2 commits into
mainfrom
fix/4069-architecture-file-format

Conversation

@Git-PrinceNagar

@Git-PrinceNagar Git-PrinceNagar commented Dec 2, 2026 •

Copy link
Copy Markdown

Overview/Summary

The bootstrap now writes the starter's Terraform architecture file as authored and changes only the intermediate root management group's exists: false to true. Before, every Terraform run re-encoded the whole file with yamlencode or jsonencode, which quoted and sorted every key, dropped comments and blank lines, and minified JSON.

Refs Azure/Azure-Landing-Zones#4069

This PR fixes/adds/changes/removes

  1. modules/file_manipulation/locals.intermediate_root_management_group.tf tries the original text first, then the original with the first exists: false set to true. It writes the first text that decodes to the same content the module produced before. If none does, it writes the previous yamlencode or jsonencode output.
  2. A file whose root is first and already has exists: true is written byte for byte.
  3. No variables, outputs or resources change. alz/github, alz/azuredevops and alz/local all call the same module.

Breaking Changes

  1. None. The decoded architecture is identical to before, so the starter deployment that reads it is unaffected.
  2. A re-apply of an existing bootstrap updates the architecture file once, from the re-encoded layout to the authored layout.

Testing Evidence

Unit tests with terraform test on Terraform 1.17.2, with no providers and no Azure deployment. A harness calls modules/file_manipulation the way alz/local does and compares the generated architecture file with a hand-written expected file.

Before, on main c58ce10, with the test starter template from alz-terraform-accelerator:

"management_groups":
- "archetypes":
  - "test"
  "display_name": "Test"
  "exists": true
  "id": "test"
  "parent_id": null
- "archetypes":
  - "test"
  "display_name": "Child Test"
  "exists": false
  "id": "child-test"
  "parent_id": "test"
"name": "alz_custom"

After, the file as authored with only the root line changed:

name: alz_custom
management_groups:
  - id: test
    display_name: Test
    archetypes:
      - test
    exists: true
    parent_id: null
  - id: child-test
    display_name: Child Test
    archetypes:
      - test
    exists: false
    parent_id: test

Results on this branch:

  run "starter_default_keeps_format"... pass
  run "starter_test_template_keeps_format"... pass
  run "yaml_comments_and_blank_lines_kept"... pass
  run "json_pretty_print_kept"... pass
  run "root_already_exists_unchanged"... pass
  run "root_not_first_still_moved_first_and_marked"... pass
  run "root_without_exists_key_marked_child_untouched"... pass
  run "yaml_crlf_line_endings_kept"... pass
  run "comment_mentioning_flag_before_root_kept"... pass
Success! 9 passed, 0 failed.

On main c58ce10, 7 of the 9 runs fail. With the decoded-content comparison removed, three runs fail, so that comparison keeps the fallback cases correct. Thirteen more edge cases pass, including "exists" and 'exists' keys, --- document markers, flow mappings, YAML merge keys, minified JSON, .yml and a root last with no trailing newline.

These inputs still get the previous re-encoded output, with correct content and the old layout. The root is not first in management_groups, the root has no exists key, the value is exists: False, or a block scalar containing exists: false comes before the root.

terraform fmt -check -recursive is clean and terraform validate passes on alz/local, alz/github and alz/azuredevops. TFLint reports the same findings as main.

I also ran Deploy-Accelerator (ALZ PowerShell module 7.1.5, alz_local, platform_landing_zone starter) in a test tenant. On main, the saved bootstrap plan writes the re-encoded file. On this branch, the bootstrap applied, the generated architecture file matched the authored file except for the root exists flag, and a second plan returned No changes. I then deployed the full hub-and-spoke platform in centralindia from the generated files. The bootstrap created 164 resources, the platform created 1213, and a second platform plan returned No changes. The management-only, migration and SLZ variants of the example applied and re-planned the same way.

As part of this Pull Request I have

  • Checked for duplicate Pull Requests
    • Checked open PRs in Azure/accelerator-bootstrap-modules; none touch modules/file_manipulation.
  • Associated it with relevant issues, for tracking and closure.
  • Ensured my code/branch is up-to-date with the latest changes in the main branch
    • The branch is based on c58ce10. main has one newer commit, 0a3cc0d, which changes only a workflow file.
  • Performed testing and provided evidence.
  • Updated relevant and associated documentation.
    • No documentation describes the re-encoding.

Prince Nagar (BEYONDSOFT CONSULTING INC) added 2 commits November 26, 2026 11:34
…ting

The bootstrap decoded the starter architecture file and wrote it back with
yamlencode or jsonencode to set exists = true on the intermediate root
management group. That sorted and quoted every key, dropped comments and
blank lines, and minified JSON files.

The file is now written as authored when its root already has
exists: true, or with only the first exists: false changed to true. Either
text is used only when it decodes to the same content as before; otherwise
the previous re-encoded output is kept (root not first, root without an
exists key).

Refs Azure/Azure-Landing-Zones#4069
A comment that mentions "exists: false" before the root management group
made the single first-match pattern hit the comment, so the guard fell back
to re-encoding the whole file. Try a line-anchored key match first, then
the previous pattern for flow mappings and minified JSON.

Refs Azure/Azure-Landing-Zones#4069
@Git-PrinceNagar Git-PrinceNagar added the PR: Safe to test 🧪 Enables running of End to End Tests label Dec 2, 2026

This branch is waiting to be deployed

1 waiting deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Safe to test 🧪 Enables running of End to End Tests

Projects

Development

Successfully merging this pull request may close these issues.

1 participant