hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
433 stars 230 forks source link

Acceptance Testing Framework for_each Resource Support (unexpected index type (string)) #536

Open bflad opened 4 years ago

bflad commented 4 years ago

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

paddycarver commented 4 years ago

I'm not going to lie, I'm not entirely sure why this doesn't work right now. In theory, it should--the test framework shouldn't care about for_each at all, it should never even see it. Terraform should just handle it.

I have a sneaking suspicion there's a deeper problem here or the SDK has trouble handling the output of for_each or something. But we're going to need to do a bit more digging to figure out what's going on here, because you definitely shouldn't be getting apply errors from configs that standalone Terraform can apply; after all, the whole point of the new test driver is that standalone Terraform is applying them.

akselleirv commented 2 years ago

Any update on this issue? I would also like to add tests for resources using for_each.