diff --git a/packages/@cdktf/cli-core/src/lib/cdktf-project.ts b/packages/@cdktf/cli-core/src/lib/cdktf-project.ts index 33f2c6eb63..0d386e5828 100644 --- a/packages/@cdktf/cli-core/src/lib/cdktf-project.ts +++ b/packages/@cdktf/cli-core/src/lib/cdktf-project.ts @@ -74,13 +74,20 @@ 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; @@ -88,10 +95,10 @@ export type DiffOptions = SingleStackOptions & varFiles?: string[]; noColor?: boolean; migrateState?: boolean; - skipSynth?: boolean; }; export type MutationOptions = MultipleStackOptions & + SkipProviderLockOptions & SkipSynthOptions & AutoApproveOptions & { refreshOnly?: boolean; @@ -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); @@ -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) { @@ -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(); @@ -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 { for (const stack of this.stacksToRun) { - await stack.initalizeTerraform(noColor); + await stack.initalizeTerraform(noColor, skipProviderLock); } } } diff --git a/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts b/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts index e2210a0646..32a926fab5 100644 --- a/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts +++ b/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts @@ -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, diff --git a/packages/cdktf-cli/src/bin/cmds/deploy.ts b/packages/cdktf-cli/src/bin/cmds/deploy.ts index d2cb2f8f34..e55f76a124 100644 --- a/packages/cdktf-cli/src/bin/cmds/deploy.ts +++ b/packages/cdktf-cli/src/bin/cmds/deploy.ts @@ -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) { diff --git a/packages/cdktf-cli/src/bin/cmds/destroy.ts b/packages/cdktf-cli/src/bin/cmds/destroy.ts index 9a41c91524..2cb27160f3 100644 --- a/packages/cdktf-cli/src/bin/cmds/destroy.ts +++ b/packages/cdktf-cli/src/bin/cmds/destroy.ts @@ -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) { diff --git a/packages/cdktf-cli/src/bin/cmds/diff.ts b/packages/cdktf-cli/src/bin/cmds/diff.ts index fe2f8f9dd8..391ec202a2 100644 --- a/packages/cdktf-cli/src/bin/cmds/diff.ts +++ b/packages/cdktf-cli/src/bin/cmds/diff.ts @@ -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) { diff --git a/packages/cdktf-cli/src/bin/cmds/handlers.ts b/packages/cdktf-cli/src/bin/cmds/handlers.ts index 01551c9f08..97324aaac9 100644 --- a/packages/cdktf-cli/src/bin/cmds/handlers.ts +++ b/packages/cdktf-cli/src/bin/cmds/handlers.ts @@ -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 @@ -225,6 +226,7 @@ export async function deploy(argv: any) { noColor, migrateState, skipSynth, + skipProviderLock, }), ); } @@ -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, { @@ -262,6 +265,7 @@ export async function destroy(argv: any) { noColor, migrateState, skipSynth, + skipProviderLock, }), ); } @@ -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, { @@ -294,6 +299,7 @@ export async function diff(argv: any) { noColor, migrateState, skipSynth, + skipProviderLock, }), ); } @@ -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 = () => {}; @@ -537,6 +544,7 @@ export async function output(argv: any) { onOutputsRetrieved, outputsPath, skipSynth, + skipProviderLock, }), ); } diff --git a/packages/cdktf-cli/src/bin/cmds/output.ts b/packages/cdktf-cli/src/bin/cmds/output.ts index b4c1af253a..10a28336f6 100644 --- a/packages/cdktf-cli/src/bin/cmds/output.ts +++ b/packages/cdktf-cli/src/bin/cmds/output.ts @@ -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) { diff --git a/packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx b/packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx index d8951915a3..70a860f9d6 100644 --- a/packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx +++ b/packages/cdktf-cli/src/bin/cmds/ui/deploy.tsx @@ -67,6 +67,7 @@ interface DeployConfig { noColor?: boolean; migrateState?: boolean; skipSynth?: boolean; + skipProviderLock?: boolean; } export const Deploy = ({ @@ -85,6 +86,7 @@ export const Deploy = ({ noColor, migrateState, skipSynth, + skipProviderLock, }: DeployConfig): React.ReactElement => { const [outputs, setOutputs] = useState(); const { status, logEntries } = useCdktfProject( @@ -102,6 +104,7 @@ export const Deploy = ({ noColor, migrateState, skipSynth, + skipProviderLock, }); if (onOutputsRetrieved) { diff --git a/packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx b/packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx index 915ffb0f97..64b5be42a7 100644 --- a/packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx +++ b/packages/cdktf-cli/src/bin/cmds/ui/destroy.tsx @@ -27,6 +27,7 @@ interface DestroyConfig { vars?: string[]; varFiles?: string[]; skipSynth?: boolean; + skipProviderLock?: boolean; } export const Destroy = ({ @@ -42,6 +43,7 @@ export const Destroy = ({ vars, varFiles, skipSynth, + skipProviderLock, }: DestroyConfig): React.ReactElement => { const { status, logEntries } = useCdktfProject( { outDir, synthCommand }, @@ -57,6 +59,7 @@ export const Destroy = ({ vars, varFiles, skipSynth, + skipProviderLock, }), ); diff --git a/packages/cdktf-cli/src/bin/cmds/ui/diff.tsx b/packages/cdktf-cli/src/bin/cmds/ui/diff.tsx index 34b69dfa7b..fa1fbf63e7 100644 --- a/packages/cdktf-cli/src/bin/cmds/ui/diff.tsx +++ b/packages/cdktf-cli/src/bin/cmds/ui/diff.tsx @@ -19,6 +19,7 @@ interface DiffConfig { noColor?: boolean; migrateState?: boolean; skipSynth?: boolean; + skipProviderLock?: boolean; } export const Diff = ({ @@ -32,6 +33,7 @@ export const Diff = ({ noColor, migrateState, skipSynth, + skipProviderLock, }: DiffConfig): React.ReactElement => { const { status, logEntries } = useCdktfProject( { outDir, synthCommand }, @@ -45,6 +47,7 @@ export const Diff = ({ noColor, migrateState, skipSynth, + skipProviderLock, }), ); diff --git a/packages/cdktf-cli/src/bin/cmds/ui/output.tsx b/packages/cdktf-cli/src/bin/cmds/ui/output.tsx index 2ebe417579..9a9c3188cb 100644 --- a/packages/cdktf-cli/src/bin/cmds/ui/output.tsx +++ b/packages/cdktf-cli/src/bin/cmds/ui/output.tsx @@ -16,6 +16,7 @@ type OutputConfig = { onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void; outputsPath?: string; skipSynth?: boolean; + skipProviderLock?: boolean; }; export const Output = ({ @@ -25,6 +26,7 @@ export const Output = ({ onOutputsRetrieved, outputsPath, skipSynth, + skipProviderLock, }: OutputConfig): React.ReactElement => { const { status, logEntries, returnValue } = useCdktfProject( { outDir, synthCommand }, @@ -32,6 +34,7 @@ export const Output = ({ const outputs = await project.fetchOutputs({ stackNames: targetStacks, skipSynth, + skipProviderLock, }); onOutputsRetrieved(outputs); return outputs; diff --git a/website/docs/cdktf/cli-reference/commands.mdx b/website/docs/cdktf/cli-reference/commands.mdx index fd71a2daed..e9f7c99656 100644 --- a/website/docs/cdktf/cli-reference/commands.mdx +++ b/website/docs/cdktf/cli-reference/commands.mdx @@ -142,7 +142,7 @@ pbpaste | cdktf convert --language python | pbcopy This command deploys a given application. ```bash -$ cdktf deploy --help +cdktf deploy --help ``` **Help Output** @@ -153,36 +153,38 @@ cdktf deploy [stacks...] Deploy the given stacks Positionals: - stacks Deploy stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] + stacks Deploy stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] Options: - --version Show version number [boolean] + --version Show version number [boolean] --experimental-provider-schema-cache-path An experimental schema cache that can be used to improve the speed of cdktf get and convert. Supported using the env - CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] + CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] --disable-plugin-cache-env Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the plugin cache is configured differently. Supported using the env - CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] - --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] - --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard - out at the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY - -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] - -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] - --auto-approve Auto approve [boolean] [default: false] - --outputs-file Path to file where stack outputs will be written as JSON [string] - --outputs-file-include-sensitive-outputs Whether to include sensitive outputs in the output file [boolean] [default: false] - --ignore-missing-stack-dependencies Don't check if all stacks specified in the command have their dependencies included as well [boolean] [default: false] - --parallelism Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1 [number] [default: -1] - --refresh-only 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. [boolean] [default: false] + CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] + --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] + --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard out at + the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY + -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] + -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] + --auto-approve Auto approve [boolean] [default: false] + --outputs-file Path to file where stack outputs will be written as JSON [string] + --outputs-file-include-sensitive-outputs Whether to include sensitive outputs in the output file [boolean] [default: false] + --ignore-missing-stack-dependencies Don't check if all stacks specified in the command have their dependencies included as well [boolean] [default: false] + --parallelism Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1 [number] [default: -1] + --refresh-only 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. [boolean] [default: false] --terraform-parallelism 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 [number] [default: -1] - --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] - --migrate-state Pass this flag after switching state backends to approve a state migration for all targeted stacks [boolean] [default: false] - --var Set a value for one of the input variables in the stack or stacks to apply. Use this option more than once to set more than one - variable. [array] [default: []] - --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more - than once to include more than one variables file. [array] [default: []] - --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] - -h, --help Show help [boolean] + supported by remote / cloud backend [number] [default: -1] + --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] + --migrate-state Pass this flag after switching state backends to approve a state migration for all targeted stacks [boolean] [default: false] + --var Set a value for one of the input variables in the stack or stacks to apply. Use this option more than once to set more than one variable. + [array] [default: []] + --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to + include more than one variables file. [array] [default: []] + --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] + --skip-provider-lock Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform + [boolean] [default: false] + -h, --help Show help ``` ~> **Note:** The `parallelism` flag has a different behavior than the [terraform parallelism flag](/terraform/cli/commands/apply#parallelism-n). To set the custom terraform parallelism flag, please use the `--terraform-parallelism` flag instead. @@ -192,31 +194,31 @@ Options: Deploy an application. ```bash -$ cdktf deploy +cdktf deploy ``` Deploy an application with automatic approval of the diff (Terraform plan). ```bash -$ cdktf deploy --auto-approve my-first-stack my-second-stack my-third-stack +cdktf deploy --auto-approve my-first-stack my-second-stack my-third-stack ``` Deploy multiple stacks in one run. ```bash -$ cdktf deploy my-first-stack my-second-stack my-third-stack +cdktf deploy my-first-stack my-second-stack my-third-stack ``` Deploy all stacks in one run: ```bash -$ cdktf deploy '*' +cdktf deploy '*' ``` Deploy all stacks ending with `-production` in one run: ```bash -$ cdktf deploy '*-production' +cdktf deploy '*-production' ``` If the stacks have dependencies (through cross stack references or by calling `myStack.addDependency(otherStack)`) deploy will figure out the right order to run. @@ -228,7 +230,7 @@ For more info on the `--outputs-file` option, refer to the [`output` command](/t This command destroys a given application. ```bash -$ cdktf destroy --help +cdktf destroy --help ``` Help output: @@ -239,32 +241,34 @@ cdktf destroy [stacks..] Destroy the given stacks Positionals: - stacks Destroy stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] + stacks Destroy stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] Options: - --version Show version number [boolean] + --version Show version number [boolean] --experimental-provider-schema-cache-path An experimental schema cache that can be used to improve the speed of cdktf get and convert. Supported using the env - CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] + CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] --disable-plugin-cache-env Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the plugin cache is configured differently. Supported using the env - CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] - --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] - --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard - out at the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY - -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] - -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] - --auto-approve Auto approve [boolean] [default: false] - --ignore-missing-stack-dependencies Don't check if all stacks specified in the command have their dependencies included as well [boolean] [default: false] - --parallelism Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1 [number] [default: -1] + CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] + --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] + --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard out at + the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY + -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] + -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] + --auto-approve Auto approve [boolean] [default: false] + --ignore-missing-stack-dependencies Don't check if all stacks specified in the command have their dependencies included as well [boolean] [default: false] + --parallelism Number of concurrent CDKTF stacks to run. Defaults to infinity, denoted by -1 [number] [default: -1] --terraform-parallelism 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 [number] [default: -1] - --var Set a value for one of the input variables in the stack or stacks to apply. Use this option more than once to set more than one - variable. [array] [default: []] - --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more - than once to include more than one variables file. [array] [default: []] - --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] - --migrate-state Pass this flag after switching state backends to approve a state migration for all targeted stacks [boolean] [default: false] - --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] - -h, --help Show help [boolean] + supported by remote / cloud backend [number] [default: -1] + --var Set a value for one of the input variables in the stack or stacks to apply. Use this option more than once to set more than one variable. + [array] [default: []] + --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to + include more than one variables file. [array] [default: []] + --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] + --migrate-state Pass this flag after switching state backends to approve a state migration for all targeted stacks [boolean] [default: false] + --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] + --skip-provider-lock Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform + [boolean] [default: false] + -h, --help Show help ``` ~> **Note:** The `parallelism` flag has a different behavior than the [terraform parallelism flag](/terraform/cli/commands/apply#parallelism-n). To set the custom terraform parallelism flag, please use the `--terraform-parallelism` flag instead. @@ -274,31 +278,31 @@ Options: Destroy an application. ```bash -$ cdktf destroy +cdktf destroy ``` Destroy an application with automatic approval of the diff (Terraform plan). ```bash -$ cdktf destroy --auto-approve +cdktf destroy --auto-approve ``` Destroy multiple stacks in one run. ```bash -$ cdktf destroy my-first-stack my-second-stack my-third-stack +cdktf destroy my-first-stack my-second-stack my-third-stack ``` Destroy all stacks in one run: ```bash -$ cdktf destroy '*' +cdktf destroy '*' ``` Destroy all stacks ending with production in one run: ```bash -$ cdktf destroy '*-production' +cdktf destroy '*-production' ``` If the stacks have dependencies (through cross stack references or by calling `myStack.addDependency(otherStack)`) deploy will figure out the right order to run. @@ -308,7 +312,7 @@ If the stacks have dependencies (through cross stack references or by calling `m This command generates a diff for a given application by running Terraform plan. ```bash -$ cdktf diff --help +cdktf diff --help ``` Help output: @@ -319,31 +323,32 @@ cdktf diff [stack] Perform a diff (terraform plan) for the given stack Positionals: - stack Diff stack which matches the given id only. Required when more than one stack is present in the app [string] + stack Diff stack which matches the given id only. Required when more than one stack is present in the app [string] Options: - --version Show version number [boolean] + --version Show version number [boolean] --experimental-provider-schema-cache-path An experimental schema cache that can be used to improve the speed of cdktf get and convert. Supported using the env - CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] + CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] --disable-plugin-cache-env Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the plugin cache is configured differently. Supported using the env - CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] - --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] - --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard - out at the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY - -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] - -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] - --refresh-only 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. [boolean] [default: false] + CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] + --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] + --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard out at + the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY + -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] + -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] + --refresh-only 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. [boolean] [default: false] --terraform-parallelism 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 [number] [default: -1] - --var Set a value for one of the input variables in the stack. Use this option more than once to set more than one variable. - [array] [default: []] - --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more - than once to include more than one variables file. [array] [default: []] - --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] - --migrate-state Pass this flag after switching state backends to approve a state migration for the targeted stack [boolean] [default: false] - --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] - -h, --help Show help [boolean] + supported by remote / cloud backend [number] [default: -1] + --var Set a value for one of the input variables in the stack. Use this option more than once to set more than one variable. [array] [default: []] + --var-file Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to + include more than one variables file. [array] [default: []] + --no-color Disables terminal formatting sequences in the output. [boolean] [default: false] + --migrate-state Pass this flag after switching state backends to approve a state migration for the targeted stack [boolean] [default: false] + --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] + --skip-provider-lock Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform + [boolean] [default: false] + -h, --help Show help ``` ~> **Note:** The `parallelism` flag has a different behavior than the [terraform parallelism flag](/terraform/cli/commands/plan#parallelism-n). To set the custom terraform parallelism flag, please use the `--terraform-parallelism` flag instead. @@ -353,7 +358,7 @@ Examples: Generate a diff for a given application. ```bash -$ cdktf diff +cdktf diff ``` ## get @@ -366,7 +371,7 @@ The command does not update the version when you specify loose version constrain When you change a version constraint, the `cdktf get` command recreates the bindings for that provider. ```bash -$ cdktf get --help +cdktf get --help ``` **Help Output** @@ -408,13 +413,13 @@ $ cat cdktf.json ``` ```bash -$ cdktf get +cdktf get ``` If you run into issues generating a lot of bindings you can use the `--parallelism` option to limit the number of bindings generated in parallel. ```bash -$ cdktf get --parallelism 1 +cdktf get --parallelism 1 ``` ## init @@ -422,7 +427,7 @@ $ cdktf get --parallelism 1 This command creates a new CDK for Terraform project using a template. ```sh -$ cdktf init --help +cdktf init --help ``` **Help Output** @@ -460,19 +465,19 @@ Options: Create a new Typescript project. ```bash -$ cdktf init --template="typescript" +cdktf init --template="typescript" ``` Create a new Python project and use a specific version of the `cdktf` package. ```bash -$ cdktf init --template="python" --cdktf-version="0.0.1" +cdktf init --template="python" --cdktf-version="0.0.1" ``` Create a new Typescript project from an existing Terraform codebase. Currently, you can only use the `--from-terraform-project` flag with TypeScript, and there are some known limitations. ```bash -$ cdktf init --template="typescript" --from-terraform-project /path/to/terraform/project +cdktf init --template="typescript" --from-terraform-project /path/to/terraform/project ``` ## login @@ -480,7 +485,7 @@ $ cdktf init --template="typescript" --from-terraform-project /path/to/terraform This command helps log in to HCP Terraform by fetching a HCP Terraform API token. ```bash -$ cdktf login --help +cdktf login --help ``` **Help Output** @@ -516,7 +521,7 @@ Please note that we currently expect custom TFE instances to be using the `https Fetch an API token from HCP Terraform. ```bash -$ cdktf login +cdktf login ``` ## synth @@ -524,7 +529,7 @@ $ cdktf login This command synthesizes Terraform configuration for an application. CDKTF stores the synthesized configuration in the `cdktf.out` directory, unless you use the `--output` flag to specify a different location. The output folder is ephemeral and might be erased for each `synth` that you run manually or that happens automatically when you run `deploy`, `diff`, or `destroy`. ```sh -$ cdktf synth --help +cdktf synth --help ``` **Help Output** @@ -556,19 +561,19 @@ Options: Synthesize code for an application. ```bash -$ cdktf synth +cdktf synth ``` Synthesize code when providing a custom command to execute and an output directory. ```bash -$ cdktf synth --app="npm compile && node main.js" --output="dirname" +cdktf synth --app="npm compile && node main.js" --output="dirname" ``` Synthesize code in Terraform HCL instead of JSON ```bash -$ cdktf synth --hcl +cdktf synth --hcl ``` ## watch @@ -586,7 +591,7 @@ Before using `watch` you should check your environment. The `watch` command shou ### Run watch ```sh -$ cdktf watch --help +cdktf watch --help ``` **Help Output** @@ -642,7 +647,7 @@ The debug output is directed to a `cdktf.log` file in your projects root directo This command gets the outputs defined in the Terraform configuration of the given stack. It uses `terraform output` under the hood. ```sh -$ cdktf output --help +cdktf output --help ``` **Help Output** @@ -653,24 +658,25 @@ cdktf output [stacks..] Prints the output of stacks Positionals: - stacks Get outputs of the stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] + stacks Get outputs of the stacks matching the given ids. Required when more than one stack is present in the app [array] [default: []] Options: - --version Show version number [boolean] + --version Show version number [boolean] --experimental-provider-schema-cache-path An experimental schema cache that can be used to improve the speed of cdktf get and convert. Supported using the env - CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] + CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH. [string] [default: false] --disable-plugin-cache-env Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the plugin cache is configured differently. Supported using the env - CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] - --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] - --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard - out at the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY - -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] - -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] - --outputs-file Path to file where stack outputs will be written as JSON [string] - --outputs-file-include-sensitive-outputs Whether to include sensitive outputs in the output file [boolean] [default: false] - --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] - -h, --help Show help [boolean] -➜ + CDKTF_DISABLE_PLUGIN_CACHE_ENV. [boolean] [default: false] + --log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string] + --log-file-directory The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard out at + the level specified in `CDKTF_LOG_LEVEL`. Only supported via setting the env CDKTF_LOG_FILE_DIRECTORY + -a, --app Command to use in order to execute cdktf app [required] [default: "npx ts-node main.ts"] + -o, --output Output directory for the synthesized Terraform config [required] [default: "cdktf.out"] + --outputs-file Path to file where stack outputs will be written as JSON [string] + --outputs-file-include-sensitive-outputs Whether to include sensitive outputs in the output file [boolean] [default: false] + --skip-synth Skip synthesis of the application, assume the synthesized Terraform code is already present and up to date [boolean] [default: false] + --skip-provider-lock Block `terraform provider lock` from being run for any reason. Warning: This may cause issues when used with HCP Terraform + [boolean] [default: false] + -h, --help Show help ``` ### `--outputs-file` @@ -748,7 +754,7 @@ com.hashicorp.cdktf-provider-ad (PREBUILT) This command facilitates adding Terraform providers to a CDKTF project. If a [pre-built provider](/terraform/cdktf/concepts/providers#install-pre-built-providers) is available for the CDKTF version you are using and the Terraform provider version you requested (if any), it will be installed using e.g. `npm install` or `dotnet add` depending on the language you are using. Otherwise, the provider will be added to the `cdktf.json` config and `cdktf get` will be automatically invoked to generate [local provider bindings](/terraform/cdktf/concepts/providers#add-provider-to-cdktf-json). ```sh -$ cdktf provider add --help +cdktf provider add --help ``` **Help Output** @@ -779,25 +785,25 @@ Options: Add the `aws` provider to the project. As the namespace of the AWS Terraform provider is `hashicorp` it can be left out. ```bash -$ cdktf provider add aws +cdktf provider add aws ``` Add a specific version of the `aws` provider to the project. You can use the `@` symbol to specify a [version constraint](/terraform/language/providers/requirements#version-constraints). ```bash -$ cdktf provider add aws@~>4.0 +cdktf provider add aws@~>4.0 ``` Add multiple providers to the project and force local generation of provider bindings. ```bash -$ cdktf provider add kreuzwerker/docker google --force-local +cdktf provider add kreuzwerker/docker google --force-local ``` Add a provider from a private registry to the project. ```bash -$ cdktf provider add registry.example.com/acme/my-provider +cdktf provider add registry.example.com/acme/my-provider ``` ## provider upgrade @@ -883,17 +889,17 @@ Options: Upgrade the `aws` provider to the newest version available for your `cdktf` version. ```bash -$ cdktf provider add aws +cdktf provider add aws ``` Upgrade the `aws` provider to the newest version available for your `cdktf` version and at version `4` of the provider version. ```bash -$ cdktf provider add aws@~>4.0 +cdktf provider add aws@~>4.0 ``` Upgrade multiple providers to the latest version available for your `cdktf` version. ```bash -$ cdktf provider add kreuzwerker/docker google +cdktf provider add kreuzwerker/docker google ```