terragrunt: terragrunt state pull throws an "unexpected end of JSON input" error
I’m not sure what’s going on here, but if you run:
% terragrunt init
<snip>
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
<snip>
Initializing provider plugins...
Terraform has been successfully initialized!
% terragrunt state pull > terraform.tfstate
[terragrunt] [/Users/chrisswingler/src/infra_terraform] 2018/07/06 12:03:12 Running command: terraform --version
[terragrunt] 2018/07/06 12:03:13 Reading Terragrunt config file at /Users/chrisswingler/Sprout/src/infra_terraform/terraform.tfvars
[terragrunt] 2018/07/06 12:03:13 unexpected end of JSON input
[terragrunt] 2018/07/06 12:03:13 Unable to determine underlying exit code, so Terragrunt will exit with error code 1
Terragrunt pukes on something not being valid JSON. I don’t know what it’s puking on, though. terraform state pull works fine.
Debug output:
➜ infra_terraform [default] git:(terragrunt_k8s) ✗ TERRAGRUNT_DEBUG=trye terragrunt state pull > terraform.tfstate
[terragrunt] [/Users/chrisswingler/Sprout/src/infra_terraform] 2018/07/06 13:16:51 Running command: terraform --version
[terragrunt] 2018/07/06 13:16:51 Reading Terragrunt config file at /Users/chrisswingler/Sprout/src/infra_terraform/terraform.tfvars
[terragrunt] 2018/07/06 13:16:51 *json.SyntaxError unexpected end of JSON input
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:79 (0x142fbbb)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:71 (0x142faed)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:56 (0x142f925)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/remote/remote_state.go:69 (0x142c10b)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:571 (0x14d4182)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:441 (0x14d3361)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:410 (0x14d31d9)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:323 (0x14d27b6)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:235 (0x14d1a48)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:204 (0x14d1950)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:185 (0x14d1644)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:502 (0x14762c8)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:268 (0x14743ec)
/private/tmp/terragrunt-20180703-977-jbnzes/terragrunt-0.15.2/main.go:20 (0x14d7be4)
/usr/local/Cellar/go/1.10.3/libexec/src/runtime/proc.go:198 (0x102ccb2)
/usr/local/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:2361 (0x1056f11)
[terragrunt] 2018/07/06 13:16:51 Unable to determine underlying exit code, so Terragrunt will exit with error code 1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (9 by maintainers)
Commits related to this issue
- Prefer remote tfstate over local tfstate, if present This addresses issue #514: Upon a local to remote tfstate migration, Terraform will leave an empty `terraform.tfstate` file in the working direct... — committed to andreykaipov/terragrunt by andreykaipov 3 years ago
- Prefer remote tfstate over local tfstate, if present This addresses issue #514: Upon a local to remote tfstate migration, Terraform will leave an empty `terraform.tfstate` file in the working direct... — committed to andreykaipov/terragrunt by andreykaipov 3 years ago
- Prefer remote tfstate over local tfstate, if present (#1885) This addresses issue #514: Upon a local to remote tfstate migration, Terraform will leave an empty `terraform.tfstate` file in the wor... — committed to gruntwork-io/terragrunt by andreykaipov 3 years ago
Do you by chance have a
.tfstatefile sitting around in the current directory? E.g., if you run this all from a clean folder and with the--terragrunt-source-updateflag, does it work?I also ran into this issue, following what seemed to me to be a fairly standard use case.
terragrunt initproperly migrated the state to S3terragrunt planbroke with the invalid JSON error*.tfstatefiles from my local file system fixed the errorIt would be helpful if
terragruntwould either:@brikis98 - could this issue be reopened?
I ran into this as well. Removing the terraform.tfstate file fixed the issue.
@brikis98 Could you please add this as a warning to the stderr, I guess it will safe a lot of time for all of us.
I had this issue today and wanted to chime in that yes having
*.tfstatefiles in the directory will cause problems. I ran in to it when I pulled remote state toterraform.tfstateand it started messing with everything.I recommend using
*.outor similar instead.i ran into it as well. The error message:
is really quite useless. I had a hunch that it could be about state, but unfortunatelly i just checked remote state json from s3 bucket and it was ok - didn’t notice local “terraform.tfstate” and “.terraform.tfstate.lock.info” files, as they were in
.gitignore- what a waste of time it was!Would be really useful to get more informative error messages (in this case mentioning
terraform.tfstateand perhaps even suggesting deleting it, as 0 bytes state file doesn’t make sense)I just ran into this. Seems like either deleting the empty file or issuing a warning would be a good fix.
Happened to me too (Terragrunt v0.23.10) after setting up S3 remote store backend.
The initialization asked for migration like this
and succeeded. The following attempt to do
terragrunt planresulted inwhich was caused by an empty terraform.tfstate file in the cache. Removing the file fixed it.
Edit: yes, removing the 0 byte file worked…it just didn’t seem like it because i had other errors that this was masking. Which may speak to better messaging, like adding the filename. Clearly my mistake, and thanks for the great project.
Closing due to inactivity