fix: persist guided deploy args to samconfig.toml on failure - #9140
fix: persist guided deploy args to samconfig.toml on failure#9140ljacobsson wants to merge 2 commits into
Conversation
Save guided prompt answers even when the deploy fails (e.g. bad credentials), so they aren't lost. New projects always save on failure; when a samconfig already exists it's preserved unless --save-params-on-failure is passed.
|
Thanks for pushing on this, @ljacobsson — and apologies for the long silence. I reviewed the branch at For the record, the gating design here matches what @qingchm proposed in #3693 (2022-12-19): keep the default behaviour and add an opt-in flag. So the shape of the change isn't the problem. 1. CI is red — must fix
Both are positional
Separately, the branch is 77 commits behind 2. Correctness bug: a failing save swallows the original error
try:
self.guided_prompts(_parameter_override_keys)
except Exception:
if self._should_save_config() and (not config_already_exists or self.force_save_config):
self._save_config(guided_config) # <-- if this raises, the `raise` below never runs
raiseIf The user sees a permissions error instead of "your credentials are invalid" — the exact opposite of this PR's goal. Please wrap the save in its own 3. Behaviour-change question for maintainers (a): the save fires on every post-answer failure, not just credential failuresThe PR description and code comments frame this as "the AWS calls failed". But the
So 4. Behaviour-change question for maintainers (b): the saved config is incomplete, and the success message claims otherwise
version = 0.1
[default.deploy.parameters]
stack_name = "my-stack"
s3_prefix = "my-stack"
region = "us-west-2"
confirm_changeset = true
capabilities = "CAPABILITY_IAM"
parameter_overrides = "MyPlainParam=\"...\""
[default.global.parameters]
region = "us-west-2"No The bigger issue is that That second line is false for this config. The failure path needs its own wording, e.g. "Partially saved your answers to samconfig.toml so you don't have to re-enter them; re-run 5.
|
Which issue(s) does this change fix?
Fixes #3693
Why is this change necessary?
When running
sam deploy --guided, the answers entered during the guided prompts are only written tosamconfig.tomlafter the credential-requiring AWS calls (manage_stack/sync_ecr_stack) succeed. If those calls fail (e.g. invalid or expired SSO credentials), the command aborts before saving, so the user has to re-enter every prompt after fixing their credentials. This is especially painful for stacks with many parameters (see #3693).How does it address the issue?
All config-relevant answers are now collected on the instance before any AWS call is made, and the config is saved even when the guided flow fails.
To avoid clobbering a known-good configuration during development (the concern raised in the issue discussion), save-on-failure is gated:
samconfig.toml(new project): answers are always saved on failure, since there is nothing to overwrite.samconfig.toml: the file is left untouched on failure by default. Users can opt in to overwriting it with the new--save-params-on-failure/--no-save-params-on-failureflag.Successful deploys continue to save the config exactly as before.
What side effects does this change have?
--save-params-on-failure/--no-save-params-on-failureflag onsam deploy(default off), only relevant to--guided.samconfig.tomlwill now be written where previously none was. The original error is still surfaced.schema/samcli.jsonregenerated for the new option.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedDocumentation: the new --save-params-on-failure flag is documented via its --help text and the regenerated schema/samcli.json.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.