hashicorp / hashicorp/terraform-plugin-sdk
Acceptance Testing Framework for_each Resource Support (unexpected index type (string))
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
### SDK version
```
v2.0.1
```
### Use-cases
For parity with real world Terraform configurations, we would like to utilize resource `for_each` support in acceptance testing configurations for the Terraform AWS Provider, to automatically validate documented configuration practices.
Essentially, we would like to enable the commented configuration below, which matches our resource and examples documentation.
https://github.com/terraform-providers/terraform-provider-aws/blob/d104477b8209c4829d1d9601ca3cac7e5cf1cdd5/aws/resource_aws_acm_certificate_validation_test.go#L202-L245
### Attempted Solutions
The acceptance testing framework currently throws an error when applying a test configuration with `for_each` usage:
```
TestAccAWSAcmCertificateValidation_basic: testing_new_config.go:52: unexpected index type (string) for "aws_route53_record.test", for_each is not supported
TestAccAWSAcmCertificateValidation_basic: testing_new.go:57: unexpected index type (string) for "aws_route53_record.test", for_each is not supported
--- FAIL: TestAccAWSAcmCertificateValidation_basic (70.91s)
```
Since test configuration workarounds are currently applied, any resources changes will require manual re-verification of certain functionality.
### Proposal
Support `for_each` indexed resources in the acceptance test configurations, similar to `count` resources. In our case, we don't necessarily need all other testing functionality to support `for_each` indexed resources (e.g. `TestCheckFunc`), just the successful apply of the configuration would be great for our situation.
### References
- https://github.com/terraform-providers/terraform-provider-aws/pull/14199
- https://registry.terraform.io/providers/hashicorp/aws/3.1.0/docs/resources/acm_certificate_validation#dns-validation-with-route-53
Contributor guide
Research direction
Start with testing_new_config.go:52 and testing_new.go:57, where the unexpected string index error is reported, and inspect the existing count-resource handling. Use the referenced ACM certificate validation acceptance test and its for_each configuration as the reproduction. Done means that configuration applies successfully; TestCheckFunc support is explicitly out of scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devtools, testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100