plumber-cd / terraform-backend-git

Terraform HTTP Backend implementation that uses Git repository as storage
Apache License 2.0
185 stars 18 forks source link

terraform-backend-git.hcl doesn't work when using `terraform -chdir=` and #20

Closed guimaluf closed 2 years ago

guimaluf commented 2 years ago

When using terraform -chdir and terraform-backend-git.hcl config file, the terraform-backend-git seems unhappy and throws

[terraform-backend-git]: repository must be set

How to reproduce

$ mkdir terraform
$ cat <<EOF > terraform/main.tf
resource "null_resource" "echo" {
  provisioner "local-exec" {
    command = "echo it works"
  }
}
EOF

$ cat <<EOF > terraform-backend-git.hcl
git.repository = "$(git remote get-url origin)"
git.ref = "master"
git.state = "terraform.tfstate"
EOF

$ ./terraform-backend-git-linux-amd64 git terraform -chdir=terraform/ init
[terraform-backend-git]: repository must be set

Doesn't matter if I put the config file in the -chdir target.

$ cp  terraform-backend-git.hcl terraform/
$ ./terraform-backend-git-linux-amd64 git terraform -chdir=terraform/ init
[terraform-backend-git]: repository must be set

Without -chdir it does work

$ cd terraform/
$ ../terraform-backend-git-linux-amd64 git terraform init
[terraform-backend-git]: Using config file: /home/gb637/workspace/tfm-debug/terraform/terraform-backend-git.hcl
[terraform-backend-git]: WARNING: HTTP basic auth is disabled, please specify TF_BACKEND_GIT_HTTP_USERNAME and TF_BACKEND_GIT_HTTP_PASSWORD
[terraform-backend-git]: listen on 127.0.0.1:6061

Thanks for the great work on this project.

dee-kryvenko commented 2 years ago

Thanks for your report! I haven't looked yet but from the top of my head - the backend would not know you instructed tf to use different working dir so it has to be told explicitly with a s parte arg that doesn't exists at the moment. I'll think of something to allow for this scenario.