Skip to content

Proposal: Allow using Computed values from statecheck.StateCheck in subsequent knownvalue.Check #562

@gdavison

Description

@gdavison

terraform-plugin-testing version

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

Use cases

When testing List Resources, to fully validate, e.g. that a Resource Identity is present in the results, the full Resource Identity is needed. However, attributes in the Resource Identity may be Computed, and therefore must be retrieved from the resource itself.

Proposal

Add a struct, inspired by statecheck.CompareValue that can be initialized using a statecheck.StateCheck and then used as a knownvalue.Check.

I'm not sure which package this would fit best in, so in the example, I'll use some_pkg.

For example:

func TestExample(t *testing.T) {
  id := some_pkg.StateValue()

  // ...

  Steps: []resource.TestStep{
    {
      // ...
      ConfigStateChecks: []statecheck.StateCheck{
        id.GetStateValue(resourceName, tfjsonpath.New("id"),
      },
    },
    {
      // ...
      Query: true,
      QueryResultChecks: []querycheck.QueryResultCheck{
        querycheck.ExpectIdentity("aws_vpc.test", map[string]knownvalue.Check{
          "account_id": tfknownvalue.AccountID(),
          "region":    knownvalue.StringExact(acctest.Region()),
          "id":        id.Value(),
        }),
      },
    },
  })
}

I have a working implementation in hashicorp/terraform-provider-aws#44609

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