terraform-cdk
terraform-cdk copied to clipboard
Stack Refactoring
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
Description
I created an eks across multiple accounts under one stack. But now I want to split them to separate stacks or at the very least update the stack name. But doing either will make terraform destroy and recreate the whole eks, which is not what I want. How do I do this?
const app = new App()
const stack = new TerraformStack(app, 'stack');
const eks1 = new EKSCluster(stack, 'eks1', {
...
}
const eks2 = new EKSCluster(stack, 'eks2', {
...
}
app.synth();
I want to get to this point. I remove stack = new TerraformStack
and just let each eks be its own stack. Note that my class EKSCluster extends TerraformStack
const app = new App()
const eks1 = new EKSCluster(app, 'eks1', {
...
}
const eks2 = new EKSCluster(app, 'eks2', {
...
}
app.synth();
References
Updating the stack name should not have an effect on the synthesised code, so that should be no problem.
If you want to split one stack into two, while not destroying the underlying resource you are in for some work. First you'd need to keep the cdktf program like it was last deployed. The you'd need to add your EKSCluster
construct while not changing the other stack (as if you wanted to create a new EKS Cluster). Now you synthesise the code and change into the new stacks directory (cdktf.out/stacks/myStack) and run terraform import
for every resource in the synthesised JSON, with the values from your already deployed stack (you can get the values via terraform state show
in the deployed stacks directory). You then need to remove the values of that now moved over EKS cluster from the deployed cluster via terraform state rm
since it is now owned by the new stack. Last but not least you need to change the CDKTF code for your deployed stack to not include the moved over cluster anymore. A final cdktf diff
on both stacks verifies that the move has been successful.
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.