Skip to content

Commit 4af72e3

Browse files
committed
chore: Prevent provider lock operation from running if disallowed by cli
1 parent 6f0477a commit 4af72e3

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

packages/@cdktf/cli-core/src/lib/cdktf-project.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,31 @@ export type SkipSynthOptions = {
7474
skipSynth?: boolean;
7575
};
7676

77-
export type FetchOutputOptions = SkipSynthOptions & MultipleStackOptions;
77+
export type SkipProviderLockOptions = {
78+
skipProviderLock?: boolean;
79+
};
80+
81+
export type FetchOutputOptions = SkipSynthOptions &
82+
SkipProviderLockOptions &
83+
MultipleStackOptions;
7884

7985
export type AutoApproveOptions = {
8086
autoApprove?: boolean;
8187
};
8288

8389
export type DiffOptions = SingleStackOptions &
90+
SkipProviderLockOptions &
8491
SkipSynthOptions & {
8592
refreshOnly?: boolean;
8693
terraformParallelism?: number;
8794
vars?: string[];
8895
varFiles?: string[];
8996
noColor?: boolean;
9097
migrateState?: boolean;
91-
skipSynth?: boolean;
9298
};
9399

94100
export type MutationOptions = MultipleStackOptions &
101+
SkipProviderLockOptions &
95102
SkipSynthOptions &
96103
AutoApproveOptions & {
97104
refreshOnly?: boolean;
@@ -400,7 +407,7 @@ export class CdktfProject {
400407
const stack = this.getStackExecutor(
401408
getSingleStack(stacks, opts?.stackName, "diff"),
402409
);
403-
await stack.initalizeTerraform(opts.noColor);
410+
await stack.initalizeTerraform(opts.noColor, opts.skipProviderLock);
404411

405412
try {
406413
await stack.diff(opts);
@@ -449,7 +456,10 @@ export class CdktfProject {
449456
!opts.parallelism || opts.parallelism < 0 ? Infinity : opts.parallelism;
450457
const allExecutions = [];
451458

452-
await this.initializeStacksToRunInSerial(opts.noColor);
459+
await this.initializeStacksToRunInSerial(
460+
opts.noColor,
461+
opts.skipProviderLock,
462+
);
453463
while (this.stacksToRun.filter((stack) => stack.isPending).length > 0) {
454464
const runningStacks = this.stacksToRun.filter((stack) => stack.isRunning);
455465
if (runningStacks.length >= maxParallelRuns) {
@@ -657,7 +667,7 @@ export class CdktfProject {
657667
this.getStackExecutor(stack, {}),
658668
);
659669

660-
await this.initializeStacksToRunInSerial();
670+
await this.initializeStacksToRunInSerial(undefined, opts.skipProviderLock);
661671
const outputs = await Promise.all(
662672
this.stacksToRun.map(async (s) => {
663673
const output = await s.fetchOutputs();
@@ -676,9 +686,10 @@ export class CdktfProject {
676686
// Serially run terraform init to prohibit text file busy errors for the cache files
677687
private async initializeStacksToRunInSerial(
678688
noColor?: boolean,
689+
skipProviderLock?: boolean,
679690
): Promise<void> {
680691
for (const stack of this.stacksToRun) {
681-
await stack.initalizeTerraform(noColor);
692+
await stack.initalizeTerraform(noColor, skipProviderLock);
682693
}
683694
}
684695
}

packages/@cdktf/cli-core/src/lib/cdktf-stack.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,14 @@ export class CdktfStack {
250250
);
251251
}
252252

253-
public async initalizeTerraform(noColor?: boolean) {
253+
public async initalizeTerraform(
254+
noColor?: boolean,
255+
skipProviderLock?: boolean,
256+
) {
254257
const terraform = await this.terraformClient();
255-
const needsLockfileUpdate = await this.checkNeedsLockfileUpdate();
258+
const needsLockfileUpdate = skipProviderLock
259+
? false
260+
: await this.checkNeedsLockfileUpdate();
256261
const needsUpgrade = await this.checkNeedsUpgrade();
257262
await terraform.init({
258263
needsUpgrade,

packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ interface DeployConfig {
6767
noColor?: boolean;
6868
migrateState?: boolean;
6969
skipSynth?: boolean;
70+
skipProviderLock?: boolean;
7071
}
7172

7273
export const Deploy = ({
@@ -85,6 +86,7 @@ export const Deploy = ({
8586
noColor,
8687
migrateState,
8788
skipSynth,
89+
skipProviderLock,
8890
}: DeployConfig): React.ReactElement => {
8991
const [outputs, setOutputs] = useState<NestedTerraformOutputs>();
9092
const { status, logEntries } = useCdktfProject(
@@ -102,6 +104,7 @@ export const Deploy = ({
102104
noColor,
103105
migrateState,
104106
skipSynth,
107+
skipProviderLock,
105108
});
106109

107110
if (onOutputsRetrieved) {

packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface DestroyConfig {
2727
vars?: string[];
2828
varFiles?: string[];
2929
skipSynth?: boolean;
30+
skipProviderLock?: boolean;
3031
}
3132

3233
export const Destroy = ({
@@ -42,6 +43,7 @@ export const Destroy = ({
4243
vars,
4344
varFiles,
4445
skipSynth,
46+
skipProviderLock,
4547
}: DestroyConfig): React.ReactElement => {
4648
const { status, logEntries } = useCdktfProject(
4749
{ outDir, synthCommand },
@@ -57,6 +59,7 @@ export const Destroy = ({
5759
vars,
5860
varFiles,
5961
skipSynth,
62+
skipProviderLock,
6063
}),
6164
);
6265

packages/cdktf-cli/src/bin/cmds/ui/diff.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DiffConfig {
1919
noColor?: boolean;
2020
migrateState?: boolean;
2121
skipSynth?: boolean;
22+
skipProviderLock?: boolean;
2223
}
2324

2425
export const Diff = ({
@@ -32,6 +33,7 @@ export const Diff = ({
3233
noColor,
3334
migrateState,
3435
skipSynth,
36+
skipProviderLock,
3537
}: DiffConfig): React.ReactElement => {
3638
const { status, logEntries } = useCdktfProject(
3739
{ outDir, synthCommand },
@@ -45,6 +47,7 @@ export const Diff = ({
4547
noColor,
4648
migrateState,
4749
skipSynth,
50+
skipProviderLock,
4851
}),
4952
);
5053

0 commit comments

Comments
 (0)