Skip to content

feat: Skip Provider Locking on request #3879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/@cdktf/cli-core/src/lib/cdktf-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,31 @@ export type SkipSynthOptions = {
skipSynth?: boolean;
};

export type FetchOutputOptions = SkipSynthOptions & MultipleStackOptions;
export type SkipProviderLockOptions = {
skipProviderLock?: boolean;
};

export type FetchOutputOptions = SkipSynthOptions &
SkipProviderLockOptions &
MultipleStackOptions;

export type AutoApproveOptions = {
autoApprove?: boolean;
};

export type DiffOptions = SingleStackOptions &
SkipProviderLockOptions &
SkipSynthOptions & {
refreshOnly?: boolean;
terraformParallelism?: number;
vars?: string[];
varFiles?: string[];
noColor?: boolean;
migrateState?: boolean;
skipSynth?: boolean;
};

export type MutationOptions = MultipleStackOptions &
SkipProviderLockOptions &
SkipSynthOptions &
AutoApproveOptions & {
refreshOnly?: boolean;
Expand Down Expand Up @@ -400,7 +407,7 @@ export class CdktfProject {
const stack = this.getStackExecutor(
getSingleStack(stacks, opts?.stackName, "diff"),
);
await stack.initalizeTerraform(opts.noColor);
await stack.initalizeTerraform(opts.noColor, opts.skipProviderLock);

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

await this.initializeStacksToRunInSerial(opts.noColor);
await this.initializeStacksToRunInSerial(
opts.noColor,
opts.skipProviderLock,
);
while (this.stacksToRun.filter((stack) => stack.isPending).length > 0) {
const runningStacks = this.stacksToRun.filter((stack) => stack.isRunning);
if (runningStacks.length >= maxParallelRuns) {
Expand Down Expand Up @@ -657,7 +667,7 @@ export class CdktfProject {
this.getStackExecutor(stack, {}),
);

await this.initializeStacksToRunInSerial();
await this.initializeStacksToRunInSerial(undefined, opts.skipProviderLock);
const outputs = await Promise.all(
this.stacksToRun.map(async (s) => {
const output = await s.fetchOutputs();
Expand All @@ -676,9 +686,10 @@ export class CdktfProject {
// Serially run terraform init to prohibit text file busy errors for the cache files
private async initializeStacksToRunInSerial(
noColor?: boolean,
skipProviderLock?: boolean,
): Promise<void> {
for (const stack of this.stacksToRun) {
await stack.initalizeTerraform(noColor);
await stack.initalizeTerraform(noColor, skipProviderLock);
}
}
}
9 changes: 7 additions & 2 deletions packages/@cdktf/cli-core/src/lib/cdktf-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,14 @@ export class CdktfStack {
);
}

public async initalizeTerraform(noColor?: boolean) {
public async initalizeTerraform(
noColor?: boolean,
skipProviderLock?: boolean,
) {
const terraform = await this.terraformClient();
const needsLockfileUpdate = await this.checkNeedsLockfileUpdate();
const needsLockfileUpdate = skipProviderLock
? false
: await this.checkNeedsLockfileUpdate();
const needsUpgrade = await this.checkNeedsUpgrade();
await terraform.init({
needsUpgrade,
Expand Down
6 changes: 6 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class Command extends BaseCommand {
required: false,
desc: "Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date",
})
.option("skip-provider-lock", {
type: "boolean",
default: false,
required: false,
desc: "Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform",
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
6 changes: 6 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class Command extends BaseCommand {
required: false,
desc: "Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date",
})
.option("skip-provider-lock", {
type: "boolean",
default: false,
required: false,
desc: "Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform",
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
6 changes: 6 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Command extends BaseCommand {
required: false,
desc: "Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date",
})
.option("skip-provider-lock", {
type: "boolean",
default: false,
required: false,
desc: "Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform",
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
8 changes: 8 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export async function deploy(argv: any) {
const noColor = argv.noColor;
const migrateState = argv.migrateState;
const skipSynth = argv.skipSynth;
const skipProviderLock = argv.skipProviderLock;

let outputsPath: string | undefined = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down Expand Up @@ -225,6 +226,7 @@ export async function deploy(argv: any) {
noColor,
migrateState,
skipSynth,
skipProviderLock,
}),
);
}
Expand All @@ -247,6 +249,7 @@ export async function destroy(argv: any) {
const noColor = argv.noColor;
const migrateState = argv.migrateState;
const skipSynth = argv.skipSynth;
const skipProviderLock = argv.skipProviderLock;

await renderInk(
React.createElement(Destroy, {
Expand All @@ -262,6 +265,7 @@ export async function destroy(argv: any) {
noColor,
migrateState,
skipSynth,
skipProviderLock,
}),
);
}
Expand All @@ -281,6 +285,7 @@ export async function diff(argv: any) {
const noColor = argv.noColor;
const migrateState = argv.migrateState;
const skipSynth = argv.skipSynth;
const skipProviderLock = argv.skipProviderLock;

await renderInk(
React.createElement(Diff, {
Expand All @@ -294,6 +299,7 @@ export async function diff(argv: any) {
noColor,
migrateState,
skipSynth,
skipProviderLock,
}),
);
}
Expand Down Expand Up @@ -519,6 +525,7 @@ export async function output(argv: any) {
const stacks = argv.stacks;
const includeSensitiveOutputs = argv.outputsFileIncludeSensitiveOutputs;
const skipSynth = argv.skipSynth;
const skipProviderLock = argv.skipProviderLock;
let outputsPath: string | undefined = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
let onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void = () => {};
Expand All @@ -537,6 +544,7 @@ export async function output(argv: any) {
onOutputsRetrieved,
outputsPath,
skipSynth,
skipProviderLock,
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class Command extends BaseCommand {
required: false,
desc: "Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date",
})
.option("skip-provider-lock", {
type: "boolean",
default: false,
required: false,
desc: "Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform",
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ interface DeployConfig {
noColor?: boolean;
migrateState?: boolean;
skipSynth?: boolean;
skipProviderLock?: boolean;
}

export const Deploy = ({
Expand All @@ -85,6 +86,7 @@ export const Deploy = ({
noColor,
migrateState,
skipSynth,
skipProviderLock,
}: DeployConfig): React.ReactElement => {
const [outputs, setOutputs] = useState<NestedTerraformOutputs>();
const { status, logEntries } = useCdktfProject(
Expand All @@ -102,6 +104,7 @@ export const Deploy = ({
noColor,
migrateState,
skipSynth,
skipProviderLock,
});

if (onOutputsRetrieved) {
Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface DestroyConfig {
vars?: string[];
varFiles?: string[];
skipSynth?: boolean;
skipProviderLock?: boolean;
}

export const Destroy = ({
Expand All @@ -42,6 +43,7 @@ export const Destroy = ({
vars,
varFiles,
skipSynth,
skipProviderLock,
}: DestroyConfig): React.ReactElement => {
const { status, logEntries } = useCdktfProject(
{ outDir, synthCommand },
Expand All @@ -57,6 +59,7 @@ export const Destroy = ({
vars,
varFiles,
skipSynth,
skipProviderLock,
}),
);

Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/ui/diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface DiffConfig {
noColor?: boolean;
migrateState?: boolean;
skipSynth?: boolean;
skipProviderLock?: boolean;
}

export const Diff = ({
Expand All @@ -32,6 +33,7 @@ export const Diff = ({
noColor,
migrateState,
skipSynth,
skipProviderLock,
}: DiffConfig): React.ReactElement => {
const { status, logEntries } = useCdktfProject(
{ outDir, synthCommand },
Expand All @@ -45,6 +47,7 @@ export const Diff = ({
noColor,
migrateState,
skipSynth,
skipProviderLock,
}),
);

Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/src/bin/cmds/ui/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type OutputConfig = {
onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void;
outputsPath?: string;
skipSynth?: boolean;
skipProviderLock?: boolean;
};

export const Output = ({
Expand All @@ -25,13 +26,15 @@ export const Output = ({
onOutputsRetrieved,
outputsPath,
skipSynth,
skipProviderLock,
}: OutputConfig): React.ReactElement => {
const { status, logEntries, returnValue } = useCdktfProject(
{ outDir, synthCommand },
async (project) => {
const outputs = await project.fetchOutputs({
stackNames: targetStacks,
skipSynth,
skipProviderLock,
});
onOutputsRetrieved(outputs);
return outputs;
Expand Down
Loading
Loading