Skip to content
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

feat(cli): Add support for terraform's parallelism flag #2107

Merged
merged 18 commits into from
Oct 13, 2022
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
9 changes: 9 additions & 0 deletions packages/cdktf-cli/bin/cmds/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Command extends BaseCommand {
default: false,
})
.option("parallelism", {
// Note: This parallelism doesn't affect the underlying Terraform traversal parallelism
DanielMSchmidt marked this conversation as resolved.
Show resolved Hide resolved
// That is done by `terraform-parallelism`
type: "number",
required: false,
desc: "Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1",
Expand All @@ -67,6 +69,13 @@ class Command extends BaseCommand {
boolean: true,
desc: 'Select the "refresh only" planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.',
})
.option("terraform-parallelism", {
mutahhir marked this conversation as resolved.
Show resolved Hide resolved
type: "number",
required: false,
desc: "Forwards value as the `-parallelism` flag to Terraform. By default, the this flag is not forwarded to Terraform. Note: This flag is not supported by remote / cloud backend",
// Setting value to negative will prevent it from being forwarded to terraform as an argument
default: -1,
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
7 changes: 7 additions & 0 deletions packages/cdktf-cli/bin/cmds/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class Command extends BaseCommand {
desc: "Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1",
default: -1,
})
.option("terraform-parallelism", {
mutahhir marked this conversation as resolved.
Show resolved Hide resolved
type: "number",
required: false,
desc: "Forwards value as the `-parallelism` flag to Terraform. By default, the this flag is not forwarded to Terraform. Note: This flag is not supported by remote / cloud backend",
// Setting value to negative will prevent it from being forwarded to terraform as an argument
default: -1,
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
7 changes: 7 additions & 0 deletions packages/cdktf-cli/bin/cmds/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Command extends BaseCommand {
boolean: true,
desc: 'Select the "refresh only" planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.',
})
.option("terraform-parallelism", {
type: "number",
required: false,
desc: "Forwards value as the `-parallelism` flag to Terraform. By default, the this flag is not forwarded to Terraform. Note: This flag is not supported by remote / cloud backend",
// Setting value to negative will prevent it from being forwarded to terraform as an argument
default: -1,
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
26 changes: 20 additions & 6 deletions packages/cdktf-cli/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export async function deploy(argv: any) {
const stacks = argv.stacks;
const includeSensitiveOutputs = argv.outputsFileIncludeSensitiveOutputs;
const refreshOnly = argv.refreshOnly;
const terraformParallelism = argv.terraformParallelism;
const ignoreMissingStackDependencies =
argv.ignoreMissingStackDependencies || false;
const parallelism = argv.parallelism;

let outputsPath: string | undefined = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand All @@ -133,10 +137,10 @@ export async function deploy(argv: any) {
autoApprove,
onOutputsRetrieved,
outputsPath,
ignoreMissingStackDependencies:
argv.ignoreMissingStackDependencies || false,
parallelism: argv.parallelism,
ignoreMissingStackDependencies,
parallelism,
refreshOnly,
terraformParallelism,
})
);
}
Expand All @@ -150,16 +154,20 @@ export async function destroy(argv: any) {
const outDir = argv.output;
const autoApprove = argv.autoApprove;
const stacks = argv.stacks;
const ignoreMissingStackDependencies =
argv.ignoreMissingStackDependencies || false;
const parallelism = argv.parallelism;
const terraformParallelism = argv.terraformParallelism;

await renderInk(
React.createElement(Destroy, {
outDir,
targetStacks: stacks,
synthCommand: command,
autoApprove,
ignoreMissingStackDependencies:
argv.ignoreMissingStackDependencies || false,
parallelism: argv.parallelism,
ignoreMissingStackDependencies,
parallelism,
mutahhir marked this conversation as resolved.
Show resolved Hide resolved
terraformParallelism,
})
);
}
Expand All @@ -173,13 +181,15 @@ export async function diff(argv: any) {
const outDir = argv.output;
const stack = argv.stack;
const refreshOnly = argv.refreshOnly;
const terraformParallelism = argv.terraformParallelism;

await renderInk(
React.createElement(Diff, {
outDir,
refreshOnly,
targetStack: stack,
synthCommand: command,
terraformParallelism,
})
);
}
Expand Down Expand Up @@ -323,6 +333,8 @@ export async function watch(argv: any) {
const outDir = argv.output;
const autoApprove = argv.autoApprove;
const stacks = argv.stacks;
const terraformParallelism = argv.terraformParallelism;
const parallelism = argv.parallelism;

if (!autoApprove) {
console.error(
Expand All @@ -337,6 +349,8 @@ export async function watch(argv: any) {
targetStacks: stacks,
synthCommand: command,
autoApprove,
terraformParallelism,
parallelism,
})
);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/bin/cmds/ui/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface DeployConfig {
ignoreMissingStackDependencies?: boolean;
parallelism?: number;
refreshOnly?: boolean;
terraformParallelism?: number;
}

export const Deploy = ({
Expand All @@ -68,6 +69,7 @@ export const Deploy = ({
ignoreMissingStackDependencies,
parallelism,
refreshOnly,
terraformParallelism,
}: DeployConfig): React.ReactElement => {
const [outputs, setOutputs] = useState<NestedTerraformOutputs>();
const { status, logEntries } = useCdktfProject(
Expand All @@ -79,6 +81,7 @@ export const Deploy = ({
ignoreMissingStackDependencies,
parallelism,
refreshOnly,
terraformParallelism,
});

if (onOutputsRetrieved) {
Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/bin/cmds/ui/destroy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DestroyConfig {
autoApprove: boolean;
ignoreMissingStackDependencies?: boolean;
parallelism?: number;
terraformParallelism?: number;
}

export const Destroy = ({
Expand All @@ -24,6 +25,7 @@ export const Destroy = ({
autoApprove,
ignoreMissingStackDependencies,
parallelism,
terraformParallelism,
}: DestroyConfig): React.ReactElement => {
const { status, logEntries } = useCdktfProject(
{ outDir, synthCommand },
Expand All @@ -33,6 +35,7 @@ export const Destroy = ({
autoApprove,
ignoreMissingStackDependencies,
parallelism,
terraformParallelism,
})
);

Expand Down
9 changes: 8 additions & 1 deletion packages/cdktf-cli/bin/cmds/ui/diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ interface DiffConfig {
targetStack?: string;
synthCommand: string;
refreshOnly?: boolean;
terraformParallelism?: number;
}

export const Diff = ({
outDir,
targetStack,
synthCommand,
refreshOnly,
terraformParallelism,
}: DiffConfig): React.ReactElement => {
const { status, logEntries } = useCdktfProject(
{ outDir, synthCommand },
(project) => project.diff({ stackName: targetStack, refreshOnly })
(project) =>
project.diff({
stackName: targetStack,
refreshOnly,
terraformParallelism,
})
);

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/cdktf-cli/bin/cmds/ui/watch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface WatchConfig {
parallelism?: number;
synthCommand: string;
autoApprove: boolean;
terraformParallelism?: number;
}

export const Watch = ({
Expand All @@ -18,6 +19,7 @@ export const Watch = ({
synthCommand,
autoApprove,
parallelism,
terraformParallelism,
}: WatchConfig): React.ReactElement => {
const [logEntryId, setLogEntryId] = useState<number>(0);
const [logEntries, setLogEntries] = useState<LogEntry[]>([]);
Expand Down Expand Up @@ -57,6 +59,7 @@ export const Watch = ({
autoApprove,
stackNames: targetStacks,
parallelism,
terraformParallelism,
},
ac.signal,
(state) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/cdktf-cli/bin/cmds/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class Command extends BaseCommand {
desc: "Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1",
default: -1,
})
.option("terraform-parallelism", {
type: "number",
required: false,
desc: "Forwards value as the `-parallelism` flag to Terraform. By default, the this flag is not forwarded to Terraform. Note: This flag is not supported by remote / cloud backend",
// Setting value to negative will prevent it from being forwarded to terraform as an argument
default: -1,
})
.showHelpOnFail(true);

public async handleCommand(argv: any) {
Expand Down
Loading