-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Description
Terraform Version
> terraform version
Terraform v1.14.0
on darwin_arm64Use Cases
Currently, terraform test supports assertions for failure conditions using expect_failures.
However, as indicated by the documentation and other similar issues, this feature is only used to test custom conditions.
I have a use case where I am attempting to do opaque-box testing using terraform, meaning I am running a module and then using a "loader" module to verify the output (similar to how the docs describe).
Yet one of the core requirements of my implementation is that prevent_destroy is used to alleviate a deletion risk associated with a specific provider.
Currently, I cannot use expect_failures to assert on a test that attempts to destroy a resource being blocked by terraform.
This is a problem because my tests are designed to maintain the contracts of the terraform module. While I am not worried about terraform itself having a bug in the prevent_destroy feature, I am worried about other contributors to the module I'm using accidentally removing the prevent_destroy lifecycle block, leading to a deletion risk.
Attempted Solutions
Attempted to use expect_failures, but it only works with custom conditions.
Proposal
I propose that the expect_failures feature is either enhanced, or an additional failure assertion is added, which allows for asserting on lifecycle failures or errors generated during a terraform run.
References
- Allow expect_failures to target child module input variables in Terraform test run blocks #34951
- Terraform test execution doesn't handle
prevent_destroy=true#34960 - Terraform test: ability to expect overall failures of plan or apply command #35628
- Allow expect_failure to assert on an error message #37835
- Terraform test expect_failure doesn't work for permission errors #37799
- terraform test expected_failure not recognizing missing data resource as failure #35949
- [terraform test] Support expect_failures of resouces inside local module in run blocks #34700
- Have a force_delete true/false on repositories similar to AWS ECR. jfrog/terraform-provider-artifactory#1069