From b457fd9ce4be4fe01c5f29e5f81f5c0959342263 Mon Sep 17 00:00:00 2001 From: pcortada-te Date: Mon, 24 Nov 2025 13:15:35 +0000 Subject: [PATCH] Fix: Error during templating due to inconsistent elements order in array --- src/stacks/filters/lookup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stacks/filters/lookup.py b/src/stacks/filters/lookup.py index 8807d80..a8d1937 100644 --- a/src/stacks/filters/lookup.py +++ b/src/stacks/filters/lookup.py @@ -37,7 +37,11 @@ def terraform_init_headless(ctx, argv, *args, **kwargs): preinit.preinit(ctx=remote_ctx) code = helpers.hcl2_read([remote_ctx.work_dir.joinpath("*.tf")]) helpers.directory_remove(remote_ctx.work_dir) - helpers.json_write({"terraform": [{"backend": code["terraform"][0]["backend"]}]}, remote_ctx.universe_file) + + backend_block = [item["backend"] for item in code["terraform"] if "backend" in item] + if not backend_block: + raise Exception("No backend configured in terraform block") + helpers.json_write({"terraform": [{"backend": backend_block[0]}]}, remote_ctx.universe_file) helpers.run_command(config.TERRAFORM_PATH, f"-chdir={remote_ctx.work_dir}", "init") # we cannot avoid pulling providers because we need to know the resources' schema return helpers.run_command(config.TERRAFORM_PATH, f"-chdir={remote_ctx.work_dir}", *argv, interactive=False).stdout