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

Handle Multiple Stacks #636

Merged
merged 32 commits into from
Apr 21, 2021
Merged

Handle Multiple Stacks #636

merged 32 commits into from
Apr 21, 2021

Conversation

skorfmann
Copy link
Contributor

@skorfmann skorfmann commented Apr 14, 2021

This will change the commands synth, diff, deploy and destroy to handle more than one stack per application.

Current Behaviour prior to this Change

When using cdktf the application code is synthesized into the configured output folder (cdktf.out by default) as cdk.tf.json file. The output folder serves as working directory for the Terraform CLI for the commands which interacting with it (diff, deploy, destroy). Since we do have a static output folder, users might copy assets such as zip files as part of the stack synth manually in the output folder.

Changed behaviour

We'll have a stacks folder within the app output directory (cdktf.out), where each stack will synthesize itself in a sub directory (e.g. cdktf.out/stacks/stack-a). This will then serve as the working directory for all Terraform CLI commands. There won't be an automatic cleanup of the stacks directory.

Planned Changes

  • Synth all stacks at once
  • Synth a single stack only (useful when dealing with stacks which process large assets)
  • Adapt deploy, diff, destroy to take a positional stack argument. If more than one stack exists, that's a mandatory argument
  • Add a list stacks command
  • Make sure the Terraform Cloud remote exec workflow doesn't break. This won't manage the Terraform workspaces on behalf of the user and therefore expects the workspaces to be present.
  • Find a good way to access the stack's working directory on a construct level (e.g. to copy / generate assets) (extracted in Asset Construct #648)
  • Add / change documentation for stacks. Point out, that we don't support automatic cross-stack references at this point
  • Make sure local workflows handle the state files correctly
  • Add check for existing terraform.tfstate file in project root and prompt the user to rename it

Fixes #289 #35

@skorfmann
Copy link
Contributor Author

  • Find a good way to access the stack's working directory on a construct level (e.g. to copy / generate assets)

This is possible in the current state, but not really convenient. Will create a follow up issue to make this more idiomatic.

packages/cdktf-cli/bin/cmds/deploy.ts Outdated Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/destroy.ts Outdated Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/diff.ts Outdated Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/list.ts Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/terraform-check.ts Outdated Show resolved Hide resolved
packages/cdktf/lib/manifest.ts Show resolved Hide resolved
test/typescript/multiple-stacks/test.ts Outdated Show resolved Hide resolved
@ansgarm
Copy link
Member

ansgarm commented Apr 20, 2021

Maybe we should also update the help file in our templates to contain the (sometimes optional) stack argument for some commands?

@ansgarm
Copy link
Member

ansgarm commented Apr 20, 2021

Just tested it locally, works great 🚀

@skorfmann skorfmann marked this pull request as ready for review April 21, 2021 14:23
@skorfmann skorfmann requested a review from ansgarm April 21, 2021 14:23
packages/cdktf-cli/bin/cmds/deploy.ts Outdated Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/destroy.ts Outdated Show resolved Hide resolved
packages/cdktf-cli/bin/cmds/diff.ts Outdated Show resolved Hide resolved
packages/cdktf/test/manifest.test.ts Show resolved Hide resolved
test/csharp/synth-app/test.ts Show resolved Hide resolved
@skorfmann skorfmann merged commit 66ab431 into main Apr 21, 2021
@skorfmann skorfmann deleted the multiple-stacks branch April 21, 2021 19:09
ansgarm added a commit that referenced this pull request May 18, 2021
remove outdated statement as #636 introduced multiple stacks
@ansgarm ansgarm mentioned this pull request May 18, 2021
@github-actions
Copy link
Contributor

I'm going to lock this pull request 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 related to this change, 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 Dec 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple stacks
2 participants