hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Inaccurate diagnostics context for nested fields #93

Closed radeksimko closed 5 years ago

radeksimko commented 5 years ago

Terraform Version

369d512e22bf18fd810b8583e6914458abc569aa

Terraform Configuration Files

resource "azurerm_kubernetes_cluster" "aks_with_rbac" {
  name                = "something"
  location            = "test"
  resource_group_name = "tada"
  dns_prefix          = "radek"
  kubernetes_version  = "1.11"

  role_based_access_control {
    enabled = true
  }

  agent_pool_profile {}
  service_principal {
    client_id     = "00000000-0000-0000-0000-000000000000"
    client_secret = "00000000000000000000000000000000"
  }
}

Expected Behavior

Snippet of code pointing to the right LOC - i.e. to the definition of parent block which is missing arguments.

Actual Behavior

$ terraform plan
Error: Missing required argument

  on main.tf line 1, in resource "azurerm_kubernetes_cluster" "aks_with_rbac":
   1: resource "azurerm_kubernetes_cluster" "aks_with_rbac" {

The argument "name" is required, but no definition was found.

Error: Missing required argument

  on main.tf line 1, in resource "azurerm_kubernetes_cluster" "aks_with_rbac":
   1: resource "azurerm_kubernetes_cluster" "aks_with_rbac" {

The argument "vm_size" is required, but no definition was found.

Steps to Reproduce

$ terraform plan

Additional Context

As documented the arguments reported as missing are arguments nested under agent_pool_profile block, which is not obvious from the error output.

apparentlymart commented 5 years ago

The language used in these errors looks like the language produced by HCL itself when asked to decode a block with a missing required argument, so I'm not sure if this is actually an SDK bug or an HCL bug. Will need to dig in some more to see what's missing here.

apparentlymart commented 5 years ago

I've now seen this same behavior in a different program, so this seems to be a bug either in hcldec or in the lower-level body.Content method it is built on.