hashicorp / terraform-plugin-framework

A next-generation framework for building Terraform providers.
https://developer.hashicorp.com/terraform/plugin/framework
Mozilla Public License 2.0
303 stars 93 forks source link

Incomplete error message when setting a `string` in integer property of `NestedAttributeObject` #1032

Closed ianaya89 closed 2 months ago

ianaya89 commented 2 months ago

Module version

github.com/hashicorp/terraform-plugin-framework v1.11.0

Relevant provider source code

var NodeGroupSet = rschema.SetNestedAttribute{
    NestedObject:        NodeGroupAttribute,
    Validators: []validator.Set{
        setvalidator.SizeAtLeast(1),
    },
}

var NodeGroupAttribute = rschema.NestedAttributeObject{
    Attributes: map[string]rschema.Attribute{
        "name": rschema.StringAttribute{
            Optional:            true,
            Computed:            true,
        },
        "node_type": rschema.StringAttribute{
            Required:            true,
        },
        "capacity_per_zone": rschema.Int64Attribute{
            Required:            true,
            Validators: []validator.Int64{
                int64validator.AtLeast(1),
            },
        },
        "zones": rschema.ListAttribute{
            ElementType:         types.StringType,
            Optional:            true,
            Computed:            true,
            Validators: []validator.List{
                listvalidator.SizeAtLeast(1),
            },
        },
    },
}

Terraform Configuration Files

resource "altinitycloud_env_aws" "this" {
  name           = "test"
  cidr           = "10.1.0.0/21"
  region         = "us-east-1"
  aws_account_id = "434208318714"
  zones          = ["us-east-1a", "us-east-1b"]

  node_groups = [
    {
      name              = 0
      node_type         = "large.m6i"
      capacity_per_zone = "not a number"
      reservations      = ["CLICKHOUSE", "SYSTEM", "ZOOKEEPER"]
    }
  ]
}

Debug Output

Expected Behavior

This validation message:

Inappropriate value for attribute "node_groups": element 0: attribute "capacity_per_zone": number required

Actual Behavior

This validation message:

Inappropriate value for attribute "node_groups": a number is required.

Steps to Reproduce

  1. terraform init
  2. terraform plan
austinvalle commented 2 months ago

Hey there @ianaya89 👋🏻, thanks for reporting the issue and sorry you're running into trouble here.

I'm going to close this issue as the error is coming from HCL (and it's underlying type system), so I believe the Terraform core issue tracker or HCL issue tracker would be a better place to discuss this behavior, as there is nothing terraform-plugin-framework can do about this error:

An additional note, in your example, node_groups is a set type, where each element is identified by the value itself, rather than an index like a list, so your expected behavior of printing a numerical index isn't something that HCL/Terraform could achieve.

ianaya89 commented 2 months ago

@austinvalle Thanks for taking a look!