Skip to content

mapvalidator: KeysAre Returns on First Error #73

Closed
@bflad

Description

@bflad

Terraform CLI and Framework Versions

Terraform v1.3.3
on darwin_arm64

terraform-plugin-framework v0.15.0

Terraform Plugin Framework Code

mapvalidator.KeysAre(
	stringvalidator.LengthAtLeast(3),
	stringvalidator.RegexMatches(regexp.MustCompile(`^x-`), "must begin with x-"),
),

Terraform Configuration

resource "examplecloud_thing" "test" {
  map = {
    zz = "..."
  }
}

Expected Behavior

Both validation errors are returned.

Actual Behavior

Only the first is returned:

Error: Invalid Attribute Value Length
        
          with examplecloud_thing.test,
          on terraform_plugin_test.tf line 3, in resource "examplecloud_thing" "test":
           3: 						zz = "..."
        
        Attribute map["zz"] string length must be at least 3, got: 1

Steps to Reproduce

  1. terraform apply

Logs

No response

Additional Information

For configuration validation, practitioners should see all configuration errors at once, rather than requiring multiple iterations of fixing a configuration.

There is a resp.Diagnostics.HasError() check after Validate() is called in the loop, which doesn't need to be there.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions