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

CDKTF_LOG_FILE_DIRECTORY: 'cdktf init' errors out with 'Unknown argument' when this environment variable is set #3489

Closed
1 task
ShaheenK27 opened this issue Feb 8, 2024 · 1 comment · Fixed by #3495
Labels
bug Something isn't working new Un-triaged issue

Comments

@ShaheenK27
Copy link

ShaheenK27 commented Feb 8, 2024

Actual Behavior

  • If CDKTF_LOG_FILE_DIRECTORY is set on the system, then the cdktf init command errors out with the following message

    • Unknown argument: logFileDirectory

    [The environment variable is specified with a path of an existing folder (with sufficient read/write access)]

  • However, if this environment variable is set after cdktf init is executed, then:

    • All the other commands (get, synth, deploy, diff, destroy, etc.) support CDKTF_LOG_FILE_DIRECTORY & successfully log the content in the specified directory.

Expected Behavior

  • Is it intentional that CDKTF_LOG_FILE_DIRECTORY is not supported during init & it does not allow logging to a specific directory? If so:
    • Is it because logging is solely for debugging CDKTF applications, so we want to save the logs only after the application is created to debug it [Reference: Debugging]

    • Or is it because we want project-specific logs?

      • As CDKTF allows managing different projects, streaming logs from two different CDKTF projects to the same file is not a valid use case.

      • Therefore, the cdktf init does not stream logs and expects us to configure logging to separate directories for each application after initialization.

Steps to Reproduce

Step 1: export CDKTF_LOG_FILE_DIRECTORY=<path/to/logging/directory/>

Step 2: In an empty directory, run cdktf init --template=typescript command.
[This returns an 'Unknown argument' error]

Versions

  1. language: typescript
  2. cdktf-cli: 0.17.3
  3. npm: 8.19.4
  4. node: 16.20.1
  5. terraform: 1.4.5

Providers

No response

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@ShaheenK27 ShaheenK27 added bug Something isn't working new Un-triaged issue labels Feb 8, 2024
@ShaheenK27 ShaheenK27 changed the title CDKTF_LOG_FILE_DIRECTORY: 'cdktf init' errors our with 'Unknown argument' when this environment variable is set CDKTF_LOG_FILE_DIRECTORY: 'cdktf init' errors out with 'Unknown argument' when this environment variable is set Feb 8, 2024
ansgarm added a commit that referenced this issue Feb 19, 2024
…ommands (#3495)

<!--

Unless this is a very simple 1-line-of-code change, please create a new
issue describing the change you're proposing first, then link to it from
this PR.

Read more about our process in our contributing guide:
https://github.com/hashicorp/terraform-cdk/blob/main/CONTRIBUTING.md

-->

### Related issue

Fixes #3489 

### Description

We were using `CDKTF_LOG_FILE_DIRECTORY` within our logger, but we never
made it into a supported CLI flag. CDKTF configures
[yargs](https://yargs.js.org/) in a way that all environment variables
with the `CDKTF_` prefix are treated as CLI flags. For commands that had
[`strict`](https://yargs.js.org/docs/#api-reference-strictenabledtrue)
enabled, that means that setting any non-supported flag with the
`CDKTF_` prefix would cause the command to fail. This PR now adds
support for this flag and it should work across all commands.

---------

Co-authored-by: Ansgar Mertens <ansgar@hashicorp.com>
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working new Un-triaged issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant