hashicorp / hashicorp/terraform-plugin-testing
helper/resource: run Check even when apply fails in TestStep
- Dominant language
- Go
- Stars
- 68
- Forks
- 22
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
### SDK version
1.6.0
### Use-cases
We want to test the behavior when an Update fails.
Currently, we can only use ExpectError to check the error message. However, if we want to check more things, e.g. what's the value of a given attributes in tfstate, it is not possible because "Check" function is not run when there are errors, see:
https://github.com/hashicorp/terraform-plugin-sdk/blob/7f53d13be6bdb4b24d447c26d66bcf8888c5be90/helper/resource/testing_config.go#L99
### Proposal
Run the Check function before returning the Update failures, e.g.
```
state, err = shimNewState(newState, step.providers)
if err != nil {
return nil, err
}
// Run any configured checks
if step.Check != nil {
if step.Destroy {
if err := step.Check(stateBeforeApplication); err != nil {
return state, fmt.Errorf("Check failed: %s", err)
}
} else {
if err := step.Check(state); err != nil {
return state, fmt.Errorf("Check failed: %s", err)
}
}
}
if stepDiags.HasErrors() {
return state, newOperationError("apply", stepDiags)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.