Skip to content

Proposal: Simplify KnownValue checks for query results #563

@gdavison

Description

@gdavison

terraform-plugin-testing version

github.com/hashicorp/terraform-plugin-testing v1.14.0-beta.1

Use cases

When making knownvalue checks on a resource returned by a query, it will be more readable to perform one lookup for the resource and then apply one or more knownvalue checks.

This will especially be the case when looking up a resource by an identity with multiple attributes is supported.

Proposal

Add a querycheck function, e.g. ExpectResourceKnownValues, which will take a list-resource address, a resource lookup mechanism (either by display name or resource identity), and one or more path and knownvalue check pairs.

For example:

querycheck.ExpectResourceKnownValues("example_resource", querycheck.ResourceByIdentity(...), []querycheck.KnownValueCheck{
  querycheck.KnownValue(tfjsonpath.New("attr1"), knownvalue.NotNull()),
  querycheck.KnownValue(tfjsonpath.New("name"), knownvalue.StringExact("example")),
})

It will be an error if the lookup mechanism returns either zero or more than one result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions