From e3e5abdd5f7d2026fb29e28d1701b537e28e28c9 Mon Sep 17 00:00:00 2001 From: shenlan Date: Tue, 30 Sep 2025 16:21:41 +0800 Subject: [PATCH] Improve Pulumi backend selection from credentials --- iac_modules/pulumi/iac_run.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/iac_modules/pulumi/iac_run.sh b/iac_modules/pulumi/iac_run.sh index 2e4dd2f3..a76f70bf 100755 --- a/iac_modules/pulumi/iac_run.sh +++ b/iac_modules/pulumi/iac_run.sh @@ -75,12 +75,26 @@ def maybe_export(env_key, raw_value, exports): def select_backend(backends): if isinstance(backends, str): return ensure_string(backends) + if isinstance(backends, (list, tuple)): candidates = [ensure_string(item) for item in backends if ensure_string(item)] for candidate in candidates: if candidate and candidate.lower().startswith("s3://"): return candidate return candidates[0] if candidates else None + + if isinstance(backends, dict): + direct = find_value(backends, "url", "uri", "s3", "backend") + if isinstance(direct, (str, list, tuple, dict)): + selected = select_backend(direct) + if selected: + return selected + + for value in backends.values(): + selected = select_backend(value) + if selected: + return selected + return None @@ -110,7 +124,11 @@ state_auth = find_section(iac_state, "auth") maybe_export("AWS_ACCESS_KEY_ID", find_value(state_auth, "ak", "access_key"), exports) maybe_export("AWS_SECRET_ACCESS_KEY", find_value(state_auth, "sk", "secret_key"), exports) -aws_section = find_section(data, "aws-global") or find_section(data, "aws") +aws_section = ( + find_section(data, "aws-global") + or find_section(data, "aws_global") + or find_section(data, "aws") +) maybe_export("AWS_ACCESS_KEY_ID", find_value(aws_section, "ak", "access_key", "access_key_id"), exports) maybe_export("AWS_SECRET_ACCESS_KEY", find_value(aws_section, "sk", "secret_key", "secret_access_key"), exports)