terraform-docs icon indicating copy to clipboard operation
terraform-docs copied to clipboard

Terraform v1.8 function: provider::terraform::encode_expr(var.list) causes attribute separation error

Open melonger opened this issue 2 years ago • 2 comments

Describe the bug

After upgrading to TF 1.8, and taking advantage of the provider::terraform::encode_expr function, terraform docs now errors out about following:

$ terraform-docs markdown .
Error: Missing attribute separator: Expected a newline or comma to mark the beginning of the next attribute.

If I comment out the lines that include the function, terraform-docs completes without issue.

How can we reproduce it?

If you write any code that leverages a variable that is a type of list(object{ var = string}) and then try to inject a list into that string.

Nested within my module. Parameter will translate the value into an API call to Terraform Cloud

variable "variables" {
  description = "Variables to apply to workspace"
  type = list(object({
    key         = string
    value       = string
    category    = string
    description = string
    hcl         = bool
  }))
  default = []
}

Snippit from Root Module:

module "sample_module" {
  variables = [
    {
      key         = "custom_variable"
      value       = provider::terraform::encode_expr(var.custom_bootstrap_principals)
      category    = "terraform"
      description = "Sample Description"
      hcl         = true
    }
}
$ terraform-docs markdown .
Error: Missing attribute separator: Expected a newline or comma to mark the beginning of the next attribute.

Environment information

  • terraform-docs version v0.17.0 linux/amd64
  • terraform 1.8
  • Any OS

melonger avatar Apr 12 '24 03:04 melonger

Another example of missing support, working without flaw

locals {
  customer_names = ["foo", "bar", "baz"]
  customers = {
    for customer_name in local.customer_names : customer => yamldecode(file("${path.module}/../config/${customer_name}.yaml")) if fileexists("${path.module}/../config/${customer}.yaml")
  }
}

Failing

locals {
  customer_names = ["foo", "bar", "baz"]
  customers = {
    for customer_name in local.customer_names : customer => provider::terraform::decode_tfvars(file("${path.module}/../config/${customer_name}.tfvars")) if fileexists("${path.module}/../config/${customer}.tfvars")
  }
}
Terraform Docs src.......................................................Failed
- hook id: terraform-docs-src
- exit code: 1

Error: Invalid 'for' expression: Extra characters after the end of the 'for' expression.

slackfan avatar Apr 24 '24 11:04 slackfan

It isn't only that function, it seems to be provider functions, in general.

Failing:

  validation {
    condition = alltrue([
      for k, v in var.event_mapping : anytrue([
        !v.bisect_batch_on_function_error,
        alltrue([
          v.bisect_batch_on_function_error,
          contains([
            "dynamodb",
            "kinesis"
          ], try(provider::aws::arn_parse(v.source_arn).service, ""))
        ])
      ])
    ])
    error_message = "`bisect_batch_on_function_error` is only available for DynamoDB and Kinesis event sources."
  }

Command:

terraform-docs markdown table .
Error: Missing argument separator: A comma is required to separate each function argument from the next. (and 11 other messages)

dustindortch avatar May 15 '24 22:05 dustindortch