hashicorp / hashicorp/terraform-plugin-testing

Consider introducing `statecheck` support for Import test mode

Open
#365 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
68
Forks
22
Avg merge
2d 12h
Merged PRs (30d)
1

Description

### terraform-plugin-testing version

```
v1.9.0
```

### Use cases

`terraform-plugin-testing` currently supports a new method of asserting values in Terraform state during `Config` mode with the [`statecheck` package](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing@v1.9.0/statecheck) and the [`(TestStep).ConfigStateChecks` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing@v1.9.0/helper/resource#TestStep).

The `Import` mode for testing also has the [`(TestStep).ImportStateCheck`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing@v1.9.0/helper/resource#ImportStateCheckFunc) field for performing state checks after, see: https://github.com/hashicorp/terraform-plugin-testing/blob/9501a02b120c21132854c73c01d415dc53e6c81f/helper/resource/testing_new_import_state.go#L152-L177

### Proposal

We could introduce a similar state check implementation to `ConfigStateChecks`, with a new field `(TestStep).ImportStateChecks`. This implementation should be equivalent to the `Config` mode, since they both use `terraform show` to grab the JSON state representation.

We could also consider adjusting these tests and our documentation to use the [import block](https://developer.hashicorp.com/terraform/language/import), where we would then switch to using the `plancheck` package for checking values.

### References

- The random provider has some tests that use this step to extract state values during import: https://github.com/hashicorp/terraform-provider-random/pull/599

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.