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

AppOptions: Define Outdir in the code raise a synth ERROR #3405

Closed
1 task
caparisi opened this issue Jan 10, 2024 · 4 comments · Fixed by #3463
Closed
1 task

AppOptions: Define Outdir in the code raise a synth ERROR #3405

caparisi opened this issue Jan 10, 2024 · 4 comments · Fixed by #3463
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@caparisi
Copy link

caparisi commented Jan 10, 2024

Expected Behavior

With python, I want define the output dir directly in the code (without specify it in the command line) when I create the App object like :

#!/usr/bin/env python
from cdktf import App

cdktf_environment = App(outdir='out-environment-xxxxxxx.out')

# Custom CDKTF code ....

cdktf_environment.synth()

Synth cmd is :

cdktf synth -a "pipenv run python ./environment-xxxxxxx.py" 

Actual Behavior

When we execute the synth, we get the following error (error code 1):

cdktf synth -a "pipenv run python ./environment-xxxxxxx.py" 

[2024-01-10T15:06:22.324] [ERROR] default - ERROR: synthesis failed, because app was expected to call 'synth()', but didn't. Thus "cdktf.out/manifest.json"  was not created: Error: Could not find manifest file at cdktf.out/manifest.json. In case --skip-synth was passed, please try again without the flag.   

The output itself is well generated, we could go in the stack generated file and execute terraform init/apply without any issue.

If we specify the ouput dir in the command line with -o, the issue don't happen

Steps to Reproduce

  1. Setup your cdktf with python project
  2. Define the App object with the output param like App(outdir='out-environment-xxxxxxx.out')
  3. Try to synth without the -o param

Versions

language: Python 3.10.13
cdktf-cli: 0.20.0
node: v20.9.0
Terraform: v1.6.6
OS: Linux x86_64
Python dependency:

  • cdktf = "~=0.20"
  • constructs = "*"

Providers

Python dependency:

	cdktf-cdktf-provider-kubernetes = "~=11.0"
	cdktf-cdktf-provider-helm = "~=10.0"
	cdktf-cdktf-provider-postgresql = "~=11.0"
	cdktf-cdktf-provider-azurerm = "~=12.0"
	cdktf-cdktf-provider-azuread = "~=12.0"
	cdktf-cdktf-provider-random = "~=11.0"
	cdktf-cdktf-provider-time = "~=10.0"

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

#3334

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
@caparisi caparisi added bug Something isn't working new Un-triaged issue labels Jan 10, 2024
@ansgarm ansgarm self-assigned this Jan 11, 2024
@ansgarm
Copy link
Member

ansgarm commented Jan 11, 2024

Hi @caparisi 👋

This is currently required and by design. The CDKTF CLI invokes the app as a separate process and there is no further communication between the app and the CLI, so we can't pass the outdir that might've been passed to App back to the CLI for it to find the generated Terraform config.

So at this point, you have three options to pass the outdir to the CLI:

  • via the -o / --output param
  • via the CDKTF_OUTDIR environment variable
  • via the output property in your cdktf.json config

Passing the outdir to the App is intended for testing purposes.

I'm curious: What is your underlying use-case? I guess you are dynamically generating it and aren't using a static string there?

@ansgarm ansgarm added waiting-on-answer and removed new Un-triaged issue labels Jan 11, 2024
@caparisi
Copy link
Author

Hi @ansgarm,

Thanks for your answer, I didn't found this clearly explained in the documentation but maybe I didn't looking to the right place ^^

Initially, we had 1 git repository with 1 cdktf App. More we use it, more we had stacks and complexity so we split us infra in many different scripts (+ a kind of "common library" to do a lot of factorization/reusable code), each one call with the -a (e.g: cdktf synth -a "pipenv run python ./environment-staging.py", cdktf synth -a "pipenv run python ./applications-staging.py"). Each script has its own python "App" object. To have all different stack synth in same time, we had to add the -o param to synth in different folders. I used bash aliases to not have to enter the full command every time of course, but we have to specify it in documentation and take care to stay coherent between DevOps people to simplify some development.

From your explanation, I understand that the "right" way to do the things will be to create a folder to each App script in which we will have to init a cdktf App, isn't? If this is the case, I guess that we will stay the '-o' param because else we will have 8 different cdktf.json /Pipfile to update/maintain + the fact to have to move in each folder to run cdktf cli command, which is not a issue for CI but painful for daily development.

PS: To give you a bit of context. I work for a big non-profit humanitarian (8K employee, 20M beneficiary). We use CDKTF to manage in IaaS all our infrastructure.

@ansgarm
Copy link
Member

ansgarm commented Jan 24, 2024

I understand that the "right" way to do the things will be to create a folder to each App script in which we will have to init a cdktf App, isn't?

Yes, that would be the recommended way based on the assumptions that the CDKTF CLI makes. However, I can see where you're coming from. So I wouldn't discourage your approach 👍

I added some more docs in #3463 for the AppOptions#outdir option that are hopefully easier to discover than this issue 😄

I'm going to link that PR to close this issue, once it's merged. If there's anything else you run into, don't hesitate to create a new issue!

github-merge-queue bot pushed a commit that referenced this issue Jan 24, 2024
@ansgarm ansgarm added documentation Improvements or additions to documentation and removed new Un-triaged issue labels Jan 24, 2024
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 Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
3 participants