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 synth STACK" does not honour STACK #1906

Closed
ninaspitfire opened this issue Jun 30, 2022 · 8 comments · Fixed by #1907
Closed

"cdktf synth STACK" does not honour STACK #1906

ninaspitfire opened this issue Jun 30, 2022 · 8 comments · Fixed by #1907
Labels
bug Something isn't working

Comments

@ninaspitfire
Copy link

ninaspitfire commented Jun 30, 2022

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.11.2 with Python.

Affected Resource(s)

N/A

Debug Output

https://gist.github.com/jarpy/0bc5173c00814820b667f9e097a7e4ff

Expected Behavior

$ cdktf synth

Generated Terraform code for the stacks: stack-one, stack-two

$ cdktf synth stack-one

Generated Terraform code for the stacks: stack-one

$ cdktf synth stack-two

Generated Terraform code for the stacks: stack-two

Actual Behavior

$ cdktf synth

Generated Terraform code for the stacks: stack-one, stack-two

$ cdktf synth stack-one

Generated Terraform code for the stacks: stack-one, stack-two

$ cdktf synth stack-two

Generated Terraform code for the stacks: stack-one, stack-two

Steps to Reproduce

cdktf init
from constructs import Construct
from cdktf import App, TerraformStack


class MyStack(TerraformStack):
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)


app = App()
MyStack(app, "stack-one")
MyStack(app, "stack-two")

app.synth()
cdktf synth stack-one

Important Factoids

The help text for cdktf synth reads:

Synthesizes Terraform code for the given app in a directory.

Positionals:
  stack  Stack to output when using --json flag  

stack does not appear to be honoured (and the --json flag was removed in v0.10.0).

References

None.

@ninaspitfire ninaspitfire added bug Something isn't working new Un-triaged issue labels Jun 30, 2022
@DanielMSchmidt
Copy link
Contributor

Oh good point, we forgot to remove the stack positional after removing the JSON flag. Synth can not be limited to a single stack.

@ninaspitfire
Copy link
Author

ninaspitfire commented Jun 30, 2022

Ah cool. Thanks. I use my own technique to limit what gets synthed, but I wasn't sure if I needed to, or if that capability was in the engine, but glitched.

Cheers.

@DanielMSchmidt
Copy link
Contributor

What technique are you using?

@ninaspitfire
Copy link
Author

Nothing fancy. I have three stacks (dev, test, prod). I just set an optional environment variable, and then choose which stacks to synth based on that. My entrypoint looks like:

https://gist.github.com/jarpy/affd883ee535e16d2d9398352c97240e

I've been trying to figure how to get the "stage" by introspection. It would be cool if I could find this somewhere in memory:

cdktf plan my-stack-prod
                    ^^^^

Then, I wouldn't need the environment variable, which is pretty ugly. Now you can see how I ended up raising this issue! :) I wanted to cdktf synth THING, and be able to introspect what THING is at runtime.

@ansgarm
Copy link
Member

ansgarm commented Jul 11, 2022

Hi @jarpy 👋
I saw some flag mentioning API calls, are you "manually" creating resources via api calls while synthesizing (aka while running your Python program)? What exactly are you using those API calls for?

@ninaspitfire
Copy link
Author

ninaspitfire commented Jul 11, 2022

Hi @ansgarm :)

are you "manually" creating resources via api calls while synthesizing

No way! :D I would never create anything with an API call in synth, but I do consume all sorts of things so that I can programmatically declare the things I do want to create as Terraform resources. This, for me, is the beauty of CDKTF and why I find it truly delightful. I can now declare resources programmatically, by consuming, inspecting and transforming data structures that can be any shape and come from anywhere.

As a concrete example, I can inspect the GitHub API for information about repositories, (my company has thousands, and they are not provisioned by Terraform), and then dynamically declare CI pipelines, Vault resources etc. based on the incoming data structures.

I'm anticipating traditional HCL users saying, at this point, "that's what data sources are for". In some cases, they are certainly useful, but not depending on them (and not spending months trying to get changes merged into them) is incredibly freeing. CDKTF unshackles us, and allows us to innovate, with Turing complete, well tested, and well documented software, right in our "configuration". It's been wonderful so far, and I would like to offer my sincere thanks to the CDKTF team.

Please feel free to close this issue, since it sounds like cdktf synth is working as designed, and I can achieve my goals without any change to it.

@ansgarm
Copy link
Member

ansgarm commented Jul 11, 2022

Hi @jarpy :)

Thank you for those kind words. I can relate to the simplicity that a touring complete language can offer for use-cases like yours. I was just curious about your approach here. We previously had a quite related idea about facilitating such things by offering an API that enables you to quickly define data sources within your CDKTF code. But this probably would come with a bit of overhead and additional challenges (i.e. how and where to pass auth tokens, etc.). So it might not have been a useful replacement for your case here.

The whole topic of making CDKTF more dynamic is something we haven't deplored the depths of yet and your feedback definitely helps as input for these endeavors as well.

Thanks! It seems to be closed already ✅ Feel free to comment and/or create new issues, even if they just describe a minor annoyance you might encounter while everything "works as designed" 😄

@DanielMSchmidt DanielMSchmidt removed the new Un-triaged issue label Jul 15, 2022
@github-actions
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 Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants