terramate-io / terramate

Terramate CLI is an open-source Infrastructure as Code (IaC) Orchestration and Code Generation tool for Terraform, OpenTofu and Terragrunt.
https://terramate.io
Mozilla Public License 2.0
3.12k stars 86 forks source link

[BUG] Error: repository has untracked files #1672

Closed az-z closed 2 months ago

az-z commented 2 months ago

Describe the bug if the repo / current directory has uncommited files "terramate generate" fails with "Error: repository has untracked files"

To Reproduce git clone

terramate generate // above assumes the repo is configured for TM **Expected behavior** the previous version of TM did not have this behavior. In ideal world running the tm generate only on committed changes makes sense. At the same time, it gets in the way when i want to "sanity check" the configuration. This forces me to check in all, even temp files that i not necessary going to have in the repo in 5 minutes. Very frustrating experience. **Environment (please complete the following information):** - OS: [e.g. Linux] - OS Version [e.g. Ubuntu 20.04] - Git Version [e.g. 2.35.1] (git --version) - Terramate Version [e.g. 0.1.0] (terramate --version) **Additional context** Add any other context about the problem here.
i4ki commented 2 months ago

Hi @az-z What's your Terramate version?

i4ki commented 2 months ago
 $ terramate generate
Nothing to do, generated code is up to date
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   terramate.tm.hcl

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    terramate.prof

no changes added to commit (use "git add" and/or "git commit -a")
$ terramate generate
Nothing to do, generated code is up to date

Generate does not check for untracked/uncommitted files. Please provide more details so we can reproduce this.

az-z commented 2 months ago

It is 0.6.3 on fedora 39

On Thu, Apr 25, 2024, 13:02 i4k @.***> wrote:

Hi @az-z https://github.com/az-z What's your Terramate version?

— Reply to this email directly, view it on GitHub https://github.com/terramate-io/terramate/issues/1672#issuecomment-2077755330, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGHHXK3VFKYGWM5MJEGDCDY7EZJDAVCNFSM6AAAAABGZINRNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZXG42TKMZTGA . You are receiving this because you were mentioned.Message ID: @.***>

az-z commented 2 months ago

Give me a few hours, pleae.

On Thu, Apr 25, 2024, 13:06 i4k @.***> wrote:

$ terramate generate Nothing to do, generated code is up to date $ git status On branch main Your branch is up to date with 'origin/main'.

Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: terramate.tm.hcl

Untracked files: (use "git add ..." to include in what will be committed) terramate.prof

no changes added to commit (use "git add" and/or "git commit -a") $ terramate generate Nothing to do, generated code is up to date

Generate does not check for untracked/uncommitted files. Please provide more details so we can reproduce this.

— Reply to this email directly, view it on GitHub https://github.com/terramate-io/terramate/issues/1672#issuecomment-2077763624, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGHHXLKDDIYVE2BE5BF4QTY7EZ3FAVCNFSM6AAAAABGZINRNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZXG43DGNRSGQ . You are receiving this because you were mentioned.Message ID: @.***>

az-z commented 2 months ago

here we go :

az@ip-10-0-2-15: D9/DEV$ git status
On branch feature/WWWPRIV-229-implement-ssm-parameter-stor
Your branch is up to date with 'origin/feature/WWWPRIV-229-implement-ssm-parameter-stor'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   globals.tm

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    deleted:    ../../../../1
    modified:   globals.tm
    modified:   ../../config/Security/security_groups.tf
    modified:   ../../../../terramate.tm
    deleted:    ../../../../terramate.tm.hcl

az@ip-10-0-2-15: D9/DEV$ alias -p | grep tmi
alias tmi='terramate generate  && terramate --log-level=info  -C ./ run   -- terraform init'
az@ip-10-0-2-15: D9/DEV$ ls -la
total 13
drwxrwx--- 1 root vboxsf    0 Apr 25 14:35 .
drwxrwx--- 1 root vboxsf 4096 Dec 31  1969 ..
drwxrwx--- 1 root vboxsf 4096 Apr 25 14:35 cicd
drwxrwx--- 1 root vboxsf 4096 Apr 25 13:05 comp
-rwxrwx--- 1 root vboxsf  687 Dec 31  1969 globals.tm
az@ip-10-0-2-15:  D9/DEV$ cat ../../../../terramate.tm 
# file: terramate.tm.hcl
terramate {
  config {
  git {
    default_branch = "master"
#    check_untracked = false
#    check_uncommitted = false
    }
  }
}
az@ip-10-0-2-15:D9/DEV$ tmi
Nothing to do, generated code is up to date
Error: repository has uncommitted files

Notes:

    modified:   ../../../../terramate.tm
    deleted:    ../../../../terramate.tm.hcl

the terramate.tm.hcl was empty and i (finally) got around to remove it. the terramate.tm was modified , as I was trying to get the terramate to run TF code, by adding/removing the "check_" flags.

the current configuration of terramate.tm is how it was used to worked.

i4ki commented 2 months ago

It's not terramate generate that is failing but the terramate --log-level=info -C ./ run -- terraform init command.

Since version v0.4.5 you can override the safeguard options of the config in the command line itself. Example:

$ terramate run --disable-safeguards=git-untracked -- terraform init

This ☝️ will disable just the "untracked files check". You can disable all git checks with --disable-safeguards=git or disable ALL safeguards with -X.

# Disables safeguards for this command
$ terramate run -X -- terramate init

Check here for all the supported options: https://terramate.io/docs/cli/orchestration/safeguards#disabling-checks

Let me know if this solves your problem.

az-z commented 2 months ago

now, if i un-comment both "check" variables and run terramate init the command executes as expected with the `terraform init execution:

D9/DEV$ tmi
Nothing to do, generated code is up to date
terramate: Entering stack in /Clients/SOPRO/D9/DEV/cicd
terramate: Executing command "terraform init"

Initializing Terraform Cloud...
.....

and TF apply works as expected....

az-z commented 2 months ago

Oh, I see. Yes, this should work. I'll update the project config with the new section. Thank you so much for your help!

On Thu, Apr 25, 2024, 14:57 i4k @.***> wrote:

It's not terramate generate that is failing but the terramate --log-level=info -C ./ run -- terraform init command.

Since version v0.4.5 you can override the safeguard options of the config in the command line itself. Example:

$ terramate run --disable-safeguards=git-untracked -- terraform init

This ☝️ will disable just the "untracked files check". You can disable all git checks with --disable-safeguards=git or disable ALL safeguards with -X .

Disables safeguards for this command

$ terramate run -X -- terramate init

Check here for all the supported options: https://terramate.io/docs/cli/orchestration/safeguards#disabling-checks

Let me know if this solves your problem.

— Reply to this email directly, view it on GitHub https://github.com/terramate-io/terramate/issues/1672#issuecomment-2077969074, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGHHXMOPIFPFWDAJ57UWYLY7FG2BAVCNFSM6AAAAABGZINRNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZXHE3DSMBXGQ . You are receiving this because you were mentioned.Message ID: @.***>

az-z commented 2 months ago

Please close as "not a bug" and resolved

On Thu, Apr 25, 2024, 17:28 Andrew Z @.***> wrote:

Oh, I see. Yes, this should work. I'll update the project config with the new section. Thank you so much for your help!

On Thu, Apr 25, 2024, 14:57 i4k @.***> wrote:

It's not terramate generate that is failing but the terramate --log-level=info -C ./ run -- terraform init command.

Since version v0.4.5 you can override the safeguard options of the config in the command line itself. Example:

$ terramate run --disable-safeguards=git-untracked -- terraform init

This ☝️ will disable just the "untracked files check". You can disable all git checks with --disable-safeguards=git or disable ALL safeguards with -X.

Disables safeguards for this command

$ terramate run -X -- terramate init

Check here for all the supported options: https://terramate.io/docs/cli/orchestration/safeguards#disabling-checks

Let me know if this solves your problem.

— Reply to this email directly, view it on GitHub https://github.com/terramate-io/terramate/issues/1672#issuecomment-2077969074, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGHHXMOPIFPFWDAJ57UWYLY7FG2BAVCNFSM6AAAAABGZINRNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZXHE3DSMBXGQ . You are receiving this because you were mentioned.Message ID: @.***>

az-z commented 2 months ago

@i4ki , very sorry to update the closed ticket. I think you might want to update the example here https://terramate.io/docs/cli/orchestration/safeguards#example-of-a-project-config-disabling-all-checks that and this https://terramate.io/docs/cli/configuration/#terramate-config-git-block-schema can be confusing.