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 +1 -1
- package/src/commands/apply.js +116 -125
- package/src/commands/init.js +1023 -834
- package/src/utils/recovery.js +35 -1
- package/src/utils/terraform-errors.js +2 -2
package/package.json
CHANGED
package/src/commands/apply.js
CHANGED
|
@@ -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
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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
|
-
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
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
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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
|
-
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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
|
-
//
|
|
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
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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
|
-
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
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
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
})
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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('
|
|
1032
|
-
log.message(color.
|
|
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
|
-
|
|
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
|