terraform-cdk
terraform-cdk copied to clipboard
Allowing to initiate (cdktf init) a project in an empty directory.
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
References
Hi @ValAug š This issue was about not being able to run cdktf init
in a freshly cloned git repository because that one is not empty because of the .git
directory, right?
Hello,
That's correct.
ERROR: Cannot initialize a project in a non-empty directory.
Sorry that made a mistake in the issue title
It looks like I have to delete what is created with the repo first then run cdktf init --template="typescript" for this work.
Still seen to be a good opportunity to enhance the whole process. We should be able to init the project without needing to delete what is created by GitHub
I just tried running git init
followed by cdktf init
and didn't run into any problems.
I'm wondering if there is a README.md
file being created with a new project or potentially a LICENSE
file. @ValAug are either of those present or is there something else?
Hello,
Thank you for the email.
I will break my steps below.
I created a folder locally for my project I created a GitHub repo to host the project I clone the repo in my project folder I created Inside the the repo I ran CDKTF init and I received the error about not empty directory.
As we know the repo comes with it own folders. What I did was to deleted those folders and run CDKTF init again and that allows me to create the project without error.
Which is a solution but this would mean that one will need to do the same each time that clones a repo.
On Thu, Apr 7, 2022 at 11:18 PM Jon Steinich @.***> wrote:
I just tried running git init followed by cdktf init and didn't run into any problems. I'm wondering if there is a README.md file being created with a new project or potentially a LICENSE file. @ValAug https://github.com/ValAug are either of those present or is there something else?
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1092401672, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2EDCCQ6LSLSJ7QAIL3VD6QO7ANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
Hi @ValAug, quick question: Do you create the new repo based on a template that already contains some kind of CDKTF project? (You wouldn't need to run cdktf init
in that case, it is only required to create a new project but not required to be run by e.g. different team members after they cloned that existing project).
We could make the latter more clear by detecting whether there's already a cdktf.json
available and tell the user that they don't need to run init
like they'd have to do when using Terraform directly.
No the repo is new(empty).
My intention was to create the project in this new repo.
On Fri, Apr 8, 2022 at 11:43 AM Ansgar Mertens @.***> wrote:
Hi @ValAug https://github.com/ValAug, quick question: Do you create the new repo based on a template that already contains some kind of CDKTF project? (You wouldn't need to run cdktf init in that case, it is only required to create a new project but not required to be run by e.g. different team members after they cloned that existing project). We could make the latter more clear by detecting whether there's already a cdktf.json available and tell the user that they don't need to run init like they'd have to do when using Terraform directly.
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1093020533, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2AB5SEGQL6V5SHBLTTVEBH2TANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
Unless there is some issue that we aren't aware of, you should have no problem running cdktf init
in an empty directory.
@ValAug can you please run ls
in the directory that you are trying to run cdktf init
and let us know what it shows?
Hey Jon,
Thank you again for trying to make this happen.
As Ansgar mentioned a cloned repo contains a .git directory, so that might be the underlying reason for this issue.
What I did was to remove the .git directory after cloning the new repo for cdktf init to work.
Hopefully this makes things clearer.
Thank you again
On Fri, Apr 8, 2022 at 12:32 PM Jon Steinich @.***> wrote:
Unless there is some issue that we aren't aware of, you should have no problem running cdktf init in an empty directory. @ValAug https://github.com/ValAug can you please run ls in the directory that you are trying to run cdktf init and let us know what it shows?
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1093069342, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2ADBPXELH3FI3TAPJLVEBNTBANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
What's strange is that I don't have any issues with this locally. I also can see the code which should already ignore a .git
directory: https://github.com/hashicorp/terraform-cdk/blob/2dba175c527d30daef6d623f701a950b4350afb8/packages/cdktf-cli/bin/cmds/helper/init.ts#L37
@ValAug what OS are you using?
Iām Mac user and I use VsCode.
Could you please share your process?
On Sun, Apr 10, 2022 at 4:48 PM Jon Steinich @.***> wrote:
What's strange is that I don't have any issues with this locally. I also can see the code which should already ignore a .git directory: https://github.com/hashicorp/terraform-cdk/blob/2dba175c527d30daef6d623f701a950b4350afb8/packages/cdktf-cli/bin/cmds/helper/init.ts#L37
@ValAug https://github.com/ValAug what OS are you using?
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1094366022, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2DR4NDYDMVK3ZYXTPDVEM475ANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
mkdir 1697
cd 1697
git init
cdktf init
Interesting.
I am assuming this is the only possible way for CDKTF init to work.
Is there a possible opportunity to be able to clone a brand new repo and initiate the CDKTF project in the future without receiving the error message that I am receiving ?
Thank again for your time and help Jon
On Sun, Apr 10, 2022 at 5:00 PM Jon Steinich @.***> wrote:
mkdir 1697 cd 1697 git init cdktf init
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1094368359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2HSWFKX6KHI2ZG3GY3VEM6PNANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
Is there a possible opportunity to be able to clone a brand new repo and initiate the CDKTF project in the future without receiving the error message that I am receiving ?
Absolutely. I'm just trying to get to the bottom of what's different with your process/environment. Cloning an empty git repo will have a .git
directory, but the same is true after running git init
. Creating a repo in the GitHub UI can result in some other files being created if you check various boxes. Some of those would prevent cdktf init
from working. We can check for those files, but it didn't sound like you had any of those present.
I've tried both Linux and Windows without issue, but I'm unable to check on Mac. @ansgarm can you try this out please?
@jsteinich worked for me as well on OS X:
> mkdir test-git-init
> cd test-git-init
> git init
Initialized empty Git repository in /Users/ansgar/projects/playground/test-git-init/.git/
> ls -lAh
total 0
drwxr-xr-x 9 ansgar staff 288B Apr 11 14:23 .git
> cdktf --version
0.10.1
> cdktf init --local
# worked
Great!
Had you try reproducing my use case?
Thanks
On Mon, Apr 11, 2022 at 8:28 AM Ansgar Mertens @.***> wrote:
@jsteinich https://github.com/jsteinich worked for me as well on OS X:
mkdir test-git-init cd test-git-init git init Initialized empty Git repository in /Users/ansgar/projects/playground/test-git-init/.git/ ls -lAh total 0 drwxr-xr-x 9 ansgar staff 288B Apr 11 14:23 .git cdktf --version 0.10.1 cdktf init --local
worked
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1094988715, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2FKEKFGWSOZB4CFEN3VEQLFZANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
Hi @ValAug, could you create and link a public Github repo (which shows this behaviour after cloning) that I can clone to try to reproduce it locally on my machine?
Hello,
https://github.com/ValAug/cdktf-demo.git
cdktf init --template="typescript" --local ERROR: Cannot initialize a project in a non-empty directory
ls -a . .. .git README.md
Thank you Augusto
On Tue, Apr 12, 2022 at 9:33 AM Ansgar Mertens @.***> wrote:
Hi @ValAug https://github.com/ValAug, could you create and link a public Github repo (which shows this behaviour after cloning) that I can clone to try to reproduce it locally on my machine?
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1096735380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2HOBLOCLPVEAN3Z4LTVEV3TDANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Thank you Augusto Valdivia *Cloud Architect * augustovaldivia.ca http://augustovaldivia.ca
In that example the problem is README.md
. Should be easy enough to add an exception for that.
While we could ignore a README.md
, we wouldn't be able to make this proposed change: https://github.com/hashicorp/terraform-cdk/issues/1315 without e.g. asking the user whether overwrite that file š
Is this a no for the enhancement?
On Wed, Apr 13, 2022 at 4:21 AM Ansgar Mertens @.***> wrote:
While we could ignore a README.md, we wouldn't be able to make this proposed change: #1315 https://github.com/hashicorp/terraform-cdk/issues/1315 without e.g. asking the user whether overwrite that file š
ā Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-cdk/issues/1697#issuecomment-1097699167, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7XK2AZ4BFGP3NGMGVINATVEZ7YNANCNFSM5SZS6HLQ . You are receiving this because you were mentioned.Message ID: @.***>
-- Augusto Valdivia
Hi @ValAug,
no, that's no decision yet. I rather wanted to link to the other issue this proposal might collide with, to make sure we take that into consideration.
To me it would be perfectly fine to allow e.g. a README.md
file until we work on the other issue and only then think about the overwriting vs. asking the user problem. It seems that it can happen quite easily that a user creates a new repository with a README.md
file when using the Github UI for that.
I recently came across this problem while trying cdktf out, and it begs the question; why can't it init
in a non-empty directory if none of the files that exist conflict with what the init
is trying to create? Surely you can just check the files it intends to create and fail if a conflict exists?
Hi @tgmatt, the cdktf-cli currently uses node-sscaff for the different templates we support (and for user defined "remote" templates) and that library does not currently support checking whether files exist (it will just overwrite them).
While we could technically solve this for static files in the template, it would be harder for files that are written programmatically via the .hooks.sscaff.js
script. One example would be the package-lock.json
file and node_modules
directory that are created when executing npm install
in a post hook in such a script.
Maybe extending our list of allowed files (currently Readme.md
and hidden files [e.g. .git
]) to more files that might appear from various workflows (i.e. when using certain Git tools or IDEs) could improve this further. For example here is the list of allowed files from Create React App ā however, they don't share the custom template problem (which can introduce any file).
Hi there! š We haven't heard from you in 30 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.
I'm closing this issue because we haven't heard back in 60 days. āļø If you still need help, feel free to comment or reopen the issue!
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.