Skip to content

feat(deploy-accelerator): support renamed architecture definition files - #541

Open
Git-PrinceNagar wants to merge 6 commits into
mainfrom
fix/4068-renamed-architecture-file
Open

Git-PrinceNagar wants to merge 6 commits into
mainfrom
fix/4068-renamed-architecture-file

Conversation

@Git-PrinceNagar

Copy link
Copy Markdown

Pull Request

Issue

Refs Azure/Azure-Landing-Zones#4068

Description

Deploy-Accelerator now passes a renamed architecture definition file to the bootstrap and removes the starter's default copy when both declare the same architecture. Users who keep the default file name, or who set terraform_architecture_file_path, get the same output as before.

Root cause

New-Bootstrap copies config/lib over the starter's lib with Copy-Item -Recurse -Force. That merges the folders, so the starter's lib/architecture_definitions/alz_custom.alz_architecture_definition.yaml stays next to the user's renamed file. The bootstrap reads only terraform_architecture_file_path, and its default points at the starter file.

  • If the renamed file keeps name: alz_custom, the library holds two architectures with one name and the starter plan fails.
  • If the user also changed the name, the bootstrap builds the intermediate root management group and its role assignments from the starter's file instead of the user's.

The documented workaround is to set terraform_architecture_file_path and delete the duplicate by hand.

Change

New private function Resolve-TerraformArchitectureFile, called from New-Bootstrap:

  • It runs only for Terraform starters when the bootstrap declares terraform_architecture_file_path and the user has not set it through the inputs, TF_VAR_terraform_architecture_file_path or TF_VAR_management_group_settings.
  • It considers only *.alz_architecture_definition.json, .yaml and .yml files inside an additional folder named lib. A user file on the default path keeps today's behaviour.
  • It works out the target architecture name in this order: a single literal architecture_name in the starter's root .tf files, then management_group_settings.architecture_name from the inputs, then the starter's optional(string, ...) default, then the name in the starter's default file.
  • Exactly one file with that name is selected. Two files with that name stop the run with an error that names both, because alzlib rejects duplicates anyway. A file that cannot be read is skipped with a warning. No match, or a missing powershell-yaml module when a YAML file must be read, keeps the default path and logs a warning.
  • Only after a file is selected does it read terraform.tfstate in the bootstrap folder. If the state manages an intermediate root management group that differs from the selected file's root, the module does not switch. It keeps the default path with a warning when the default file uses the recorded root, and stops with an error otherwise. Switching would replace the management group, so users opt in by setting terraform_architecture_file_path. State that is empty, cannot be parsed, is not a JSON object, is a folder or names more than one root also keeps the default path with a warning.
  • After the copy, New-Bootstrap deletes the starter's default file only when it declares the same architecture name as the selected file. User files are never deleted.
  • If the bootstrap keeps the default path but that file is missing from the starter output, for example after an earlier run removed it, a warning tells the user to move their architecture file to the default path inside their lib folder, so only one file declares the architecture, or to set terraform_architecture_file_path.

actions_bootstrap.ps1 installs powershell-yaml 0.4.12 because the new tests import it and the ubuntu-latest image does not ship it. #538 adds the same entry, so whichever PR merges second should keep one copy.

523 of the 760 added lines are tests.

Evidence

Same inputs for both runs. The user's lib holds contoso.alz_architecture_definition.yaml with name: alz_custom. Each run was Deploy-Accelerator with the bootstrap Terraform step stubbed, then terraform plan on the starter folder it prepared.

v7.1.5 writes terraform_architecture_file_path = lib/architecture_definitions/alz_custom.alz_architecture_definition.yaml, and the starter plan fails:

Error: Failed to initialize AlzLib

  with provider["registry.terraform.io/azure/alz"],
  on terraform.tf line 24, in provider "alz":
  24: provider "alz" {

Alzlib.Init: error processing library ./lib: error processing file, please
check the file format and content
resource already exists in the result: architecture with name `alz_custom`
already exists

This branch writes terraform_architecture_file_path = lib/architecture_definitions/contoso.alz_architecture_definition.yaml, leaves only the contoso file in the starter library, and the starter plan succeeds:

Plan: 565 to add, 0 to change, 0 to destroy.

Backward compatibility

  • No new input or parameter.
  • Without a renamed file, the module does not read the bootstrap state and writes the same bootstrap tfvars as v7.1.5. A file on the default path or an explicit terraform_architecture_file_path takes the same early exit.
  • In Azure, a bootstrap deployed with v7.1.5 and then run with this branch and unchanged inputs planned No changes.
  • Switching that same bootstrap to a renamed file planned one local_file create and one local_file delete. The management group kept its name, display name and parent, and the plan after apply showed No changes.
  • No state migration. Reverting this change in a later release restores the old behaviour.

Deliberately not changed

  • No regex or glob input in the bootstrap. The PowerShell module already knows which files the user supplied, and a bootstrap-side search could not tell them apart from the starter's files.
  • Bicep, the starter's architecture_name default and the alz_custom file name in the starter.
  • The docs page that describes the manual workaround. It can be updated after a release.

Testing

  • Invoke-Build -File ./src/ALZ.build.ps1 on PowerShell 7.7, Windows, Pester 5.4.0: 90 tests pass, analyzer and formatting clean, coverage gate passes. Not run locally on Linux; the PR workflow builds on ubuntu-latest.
  • 18 disposable reverts of individual rules, such as dedupe, the state guard and the TF_VAR skips, each made at least one of the tests aimed at that rule fail. Most ran on earlier commits of this branch.
  • Deploy-Accelerator with the bootstrap Terraform step stubbed, for v7.1.5 and this branch, with the default and renamed configs.
  • Azure, alz_local bootstrap in a test tenant under a unique root management group, on an earlier commit of this branch: deployed v7.1.5, 112 resources, re-plan No changes. This branch with the same inputs planned No changes. This branch with the renamed file applied the two local_file changes, re-plan No changes. All 112 resources were then destroyed, and a separate inventory found nothing left.
  • The last two commits, made after the Azure run, changed when and how the bootstrap state is read and the wording of one warning. I replayed the final commit against the real bootstrap state saved before cleanup, with the bootstrap Terraform step stubbed. With the renamed config it selected the contoso file; with the default config it kept the default path, with no warnings in either case. Both bootstrap tfvars match the ones from the Azure run except for the output folder path. A copy of that state with a different root stopped the run with the root management group error.
  • Starter terraform plan for both versions as shown above, not applied.
  • Not run: the GitHub and Azure DevOps bootstrap modules. New-Bootstrap runs the same code for all three, and they share the file_manipulation module that reads the path. A live run where the state root differs from the selected file; unit tests cover that guard.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.

Prince Nagar (BEYONDSOFT CONSULTING INC) added 6 commits November 25, 2026 12:06
Deploy-Accelerator copies config/lib on top of the starter lib, so a renamed
architecture file sat next to the starter's alz_custom file while the bootstrap
kept reading the default terraform_architecture_file_path. The bootstrap then
built the intermediate root management group from the wrong file, or the library
held two architectures with the same name.

When terraform_architecture_file_path is not supplied, New-Bootstrap now looks
for *.alz_architecture_definition.{json,yaml,yml} files in the starter
additional files whose name matches management_group_settings.architecture_name
(or the starter default file's name). A single match outside the default path
is passed to the bootstrap, and the starter default file is removed when it
declares the same architecture. More than one match stops with an error.

actions_bootstrap.ps1 installs powershell-yaml so the new tests can parse YAML
architecture files on the CI runner.

Refs Azure/Azure-Landing-Zones#4068
…g architecture files

Review follow-up for the renamed architecture file support.

- Take the target architecture name from the starter code (a hardcoded
  architecture_name, the input, or the optional() default) so a rerun after
  the default file was removed resolves the same file.
- Only count files in the lib folder, matched with the lower-case extensions
  the bootstrap reads, and leave everything unchanged when a user file lands
  on the default path, so the dedupe can never remove the user's own file.
- Skip files that do not parse or have no text name, and warn instead of
  failing when powershell-yaml is not loaded.
- Keep the default path when the bootstrap state already manages a different
  intermediate root management group; switching would replace it.
- Warn when the default file is missing from a reused starter folder.

Refs Azure/Azure-Landing-Zones#4068
…cond review

- Compare the default path case-insensitively on every OS (macOS file systems
  are case-insensitive) and require the lib folder name to match exactly.
- Stop with an error when the bootstrap state manages a root management group
  that neither the selected file nor the default uses; read only managed,
  non-deposed state instances and skip resolution when the state is unreadable
  or names more than one root.
- Ignore architecture_name in block comments and expressions in starter code.
- Count a file once when two lib folders copy it to the same destination.
- Skip resolution when TF_VAR_management_group_settings overrides the input.

Refs Azure/Azure-Landing-Zones#4068
…iles apart

- Strip heredoc strings as well as block comments before reading the
  architecture name from the starter code.
- Deduplicate copied architecture files by their exact destination, so files
  whose paths differ only in letter case are both counted.

Refs Azure/Azure-Landing-Zones#4068
… and give working recovery advice

- Read terraform.tfstate inside Resolve-TerraformArchitectureFile after a
  renamed file is selected. Users without a renamed architecture file no
  longer get a state warning, and an empty or unreadable state keeps the
  default path with a warning.
- Parse the state with -AsHashtable so keys that differ only in case do not
  fail the read.
- When the default architecture file is missing, tell users to add their file
  to their lib folder at the default path or set
  terraform_architecture_file_path. -replaceFiles only applies to the override
  folders, so it did not restore the file for release downloads.
- Use -LiteralPath when removing the starter default file.
- Add New-Bootstrap tests for unreadable and empty state and for a default
  layout with unreadable state; rename a test whose name did not match its
  setup.

Refs Azure/Azure-Landing-Zones#4068
…nd say move, not add

- Tell users to move their architecture file to the default path inside
  their lib folder. Copying it there would leave two files declaring the
  same architecture, which alzlib rejects.
- Treat a state path that exists but is not a readable JSON object,
  including a folder, as unknown, so the default path is kept with a
  warning.
- Add tests for state that is a JSON array and for a folder at the state
  path; fix a test title.

Refs Azure/Azure-Landing-Zones#4068
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Triage 🔍 Needs triaging by the team

Projects

Development

Successfully merging this pull request may close these issues.

1 participant