terraform-provider-local
terraform-provider-local copied to clipboard
Add option for failing if local file already exists
Terraform CLI and Provider Versions
N/A
Use Cases or Problem Statement
Local file is useful for unit testing scenarios.
Sometimes third parties want to test failure conditions with tests, such as what happens when Terraform apply is partially successful.
See for example this issue and associated PR with comments: https://github.com/cloud-custodian/pytest-terraform/issues/59
With that PR it would have been great to be able to run TF destroy on the local file and ensure that partially applied resources are cleaned up by testing for the existence of local file after the test has run.
However with the current "silent overwrite" behaviour there is no way to force local file to fail.
I can also imagine a use case where in a complex repo, local file silently overwriting other instances of itself would be unexpected behaviour for the user. It would be better to allow them a way to ensure that a conflict is made visible.
Proposal
A simple optional variable could be added for overriding the default behaviour.
Perhaps support multiple file modes, like overwrite (default), append, error. Though for this use case, only "error" is desirable.
While the order of Terraform apply is usually non-deterministic, the depends_on property can be used to control ordering. So "append" is foreseeably something that could make sense to someone in future.
How much impact is this issue causing?
Low
Additional Information
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct