0

I had the following simple .gitignore file.

#  Local .terraform directories. Here .terraform is a folder
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# .tfvars files
*.tfvars

# .tfplan files
*.tfplan

# .pem files
*.pem

# .hcl files from Terraform v0.14 and newer
*.hcl

# working directory for web app
/globo_web_app/*

**/next-step.txt

Note that this makes git to ignore .terraform.lock.hcl file as well.

Also note that .terraform.lock.hcl is not inside of .terraform folder. See the shot below.

But Now I learnt that this .terraform.lock.hcl file must be checked into VC. So it should not be ignored by git.

I am not able to achieve that.

gitignore file

I tried adding !.terraform.lock.hcl as shown be in the above screen shot. But it does not seem to work. Any ideas?

VivekDev
  • 20,868
  • 27
  • 132
  • 202

1 Answers1

1

Notice you still have this line in your .gitignore:

*.hcl

which, as you know, ignores all .hcl files. If you've added the !.terraform.lock.hcl before that line, it will not work. You need to change it to:

*.hcl
!.terraform.lock.hcl
gmdev
  • 2,725
  • 2
  • 13
  • 28