Skip to content

Commit

Permalink
Use ignore instead of copy+delete in plan_summary()
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocc committed Dec 6, 2022
1 parent be0e807 commit f8d5f43
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,19 @@ def plan_summary(module_path, basedir, tf_var_files=None, **tf_vars):
# to run multiple tests for the same module in parallel
if os.environ.get('TFTEST_COPY'):
test_path = Path(tmp_path)
shutil.copytree(module_path, test_path, dirs_exist_ok=True)

# if we're copying the module, we might as well remove any files
# and directories from the test directory that are automatically
# read by terraform. Useful to avoid surprises if, for example,
# you have an active fast deployment with links to configs)
autopaths = itertools.chain(
test_path.glob('*.auto.tfvars'),
test_path.glob('*.auto.tfvars.json'),
test_path.glob('terraform.tfstate*'),
test_path.glob('terraform.tfvars'),
test_path.glob('.terraform'),
# any symlinks?
)
for p in autopaths:
if p.is_dir():
shutil.rmtree(p)
else:
p.unlink()

# if we're copying the module, we might as well ignore files and
# directories that are automatically read by terraform. Useful
# to avoid surprises if, for example, you have an active fast
# deployment with links to configs)
ignore_patterns = shutil.ignore_patterns('*.auto.tfvars',
'*.auto.tfvars.json',
'terraform.tfstate*',
'terraform.tfvars', '.terraform')

shutil.copytree(module_path, test_path, dirs_exist_ok=True,
ignore=ignore_patterns)

else:
test_path = module_path

Expand Down

0 comments on commit f8d5f43

Please sign in to comment.