minamijoyo / tfupdate

Update version constraints in your Terraform configurations
MIT License
542 stars 23 forks source link

tfupdate provider returns panic #51

Closed nanaones closed 2 years ago

nanaones commented 2 years ago

I am getting the following error:

$  docker run -it --rm -v $PWD:/work --entrypoint /bin/bash minamijoyo/tfupdate

bash-5.0# tfupdate provider -v 3.63.0 -r aws /work
panic: runtime error: index out of range [19] with length 19

goroutine 1 [running]:
github.com/minamijoyo/tfupdate/tfupdate.(*ProviderUpdater).updateTerraformRequiredProvidersBlockAsObject(0xc00007eae0, 0xc00009bdc0, 0xc0000d3860, 0xc0001b8c70, 0xa2dac0)
        /work/tfupdate/provider.go:120 +0x27f
github.com/minamijoyo/tfupdate/tfupdate.(*ProviderUpdater).updateTerraformBlock(0xc00007eae0, 0xc000228540, 0x7ffcb818feef, 0xc)
        /work/tfupdate/provider.go:72 +0x1f3
github.com/minamijoyo/tfupdate/tfupdate.(*ProviderUpdater).Update(0xc00007eae0, 0xc000228540, 0x7ffcb818feeb, 0x3)
        /work/tfupdate/provider.go:38 +0x39
github.com/minamijoyo/tfupdate/tfupdate.UpdateHCL(0xbd78c0, 0xc000010700, 0xbd6de0, 0xc0001c3bc0, 0x7ffcb818feef, 0xc, 0xb1cd06, 0x8, 0x7ffcb818feeb, 0x3, ...)
        /work/tfupdate/update.go:58 +0x1dd
github.com/minamijoyo/tfupdate/tfupdate.UpdateFile(0xbe6d78, 0xf459f0, 0x7ffcb818feef, 0xc, 0xb1cd06, 0x8, 0x7ffcb818feeb, 0x3, 0x7ffcb818fee1, 0x6, ...)
        /work/tfupdate/file.go:26 +0x298
github.com/minamijoyo/tfupdate/tfupdate.UpdateFileOrDir(0xbe6d78, 0xf459f0, 0x7ffcb818feef, 0xc, 0xb1cd06, 0x8, 0x7ffcb818feeb, 0x3, 0x7ffcb818fee1, 0x6, ...)
        /work/tfupdate/file.go:114 +0x1fa
github.com/minamijoyo/tfupdate/command.(*ProviderCommand).Run(0xc0001afdc0, 0xc000020090, 0x5, 0x5, 0xc0001c37a0)
        /work/command/provider.go:68 +0x579
github.com/mitchellh/cli.(*CLI).Run(0xc0000d4c80, 0xc0000d4c80, 0xc00019ff68, 0x1)
        /go/pkg/mod/github.com/mitchellh/cli@v1.0.0/cli.go:255 +0x41a
main.main()
        /work/main.go:48 +0x1d0
nanaones commented 2 years ago

The files to be applied are:

terraform {
  required_version = "~> 1.0.0"

  required_providers {
    aws = {
      "source"  = "hashicorp/aws"
      "version" = "~> 3.45.0"
    }
  }
}
minamijoyo commented 2 years ago

@nanaones Thank you for reporting the issue.

I was able to reproduce it. I have identified that the cause is that the source and version are enclosed in double quotes. It's not explicitly stated in the documentation, but the terraform cli looks accepting the quoted syntax too. https://www.terraform.io/docs/language/providers/requirements.html

As a workaround, do not enclose source and version in double quotes.

<       "source"  = "hashicorp/aws"
<       "version" = "~> 3.45.0"
---
>       source  = "hashicorp/aws"
>       version = "~> 3.45.0"
nanaones commented 2 years ago

@minamijoyo As you said, I checked that there were no errors after the change. Thank you for developing this tool.

minamijoyo commented 2 years ago

@nanaones Thank you for confirmation. I fixed the bug in v0.6.2.