pytest-terraform icon indicating copy to clipboard operation
pytest-terraform copied to clipboard

TEARDOWN_OFF does not seem to work with scopes other than function

Open adam-turner-j opened this issue 3 years ago • 2 comments

The following snippet produces an apply and destroy despite the teardown option. Other scopes such as module produce the same result.

@terraform('network', scope='session', teardown=terraform.TEARDOWN_OFF)
def test_network(network):
    assert network['aws_vpc.main.cidr_block'] == '10.0.0.0/16'

When removing the scope argument and letting it default to function, the terraform is applied but not destroyed, as expected. Is there anything I am doing incorrectly?

adam-turner-j avatar May 25 '21 18:05 adam-turner-j

hmm, thanks for the bug report.

kapilt avatar Jul 02 '21 10:07 kapilt

+1

I have a use case for retaining the output of a local file resource to help with automated documentation. The output from my test is added to the README.md to illustrate features to the user.

A workaround for my use case is to copy the file within a test case. Terraform will still destroy the file it created, but the copied one remains in-tact.

baolsen avatar Oct 14 '22 06:10 baolsen