File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
packages/@cdktf/cli-core/src/lib Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -407,7 +407,11 @@ export class CdktfProject {
407407 const stack = this . getStackExecutor (
408408 getSingleStack ( stacks , opts ?. stackName , "diff" ) ,
409409 ) ;
410- await stack . initalizeTerraform ( opts . noColor , opts . skipProviderLock ) ;
410+ await stack . initalizeTerraform (
411+ opts . noColor ,
412+ opts . skipProviderLock ,
413+ opts . migrateState ,
414+ ) ;
411415
412416 try {
413417 await stack . diff ( opts ) ;
@@ -459,6 +463,7 @@ export class CdktfProject {
459463 await this . initializeStacksToRunInSerial (
460464 opts . noColor ,
461465 opts . skipProviderLock ,
466+ opts . migrateState ,
462467 ) ;
463468 while ( this . stacksToRun . filter ( ( stack ) => stack . isPending ) . length > 0 ) {
464469 const runningStacks = this . stacksToRun . filter ( ( stack ) => stack . isRunning ) ;
@@ -687,9 +692,10 @@ export class CdktfProject {
687692 private async initializeStacksToRunInSerial (
688693 noColor ?: boolean ,
689694 skipProviderLock ?: boolean ,
695+ migrateState ?: boolean ,
690696 ) : Promise < void > {
691697 for ( const stack of this . stacksToRun ) {
692- await stack . initalizeTerraform ( noColor , skipProviderLock ) ;
698+ await stack . initalizeTerraform ( noColor , skipProviderLock , migrateState ) ;
693699 }
694700 }
695701}
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ export class CdktfStack {
253253 public async initalizeTerraform (
254254 noColor ?: boolean ,
255255 skipProviderLock ?: boolean ,
256+ migrateState ?: boolean ,
256257 ) {
257258 const terraform = await this . terraformClient ( ) ;
258259 const needsLockfileUpdate = skipProviderLock
@@ -263,7 +264,7 @@ export class CdktfStack {
263264 needsUpgrade,
264265 noColor : noColor ?? false ,
265266 needsLockfileUpdate,
266- migrateState : this . options . migrateState ?? false ,
267+ migrateState : migrateState ?? false ,
267268 } ) ;
268269 return terraform ;
269270 }
Original file line number Diff line number Diff line change @@ -126,6 +126,9 @@ export class TerraformCli implements Terraform {
126126 if ( opts . noColor ) {
127127 args . push ( "-no-color" ) ;
128128 }
129+ if ( opts . migrateState ) {
130+ args . push ( "-migrate-state" ) ;
131+ }
129132
130133 // eslint-disable-next-line @typescript-eslint/no-empty-function
131134 let initCanNotContinue = ( _err : any ) => { } ;
@@ -145,7 +148,11 @@ export class TerraformCli implements Terraform {
145148 } ,
146149 ( data ) => {
147150 stdout ( data ) ;
148- if ( data . includes ( "Should Terraform migrate your existing state?" ) ) {
151+ if (
152+ data . includes ( "Should Terraform migrate your existing state?" ) ||
153+ data . includes ( "Do you want to copy existing state to the new backend" )
154+ ) {
155+ // TODO: This only happens when terraform is passed the -migrate-state anyway, so this check is redundant
149156 if ( opts . migrateState ) {
150157 actions . writeLine ( "yes" ) ;
151158 } else {
You can’t perform that action at this time.
0 commit comments