Skip to content

Proposal: Enhance querychecks for resource display name #565

@gdavison

Description

@gdavison

terraform-plugin-testing version

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

Use cases

When testing query results, we want to be able to validate that a given resource has a specific display name.

In many instances, the display name is not knowable or not fully-knowable before run-time. For example, for many AWS EC2 resource types, the name is taken from the well-known tag Name, and therefore is not unique. This means that another value is appended to the display name for uniqueness. In other cases, resources do not have explicit names, so the display name is derived from one or more resource attributes which are randomly generated by AWS.

Attempted solutions

The current display name check, ContainsResourceWithName, expects an exact match for the name and checks only for the existence of the name, not that it is associated with a specific resource.

Proposal

Add a querycheck function, e.g. ExpectResourceDisplayName, that takes a list-resource address, a resource lookup mechanism, and allows passing a check for the display name. Display name checks could include exact match and regex match.

For example:

querycheck.ExpectResourceDisplayName("example_resource", querycheck.ResourceByIdentity(...), querycheck.DisplayNameExact("expected name"))
querycheck.ExpectResourceDisplayName("example_resource", querycheck.ResourceByIdentity(...), querycheck.DisplayNameRegexp(`expected name \([a-z0-9]+\)`))

Additionally, the display name check should allow customization and give access to all of the resource's attributes. This could allow, e.g. checking against a display name that contains Computed attributes.

For example:

CustomDisplayNameFormat("{name} ({id})")

This example, CustomDisplayNameFormat, uses a similar format to the ExpectRegionalARNFormat, ExpectGlobalARNFormat, and ExpectAttributeFormat functions used in the AWS provider

References

The resource lookup mechanism, e.g. querycheck.ResourceByIdentity(...) was proposed in #563

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