cloudposse / terraform-null-label

Terraform Module to define a consistent naming convention by (namespace, stage, name, [attributes])
https://cloudposse.com/accelerate
Apache License 2.0
635 stars 317 forks source link

terraform validaton fails #137

Closed ntmggr closed 1 year ago

ntmggr commented 1 year ago

Using latest source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.25.0"

terraform --version                                                                                                                                                                     nikos
Terraform v1.3.6
on darwin_amd64

╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/label/variables.tf line 38, in variable "context":
│   38:     condition     = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
│     ├────────────────
│     │ while calling lookup(inputMap, key, default...)
│     │ var.context is a string
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/label/variables.tf line 43, in variable "context":
│   43:     condition     = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
│     ├────────────────
│     │ while calling lookup(inputMap, key, default...)
│     │ var.context is a string
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵

Validation failed: terraform/modules/label
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/label/variables.tf line 38, in variable "context":
│   38:     condition     = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
│     ├────────────────
│     │ while calling lookup(inputMap, key, default...)
│     │ var.context is a string
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/label/variables.tf line 43, in variable "context":
│   43:     condition     = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
│     ├────────────────
│     │ while calling lookup(inputMap, key, default...)
│     │ var.context is a string
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.```
Nuru commented 1 year ago

This happens if you set context = "some string value". context is defined as type = any because it has been around since before Terraform had types and we want it to be as compatible as possible with various Terraform versions. However, it actually is required to be an object, which you would get from the output of another null-label module. You can infer the full definition of the object from the default value: https://github.com/cloudposse/terraform-null-label/blob/38187a06950aa2a3cfb09a87315c412018315b19/variables.tf#L3-L28

Closing as invalid.