Skip to content

Getting json.SyntaxError unexpected end of JSON input #402

Closed
@ColOfAbRiX

Description

Setup:

$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

$ terraform --version
Terraform v0.11.2

$ terragrunt --version
terragrunt version v0.13.23

My relevant file structure is the following:

.
├── components                    <-- For me "components" is less confusing than "modules"
│   └── network
│       ├── main.tf
│       ├── terraform.tfvars      <-- Used for the "*-all" commands
│       └── vars.tf
└─ live
    ├── test
    │   ├── network
    │   │   ├── terraform.tfstate <-- State file
    │   │   └── terraform.tfvars  <-- Network variables + terragrunt config
    │   ├── secrets.tfvars        <-- Environment secrets
    │   └── environment.tfvars    <-- Environment variables
    └── global.tfvars             <-- Global variables + terragrunt config

live/test/network/terraform.tfvars

terragrunt {
  terraform {
    source = "../../../components//network"
  }
  include {
    path   = "${find_in_parent_folders("global.tfvars")}"
  }
}

live/global.tfvars

terragrunt {
  terraform {
    extra_arguments "var_files" {
      commands = ["${get_terraform_commands_that_need_vars()}"]
      required_var_files = [
        "${get_tfvars_dir()}/../secrets.tfvars",
        "${get_tfvars_dir()}/../environment.tfvars"
      ]
    }
  }
  remote_state {
    backend = "local"
    config {
      path = "${get_tfvars_dir()}/terraform.tfstate"
    }
  }
}

components/network/main.tf

terraform { backend "local" {} }
provider "aws" {
  ...
}
module "networks" {
  source ="git::ssh://..."
  ...
}
module "dns" {
  source ="git::ssh://..."
  ...
}

What happens

I start cleaning rm -rf ~/.terragrunt.
I also have an existing and correct live/test/network/terraform.tfstate file:

$ python -mjson.tool < terraform.tfstate
{
    "lineage": "d130af51-dd8d-4e0b-b7e5-a4a8f540a517",
    "modules": [
        {
            "depends_on": [],
            "outputs": {},
...

Then I run terragrunt plan and everything works fine, I see terraform init runs, and also terraform plan, terraform refreshes the state and tells me there's nothing to do (because my infrastructure already exists):

[terragrunt] 2018/01/11 14:33:37 Running command: terraform plan -var-file=/home/user/automation-aws/terraform/live/test/network/../secrets.tfvars -var-file=/home/user/automation-aws/terraform/live/test/network/../environment.tfvars
Refreshing Terraform state in-memory prior to plan...

...

No changes. Infrastructure is up-to-date.

But then when I run again terragrunt plan I always get:

$ TERRAGRUNT_DEBUG=true terragrunt plan
[terragrunt] [/home/user/automation-aws/terraform/live/test/network] 2018/01/11 14:32:48 Running command: terraform --version
[terragrunt] 2018/01/11 14:32:48 Reading Terragrunt config file at /home/user/automation-aws/terraform/live/test/network/terraform.tfvars
[terragrunt] 2018/01/11 14:32:48 Cleaning up existing *.tf files in /home/user/.terragrunt/uWoy5G8HnUMi9iTnxFm02FQuNks/7VUZV-UT9PfkDWR3uowb8V2xUoI
[terragrunt] 2018/01/11 14:32:48 Downloading Terraform configurations from file:///home/user/automation-aws/terraform/components into /home/user/.terragrunt/uWoy5G8HnUMi9iTnxFm02FQuNks/7VUZV-UT9PfkDWR3uowb8V2xUoI using terraform init
[terragrunt] 2018/01/11 14:32:48 *json.SyntaxError unexpected end of JSON input
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:74 (0x4cb64c)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:66 (0x4cb55f)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/remote/terraform_state_file.go:51 (0x4cb2aa)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/remote/remote_state.go:68 (0x4c849c)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:473 (0x45e40c)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:283 (0x45ce78)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:256 (0x45cd6a)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:402 (0x45d77e)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/download_source.go:363 (0x460fd9)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/download_source.go:92 (0x45f54b)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/download_source.go:54 (0x45f0ff)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:212 (0x45c8a3)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:196 (0x45c740)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:177 (0x45c42c)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:502 (0x49cc24)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:268 (0x49a95d)
/home/ubuntu/.go_workspace/src/github.com/gruntwork-io/terragrunt/main.go:20 (0x4010c4)
/usr/local/go/src/runtime/proc.go:183 (0x42a864)
/usr/local/go/src/runtime/asm_amd64.s:2086 (0x458e51)

[terragrunt] 2018/01/11 14:32:48 Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Expected result
Terragrunt shouldn't throw an expection about JSON

I guess the issue is with file lookup, relative paths or something similar because the actual JSON of the tfstate file is correct. I saw this similar issue #275 but it doesn't seem to apply in my case.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions