grada-run 0.49.9 → 0.49.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grada-run",
3
- "version": "0.49.9",
3
+ "version": "0.49.10",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -15,7 +15,7 @@ import { readInitManifest, recordAppliedTarget } from '../utils/backup.js';
15
15
  import { requireManagedTree, parseStateBucketBackend, upsertAutoTfvar } from '../utils/terraform-metadata.js';
16
16
  import { readTerraformComputeTarget, resolveRegion, readRenderedContainerEnvNames } from '../utils/resolvers.js';
17
17
  import { requireAwakeEnvironment, resolveSleepTarget, guardSleepingEnv } from '../utils/sleep-state.js';
18
- import { promptStateBucketRecovery, recreateStateBucket } from '../utils/recovery.js';
18
+ import { promptStateBucketRecovery, recreateStateBucket, offerInFlowRecovery, confirmRecoveryAction } from '../utils/recovery.js';
19
19
  import { resolveProjectName, readResourceSuffix } from '../utils/resolvers.js';
20
20
  import { ensureLambdaSeedImage } from '../utils/lambda-ecr.js';
21
21
  import { checkAwsCredentials, ensureStateBucketExists, isAuthError, printAwsAuthGuidance, resolveClient } from '../utils/aws.js';
@@ -821,36 +821,31 @@ async function applyStackMain(input = {}) {
821
821
  const pairs = parseCollisionImports(errString)
822
822
  .filter((pair) => !pair.address.startsWith('aws_secretsmanager_secret.'));
823
823
  if (pairs.length > 0) {
824
- const refused = await refuseIfNonInteractive(options, {
825
- message: '\n✖ apply needs approval to import collided resources into state.',
826
- hint: ' Re-run with --auto-approve to import non-interactively.\n',
827
- event: 'infrastructure_applied',
828
- telemetry: { projectName: actualProjectName },
829
- errorCode: 'COLLISION_IMPORT_NON_INTERACTIVE',
830
- });
831
- if (refused) return refused;
832
- let proceed = shouldAutoApprove(options);
833
- if (!proceed) {
834
- const confirmed = await confirm({
835
- message: `Import ${pairs.length} collided resource${pairs.length === 1 ? '' : 's'} into state and retry?`,
836
- initialValue: true,
837
- });
838
- proceed = !isCancel(confirmed) && confirmed === true;
839
- }
840
- if (proceed) {
841
- try {
824
+ const recovery = await offerInFlowRecovery({
825
+ options,
826
+ refusal: {
827
+ message: '\n✖ apply needs approval to import collided resources into state.',
828
+ hint: ' Re-run with --auto-approve to import non-interactively.\n',
829
+ event: 'infrastructure_applied',
830
+ telemetry: { projectName: actualProjectName },
831
+ errorCode: 'COLLISION_IMPORT_NON_INTERACTIVE',
832
+ },
833
+ approve: () => confirmRecoveryAction(
834
+ `Import ${pairs.length} collided resource${pairs.length === 1 ? '' : 's'} into state and retry?`
835
+ ),
836
+ act: async () => {
842
837
  for (const pair of pairs) {
843
838
  await runTerraform(['import', pair.address, pair.id], tfDir, null, `Importing ${pair.address}`);
844
839
  }
845
- } catch (error) {
846
- collisionImportError = error;
847
- }
848
- if (collisionImportError === null) {
849
- trackEvent('collision_resources_imported', { projectName: actualProjectName, count: pairs.length });
850
- log.message(color.cyan('Imported collided resources — retrying apply...'));
851
- return applyStack({ ...options, _skipPreview: true, _collisionImported: true });
852
- }
840
+ },
841
+ });
842
+ if (recovery.status === 'refused') return recovery.refusal;
843
+ if (recovery.status === 'recovered') {
844
+ trackEvent('collision_resources_imported', { projectName: actualProjectName, count: pairs.length });
845
+ log.message(color.cyan('Imported collided resources — retrying apply...'));
846
+ return applyStack({ ...options, _skipPreview: true, _collisionImported: true });
853
847
  }
848
+ if (recovery.status === 'failed') collisionImportError = recovery.error;
854
849
  }
855
850
  }
856
851
  trackEvent('bucket_recovery_probed', { projectName: actualProjectName, collisions });
@@ -872,38 +867,32 @@ async function applyStackMain(input = {}) {
872
867
  // Adopt the shared provider instead of hand-editing: the
873
868
  // GitHub provider URL is account-singleton, so the existing
874
869
  // provider IS the match — flip the var and retry.
875
- const refused = await refuseIfNonInteractive(options, {
876
- message: '\n✖ apply needs approval to adopt the existing GitHub OIDC provider.',
877
- hint: ' Re-run with --auto-approve to adopt non-interactively.\n',
878
- event: 'infrastructure_applied',
879
- telemetry: { projectName: actualProjectName },
880
- errorCode: 'OIDC_ADOPT_NON_INTERACTIVE',
881
- });
882
- if (refused) return refused;
883
- let adopt = shouldAutoApprove(options);
884
- if (!adopt) {
885
- const confirmed = await confirm({
886
- message: 'Adopt the existing GitHub OIDC provider (writes create_oidc_provider = false) and retry?',
887
- initialValue: true,
888
- });
889
- adopt = !isCancel(confirmed) && confirmed === true;
890
- }
891
- if (adopt) {
892
- try {
870
+ const recovery = await offerInFlowRecovery({
871
+ options,
872
+ refusal: {
873
+ message: '\n✖ apply needs approval to adopt the existing GitHub OIDC provider.',
874
+ hint: ' Re-run with --auto-approve to adopt non-interactively.\n',
875
+ event: 'infrastructure_applied',
876
+ telemetry: { projectName: actualProjectName },
877
+ errorCode: 'OIDC_ADOPT_NON_INTERACTIVE',
878
+ },
879
+ approve: () => confirmRecoveryAction(
880
+ 'Adopt the existing GitHub OIDC provider (writes create_oidc_provider = false) and retry?'
881
+ ),
882
+ act: async () => {
893
883
  upsertAutoTfvar(tfDir, 'create_oidc_provider', false);
894
- } catch (error) {
895
- // A failed write must not crash inside the error
896
- // handler: fall through to the manual guidance with
897
- // the write error appended.
898
- adoptUpsertError = error;
899
- }
900
- if (adoptUpsertError === null) {
901
- trackEvent('oidc_provider_adopted', { projectName: actualProjectName });
902
- log.message(color.cyan('Adopted the existing OIDC provider — retrying apply...'));
903
- return applyStack({ ...options, _skipPreview: true, _oidcAdopted: true });
904
- }
884
+ },
885
+ });
886
+ if (recovery.status === 'refused') return recovery.refusal;
887
+ if (recovery.status === 'recovered') {
888
+ trackEvent('oidc_provider_adopted', { projectName: actualProjectName });
889
+ log.message(color.cyan('Adopted the existing OIDC provider — retrying apply...'));
890
+ return applyStack({ ...options, _skipPreview: true, _oidcAdopted: true });
905
891
  }
906
- // Declined (or unwritable): fall through to the manual guidance below.
892
+ // A failed write must not crash inside the error handler:
893
+ // fall through to the manual guidance with the write error
894
+ // appended. Declined runs fall through the same way.
895
+ if (recovery.status === 'failed') adoptUpsertError = recovery.error;
907
896
  }
908
897
 
909
898
  if (code === 'OIDC_PROVIDER_CONFLICT') {
@@ -928,36 +917,32 @@ async function applyStackMain(input = {}) {
928
917
  // Offer the reconfigure in-flow instead of shelling the
929
918
  // user out to raw terraform; declined or failed runs
930
919
  // fall through to the runbook below.
931
- const refused = await refuseIfNonInteractive(options, {
932
- message: '\n✖ apply needs approval to reconfigure the Terraform backend.',
933
- hint: ' Re-run with --auto-approve to reconfigure non-interactively.\n',
934
- event: 'infrastructure_applied',
935
- telemetry: { projectName: actualProjectName },
936
- errorCode: 'BACKEND_RECONFIGURE_NON_INTERACTIVE',
937
- });
938
- if (refused) return refused;
939
- let proceed = shouldAutoApprove(options);
940
- if (!proceed) {
941
- const confirmed = await confirm({
942
- message: 'Reconfigure the Terraform backend (init -reconfigure) and retry?',
943
- initialValue: true,
944
- });
945
- proceed = !isCancel(confirmed) && confirmed === true;
946
- }
947
- if (proceed) {
948
- try {
920
+ const recovery = await offerInFlowRecovery({
921
+ options,
922
+ refusal: {
923
+ message: '\n✖ apply needs approval to reconfigure the Terraform backend.',
924
+ hint: ' Re-run with --auto-approve to reconfigure non-interactively.\n',
925
+ event: 'infrastructure_applied',
926
+ telemetry: { projectName: actualProjectName },
927
+ errorCode: 'BACKEND_RECONFIGURE_NON_INTERACTIVE',
928
+ },
929
+ approve: () => confirmRecoveryAction(
930
+ 'Reconfigure the Terraform backend (init -reconfigure) and retry?'
931
+ ),
932
+ act: async () => {
949
933
  await runTerraform(['init', '-reconfigure'], tfDir, null, 'Reconfiguring backend');
950
- } catch (error) {
951
- reconfigureError = error;
952
- }
953
- if (reconfigureError === null) {
954
- trackEvent('backend_reconfigured', { projectName: actualProjectName });
955
- log.message(color.cyan('Reconfigured the backend — retrying apply...'));
956
- return applyStack({ ...options, _skipPreview: true, _backendReconfigured: true });
957
- }
934
+ },
935
+ });
936
+ if (recovery.status === 'refused') return recovery.refusal;
937
+ if (recovery.status === 'recovered') {
938
+ trackEvent('backend_reconfigured', { projectName: actualProjectName });
939
+ log.message(color.cyan('Reconfigured the backend — retrying apply...'));
940
+ return applyStack({ ...options, _skipPreview: true, _backendReconfigured: true });
958
941
  }
942
+ if (recovery.status === 'failed') reconfigureError = recovery.error;
959
943
  }
960
944
  let secretRecoveryError = null;
945
+ let secretImported = false;
961
946
  if (code === 'SECRET_PENDING_DELETION' && secretName && options._secretRecovered !== true) {
962
947
  // Offer the recovery in-flow instead of shelling the user
963
948
  // out to pasted AWS CLI + raw terraform; declined, failed,
@@ -965,29 +950,30 @@ async function applyStackMain(input = {}) {
965
950
  // runbook below. Restore is non-destructive (auto under
966
951
  // --auto-approve); force-delete always needs an explicit
967
952
  // interactive choice, never auto.
968
- const refused = await refuseIfNonInteractive(options, {
969
- message: '\n✖ apply needs approval to recover the deleted secret vault.',
970
- hint: ' Re-run with --auto-approve to restore non-interactively.\n',
971
- event: 'infrastructure_applied',
972
- telemetry: { projectName: actualProjectName },
973
- errorCode: 'SECRET_RECOVERY_NON_INTERACTIVE',
974
- });
975
- if (refused) return refused;
976
- let method = shouldAutoApprove(options) ? 'restore' : null;
977
- if (!method) {
978
- const choice = await select({
979
- message: `Secret "${secretName}" is scheduled for deletion — recover it and retry?`,
980
- options: [
981
- { value: 'restore', label: 'Restore the vault, import, and retry' },
982
- { value: 'force-delete', label: 'Force-delete without recovery and retry' },
983
- { value: 'cancel', label: 'Cancel (show manual steps)' },
984
- ],
985
- });
986
- if (!isCancel(choice) && (choice === 'restore' || choice === 'force-delete')) method = choice;
987
- }
988
- if (method) {
989
- let versionAdopted = null;
990
- try {
953
+ let versionAdopted = null;
954
+ const recovery = await offerInFlowRecovery({
955
+ options,
956
+ refusal: {
957
+ message: '\n✖ apply needs approval to recover the deleted secret vault.',
958
+ hint: ' Re-run with --auto-approve to restore non-interactively.\n',
959
+ event: 'infrastructure_applied',
960
+ telemetry: { projectName: actualProjectName },
961
+ errorCode: 'SECRET_RECOVERY_NON_INTERACTIVE',
962
+ },
963
+ approve: async () => {
964
+ const choice = await select({
965
+ message: `Secret "${secretName}" is scheduled for deletion — recover it and retry?`,
966
+ options: [
967
+ { value: 'restore', label: 'Restore the vault, import, and retry' },
968
+ { value: 'force-delete', label: 'Force-delete without recovery and retry' },
969
+ { value: 'cancel', label: 'Cancel (show manual steps)' },
970
+ ],
971
+ });
972
+ if (!isCancel(choice) && (choice === 'restore' || choice === 'force-delete')) return choice;
973
+ return null;
974
+ },
975
+ autoMethod: 'restore',
976
+ act: async (method) => {
991
977
  const targetRegion = detectedConfig.region || process.env.AWS_REGION || 'us-east-2';
992
978
  const client = resolveClient(options.secretsClient, SecretsManagerClient, { region: targetRegion });
993
979
  if (method === 'restore') {
@@ -999,6 +985,7 @@ async function applyStackMain(input = {}) {
999
985
  // Argv-spawned (no shell), so the count index
1000
986
  // needs no quoting — unlike the printed runbook.
1001
987
  await runTerraform(['import', 'aws_secretsmanager_secret.app_secrets[0]', described.ARN], tfDir, null, `Importing ${secretName}`);
988
+ secretImported = true;
1002
989
  // Adopt the live current version too: without
1003
990
  // it the retry recreates the placeholder
1004
991
  // version over the restored real values
@@ -1011,29 +998,30 @@ async function applyStackMain(input = {}) {
1011
998
  } else {
1012
999
  await client.send(new DeleteSecretCommand({ SecretId: secretName, ForceDeleteWithoutRecovery: true }));
1013
1000
  }
1014
- } catch (error) {
1015
- secretRecoveryError = error;
1016
- }
1017
- if (secretRecoveryError === null) {
1018
- trackEvent('secret_deletion_recovered', {
1019
- projectName: actualProjectName,
1020
- method,
1021
- ...(method === 'restore' ? { adopted: versionAdopted === true } : {}),
1022
- });
1023
- if (method === 'restore') {
1024
- if (versionAdopted) {
1025
- log.message(color.cyan('Restored the secret vault and adopted its live values — retrying apply...'));
1026
- } else {
1027
- log.message(color.cyan('Restored the secret vault and imported it — retrying apply...'));
1028
- log.message(color.yellow(' Live values could not be adopted: run secrets audit after apply and re-push if they look wrong.'));
1029
- }
1001
+ },
1002
+ });
1003
+ if (recovery.status === 'refused') return recovery.refusal;
1004
+ if (recovery.status === 'recovered') {
1005
+ const method = recovery.method;
1006
+ trackEvent('secret_deletion_recovered', {
1007
+ projectName: actualProjectName,
1008
+ method,
1009
+ ...(method === 'restore' ? { adopted: versionAdopted === true } : {}),
1010
+ });
1011
+ if (method === 'restore') {
1012
+ if (versionAdopted) {
1013
+ log.message(color.cyan('Restored the secret vault and adopted its live values — retrying apply...'));
1030
1014
  } else {
1031
- log.message(color.cyan('Force-deleted the secret vault — retrying apply...'));
1032
- log.message(color.dim(' Re-push your secrets after apply (secrets push): the vault is recreated empty.'));
1015
+ log.message(color.cyan('Restored the secret vault and imported it — retrying apply...'));
1016
+ log.message(color.yellow(' Live values could not be adopted: run secrets audit after apply and re-push if they look wrong.'));
1033
1017
  }
1034
- return applyStack({ ...options, _skipPreview: true, _secretRecovered: true });
1018
+ } else {
1019
+ log.message(color.cyan('Force-deleted the secret vault — retrying apply...'));
1020
+ log.message(color.dim(' Re-push your secrets after apply (secrets push): the vault is recreated empty.'));
1035
1021
  }
1022
+ return applyStack({ ...options, _skipPreview: true, _secretRecovered: true });
1036
1023
  }
1024
+ if (recovery.status === 'failed') secretRecoveryError = recovery.error;
1037
1025
  }
1038
1026
  const runbook = getRunbook(code, { headless: shouldAutoApprove(options), lockId, secretName });
1039
1027
  log.error(color.red(`✖ ${runbook.message}`));
@@ -1044,6 +1032,9 @@ async function applyStackMain(input = {}) {
1044
1032
  if (secretRecoveryError) {
1045
1033
  log.message(color.dim(` (Automatic recovery failed: ${secretRecoveryError.message})`));
1046
1034
  }
1035
+ if (secretRecoveryError && secretImported) {
1036
+ log.message(color.yellow(' The vault is already imported — run the version-adopt import from the steps above before re-applying, or the live values will be overwritten with placeholders.'));
1037
+ }
1047
1038
  log.message(color.dim(errString.split('\n').slice(0, 8).join('\n')));
1048
1039
  } else {
1049
1040
  // Generic fallback for unknown errors