hashicorp / hashicorp/terraform-plugin-testing
Proposal: Add attribute coverage options to acceptance framework
- Dominant language
- Go
- Stars
- 68
- Forks
- 22
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
### SDK version
```console
$ go mod edit -json | jq '.Require[] | select(.Path=="github.com/hashicorp/terraform-plugin-sdk/v2")'
{
"Path": "github.com/hashicorp/terraform-plugin-sdk/v2",
"Version": "v2.0.1"
}
```
### Use-cases
When writing and running acceptance tests for Terraform providers, it is often useful to ensure that we're testing all attributes on a resource. This is especially true when different output attributes will be set or not set based on input attributes.
### Proposal
The proposal is to add coverage features to the acceptance test framework. Some ideas include options to
* require checks for each attribute
* require checking each element of a collection
The motivating example is from the AWS provider. The `aws_api_gateway_domain_name` resource has two sets of domain-name-related outputs: `cloudfront_domain_name` and `cloudfront_zone_id`, and `regional_domain_name` and `regional_zone_id`. The `cloudfront_*` attributes are only set if `endpoint_configuration.types` is `EDGE`, and the `regional_*` attributes are only set if `endpoint_configuration.types` is `REGIONAL`.
For completeness, there should be an acceptance test with `endpoint_configuration.types` is `EDGE` that ensures
```go
resource.TestCheckResourceAttr(resourceName, "regional_domain_name", ""),
resource.TestCheckResourceAttr(resourceName, "regional_zone_id", ""),
```
and an acceptance test with `endpoint_configuration.types` is `REGIONAL` that ensures
```go
resource.TestCheckResourceAttr(resourceName, "cloudfront_domain_name", ""),
resource.TestCheckResourceAttr(resourceName, "cloudfront_zone_id", ""),
```
This would not be appropriate for all acceptance tests, so it would be an optional value on the `resource.TestStep` and/or `resource.TestCase`.
Additional tooling, such as [tfproviderlint](https://github.com/bflad/tfproviderlint) could require that certain types of tests would have the flags set.
Contributor guide
Assessment
This issue has not been assessed yet.