hashicorp / hashicorp/terraform-plugin-testing
Proposal: Allow using `Computed` values from `statecheck.StateCheck` in subsequent `knownvalue.Check`
- Dominant language
- Go
- Stars
- 68
- Forks
- 22
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
### 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:
```go
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
Contributor guide
Assessment
This issue has not been assessed yet.