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
terraform-plugin-testing version
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.CompareValuethat can be initialized using astatecheck.StateCheckand then used as aknownvalue.Check.I'm not sure which package this would fit best in, so in the example, I'll use
some_pkg.For example:
I have a working implementation in hashicorp/terraform-provider-aws#44609