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 {
407
407
const stack = this . getStackExecutor (
408
408
getSingleStack ( stacks , opts ?. stackName , "diff" ) ,
409
409
) ;
410
- await stack . initalizeTerraform ( opts . noColor , opts . skipProviderLock ) ;
410
+ await stack . initalizeTerraform (
411
+ opts . noColor ,
412
+ opts . skipProviderLock ,
413
+ opts . migrateState ,
414
+ ) ;
411
415
412
416
try {
413
417
await stack . diff ( opts ) ;
@@ -459,6 +463,7 @@ export class CdktfProject {
459
463
await this . initializeStacksToRunInSerial (
460
464
opts . noColor ,
461
465
opts . skipProviderLock ,
466
+ opts . migrateState ,
462
467
) ;
463
468
while ( this . stacksToRun . filter ( ( stack ) => stack . isPending ) . length > 0 ) {
464
469
const runningStacks = this . stacksToRun . filter ( ( stack ) => stack . isRunning ) ;
@@ -687,9 +692,10 @@ export class CdktfProject {
687
692
private async initializeStacksToRunInSerial (
688
693
noColor ?: boolean ,
689
694
skipProviderLock ?: boolean ,
695
+ migrateState ?: boolean ,
690
696
) : Promise < void > {
691
697
for ( const stack of this . stacksToRun ) {
692
- await stack . initalizeTerraform ( noColor , skipProviderLock ) ;
698
+ await stack . initalizeTerraform ( noColor , skipProviderLock , migrateState ) ;
693
699
}
694
700
}
695
701
}
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ export class CdktfStack {
253
253
public async initalizeTerraform (
254
254
noColor ?: boolean ,
255
255
skipProviderLock ?: boolean ,
256
+ migrateState ?: boolean ,
256
257
) {
257
258
const terraform = await this . terraformClient ( ) ;
258
259
const needsLockfileUpdate = skipProviderLock
@@ -263,7 +264,7 @@ export class CdktfStack {
263
264
needsUpgrade,
264
265
noColor : noColor ?? false ,
265
266
needsLockfileUpdate,
266
- migrateState : this . options . migrateState ?? false ,
267
+ migrateState : migrateState ?? false ,
267
268
} ) ;
268
269
return terraform ;
269
270
}
Original file line number Diff line number Diff line change @@ -126,6 +126,9 @@ export class TerraformCli implements Terraform {
126
126
if ( opts . noColor ) {
127
127
args . push ( "-no-color" ) ;
128
128
}
129
+ if ( opts . migrateState ) {
130
+ args . push ( "-migrate-state" ) ;
131
+ }
129
132
130
133
// eslint-disable-next-line @typescript-eslint/no-empty-function
131
134
let initCanNotContinue = ( _err : any ) => { } ;
@@ -145,7 +148,11 @@ export class TerraformCli implements Terraform {
145
148
} ,
146
149
( data ) => {
147
150
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
149
156
if ( opts . migrateState ) {
150
157
actions . writeLine ( "yes" ) ;
151
158
} else {
You can’t perform that action at this time.
0 commit comments