Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message when JSON parsing fails #16332

Closed
kevinburkeotto opened this issue Oct 12, 2017 · 6 comments
Closed

Misleading error message when JSON parsing fails #16332

kevinburkeotto opened this issue Oct 12, 2017 · 6 comments
Milestone

Comments

@kevinburkeotto
Copy link

kevinburkeotto commented Oct 12, 2017

Terraform Version

Terraform v0.10.7

Terraform Configuration Files

This module:

module "ecs_service" {
  # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
  # to a specific version of the modules, such as the following example:
  source = "a-secret-github.com-source-file"
  service_name = "${var.service_name}"
  task_arn                = "${aws_ecs_task_definition.task.arn}"
  desired_number_of_tasks = 3
}

depends on this definition:

resource "aws_ecs_task_definition" "task" {
  family                = "${var.service_name}"
  container_definitions = "${data.template_file.container_definition.rendered}"
  task_role_arn         = "${aws_iam_role.ecs_task_role.arn}"
}

I was getting this very misleading error message:

Error running plan: 1 error(s) occurred:

* module.ecs_service.var.task_arn: Resource 'aws_ecs_task_definition.task' not found for variable 'aws_ecs_task_definition.task.arn'

It's confusing, because I can see very clearly that the task definition exists. Running with TF_LOG=DEBUG revealed the following logs:

2017/10/12 14:12:45 [DEBUG] Resource state not found for "aws_ecs_task_definition.task": aws_ecs_task_definition.task
2017/10/12 14:12:45 [DEBUG] ReferenceTransformer: "aws_ecs_task_definition.task" references: []
2017/10/12 14:12:45 [ERROR] root: eval: *terraform.EvalValidateResource, err: Warnings: []. Errors: [ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character ']' looking for beginning of value]
2017/10/12 14:12:45 [ERROR] root: eval: *terraform.EvalSequence, err: Warnings: []. Errors: [ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character ']' looking for beginning of value]
2017/10/12 14:12:45 [ERROR] root: eval: *terraform.EvalInterpolate, err: Resource 'aws_ecs_task_definition.task' not found for variable 'aws_ecs_task_definition.task.arn'
2017/10/12 14:12:45 [ERROR] root: eval: *terraform.EvalSequence, err: Resource 'aws_ecs_task_definition.task' not found for variable 'aws_ecs_task_definition.task.arn'
2017/10/12 14:12:45 [TRACE] [walkPlan] Exiting eval tree: module.ecs_service.var.task_arn

Basically, the JSON was invalid. Here's the JSON file - there's a trailing comma that I missed.

    "environment": [
      {"name" : "SERVER_TEXT", "value" : "${server_text}"},
    ]

It would be nice if the JSON error message was bubbled up to the default log level, so I could see what the problem was, instead of the (very confusing) error message about how a resource didn't exist.

@jbardin jbardin added the config label Oct 13, 2017
@vincer
Copy link
Contributor

vincer commented Oct 18, 2017

Just ran into this as well. I had an errant , in my container definition and it took me a while to track it down due to that confusing error message.

@schmod
Copy link

schmod commented Nov 1, 2017

Related: hashicorp/terraform-provider-aws#1644

@schmod
Copy link

schmod commented Nov 1, 2017

This is a likely duplicate of: #14333

@amitsehgal
Copy link

validated json from jsonlint ..still gets this error

@apparentlymart
Copy link
Contributor

Hi all! Sorry for this weird behavior and for the delayed response.

I've just tried this with the v0.12.0-alpha1 release using the following simplified configuration:

provider "aws" {
  region = "us-west-2"
}

resource "aws_ecs_task_definition" "task" {
  family                = "placeholder"
  container_definitions = "invalid"
}

In the alpha release, this validation problem is now being correctly caught and reported during the plan step:

$ terraform plan

Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character 'i' looking for beginning of value

  on ecs-json-validation.tf line 8:
   8: }

Unfortunately the reported location of the invalid definition is not correct yet because the providers have not yet been updated to return detailed source location information and so it's just indicating the "aws_ecs_task_definition" "task" block as a whole rather than specifically the container_definitions attribute. That will be dealt with in a later change to the provider SDK, since this bug currently applies to all resource-level validation errors.

Since the direct problem reported in this issue has been addressed -- that resource validation errors during plan were not always halting the plan -- I'm going to close this out. The error messages will be improved further in later issues/PRs. Thanks for reporting this, and sorry again for the delay in addressing it.

@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants