GoogleCloudPlatform / terraform-python-testing-helper

Simple Python test helper for Terraform.
https://pypi.org/project/tftest/
Apache License 2.0
214 stars 31 forks source link

Finer grained cache hash input #60

Closed marshall7m closed 2 years ago

marshall7m commented 2 years ago

This PR fixes the issue of the caching feature having too broad of parameters that are being used for generating the caching value.

The current implementation uses the entire environment variable dictionary which includes test-level environment variables (e.g. PYTEST_CURRENT_TEST). This results in the cache being not used if a subsequent pytest test session were to be called with a different test that still requires the same tftest instance. To solve this, an internal _env attribute is set within __init__ that defines the env vars that the tftest instance was initiated with. This attribute will be used instead of the env attribute.

In addition, the file contents within tfdir and any tf_var_file or extra_files method arguments are used for generating the caching value. This means that if the Terraform configuration or any tfvars.json files were to change, the cache will be ignored.

ludoo commented 2 years ago

Actually, I just realized this is introducing a dependency on checksumdir, making the module less portable. Can you find a way of using the standard library to achieve the same? I'm holding back releasing for now.