terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Allow using CLI without having a config file

Open skorfmann opened this issue 4 years ago • 4 comments

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

cdktf & Language Versions

  • 0.5.0

Affected Resource(s)

  • cli

Debug Output

cdktf watch --app 'npx tsc && node render-stack.js' --out cdktf.test.out
Error: Usage Error: /some/path is not a cdktf project directory, no cdktf.json found or cdktf.json is missing language / app keys

Expected Behavior

Using the cli without a cdktf.json config file should work as well

Actual Behavior

An error is thrown when cdkt.json config file isn't present

skorfmann avatar Aug 02 '21 09:08 skorfmann

Oh I was not aware that a project without a cdktf.json is valid, I added this check with the intend to keep people from using cdktf outside of a cdk project context. What is the use-case for this behavior and is this documented anywhere yet?

DanielMSchmidt avatar Aug 02 '21 12:08 DanielMSchmidt

What is the use-case for this behavior and is this documented anywhere yet?

Except for app, everything else is pretty much optional. There are some subtile differences right now which are tracked here https://github.com/hashicorp/terraform-cdk/issues/798

So, it's perfectly fine to do something like cdktf deploy --app 'npx tsc && node render-stack.js or even skipping the CLI entirely npx tsc && node render-stack.js. My specific use-case here is an integration test scenario.

Don't know to which extent that's documented (probably not at all)

skorfmann avatar Aug 02 '21 13:08 skorfmann

we also have a similar use case.

Imagine we have two repos

  • controller (it contains the cdktf.json and this is where the cdktf generation logic live)
  • deployment (it contains all the output instances of cdktf apps/stacks)
    • app1
      • manifest.json
      • stacks/*
    • app2
      • manifest.json
      • stacks/*

we want to be able to run cdktf output within the deployment to retrieve the output programmatically, and this is not possible because cdktf-cli is completely couple with the cdktf.json.

alternative

  • creates a dummy cdktf.json in the deployment repo for each app
  • run cdktf from the controller repo (not possible because cdktf output implicitly run cdktf synth, but each app in deployment requires different command argumements to run the cdktf app)

michaellzc avatar Oct 03 '22 20:10 michaellzc

We generate cdktf apps on the fly per folder and don't want to have cdktf.json everywhere. All the parameters are passed in via cli flags anyways. Since cdktf --app flag already exists why cdktf.json can't be optional?

shinebayar-g avatar Jan 06 '24 02:01 shinebayar-g