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): Include provider info in cdktf debug #3190

Merged
merged 2 commits into from
Nov 1, 2023
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
65 changes: 58 additions & 7 deletions packages/cdktf-cli/src/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,71 @@ export async function output(argv: any) {
}

export async function debug(argv: any) {
const jsonOutput = argv.json;
const debugOutput = await collectDebugInformation();
// Ideally the provider info gathering happens in `collectDebugInformation()` but the inclusion of `CdktfConfig.read()` in @cdktf/commons causes the build to fail with "error TS5055"
const config = CdktfConfig.read();
const language = config.language;
const cdktfVersion = await getPackageVersion(language, "cdktf");
if (!cdktfVersion)
throw Errors.External(
"Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed."
);

if (jsonOutput) {
console.log(JSON.stringify(debugOutput, null, 2));
const manager = new DependencyManager(
language,
cdktfVersion,
config.projectDirectory
);
const allProviders = await manager.allProviders();
const debugOutput = await collectDebugInformation();
if (argv.json) {
console.log(
JSON.stringify(
{
...debugOutput,
providers: {
local: allProviders.local.map((provider) => {
return {
provider: `${provider.providerName}@${provider.providerConstraint}`,
terraformProviderVersion: provider.providerVersion,
};
}),
prebuilt: allProviders.prebuilt.map((provider) => {
return {
provider: provider.packageName,
terraformProviderVersion: provider.providerVersion,
prebuiltProviderVersion: provider.packageVersion,
cdktfVersion: provider.cdktfVersion,
};
}),
},
},
null,
2
)
);
} else {
console.log(chalkColour`{bold {greenBright cdktf debug}}`);

Object.entries(debugOutput).forEach(([key, value]) => {
console.log(`${key}: ${value === null ? "null" : value}`);
});

console.log(chalkColour`{bold {yellowBright providers}}`);

for (const provider of allProviders.local) {
console.log(
`${provider.providerName}@${provider.providerConstraint} (LOCAL)
terraform provider version: ${provider.providerVersion}`
);
}
for (const provider of allProviders.prebuilt) {
console.log(
`${provider.packageName} (PREBUILT)
terraform provider version: ${provider.providerVersion}
prebuilt provider version: ${provider.packageVersion}
cdktf version: ${provider.cdktfVersion}`
);
}
}
}

Expand Down Expand Up @@ -628,7 +682,6 @@ export async function providerList(argv: any) {
const config = CdktfConfig.read();
const language = config.language;
const cdktfVersion = await getPackageVersion(language, "cdktf");

if (!cdktfVersion)
throw Errors.External(
"Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed."
Expand All @@ -639,9 +692,7 @@ export async function providerList(argv: any) {
cdktfVersion,
config.projectDirectory
);

const allProviders = await manager.allProviders();

if (argv.json) {
console.log(JSON.stringify(allProviders));
return;
Expand Down
24 changes: 15 additions & 9 deletions website/docs/cdktf/cli-reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -657,18 +657,24 @@ The debug information depends on the programming language. The following example

```
$ cdktf debug

language: java
cdktf-cli: 0.10.4
node: v16.15.0
cdktf: 0.10.4
constructs: 10.0.5
cdktf-cli: 0.18.2
node: v18.18.1
cdktf: 0.18.2
constructs: 10.3.0
jsii: 1.59.0
terraform: 1.1.8
arch: x64
os: darwin 21.4.0
terraform: 1.5.5
arch: arm64
os: darwin 22.6.0
java: 17.0.1
maven: Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)Maven home: /usr/local/Cellar/maven/3.8.2/libexecJava version: 17.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/HomeDefault locale: en_DE, platform encoding: UTF-8OS name: "mac os x", version: "12.3.1", arch: "x86_64", family: "mac"
maven: Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)Maven home: /usr/local/Cellar/maven/3.8.2/libexecJava version: 17.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/HomeDefault locale: en_DE, platform encoding: UTF-8OS name: "mac os x", version: "12.3.1", arch: "arm64", family: "mac"
providers
kreuzwerker/docker@~> 2.0 (LOCAL)
terraform provider version: 2.25.0
@cdktf/provider-ad (PREBUILT)
terraform provider version: 0.4.4
prebuilt provider version: 6.0.0
cdktf version: ^0.18.0
```

## provider add
Expand Down