terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Where are the terraform test tfstate files located : locally or defined by the backend ?

Open alexis-renard opened this issue 1 year ago • 5 comments

Terraform Version

Terraform v1.7.3

Affected Pages

https://developer.hashicorp.com/terraform/language/tests#modules-state

What is the docs issue?

It's really hard to figure out where the "test" tfstates are stored in the doc, and if it's possible to store it remotely.

Our usecase :

We would like to start integrating terraform test as steps in our CI/CD pipelines. We have faced the challenge of a non automatically working terraform destroy when tearing down stage of the tests (not being able to destroy for any reason). That left us with some undestroyed and hanging resources, and as the terraform test command has been done in an ephemeral environment, the "local state file" lost.

One solution could be to enable storing the tests tfstates not locally but remotely. That way at least, we could take over the destruction of a non working test clean up.

Would it be possible to clarify that point ?

Proposal

No response

References

No response

alexis-renard avatar Feb 13 '24 15:02 alexis-renard

Hi @alexis-renard, thanks for filing this.

In terraform test the state is held entirely in memory for the duration of the operation. Each test file starts with an empty state, and populates it via the run blocks, then attempts to destroy everything that was created at the end. For now, there is no way to store or expose any state created by a test file. We do have a feature request for this: https://github.com/hashicorp/terraform/issues/33786. You can follow that issue to keep track of any changes on this front. We are actively doing discovery on this issue to figure out the best way we can give configuration authors more control over the state that is created during test executions.

Terraform does provide a print out of any resources left alive after the test operation completes, and I think it should also mark the the overall test as failed to make it easier to discover. We do appreciate this is not ideal, but the aim for us is to make the cleanup process as reliable as possible while we figure out a good answer to the state problem.

I'm going to close this as a duplicate of #33786 in terms of creating the ability for customised state management.

Thanks!

liamcervante avatar Feb 13 '24 15:02 liamcervante

Hello @liamcervante, and thanks for the reply ! I think indeed that #33786 will cover the technical aspect of the feature we need.

Yet I have opened this issue as a documentation one, in order to remove the doubt of the current status inside the doc itself. The goal is to clearly state that the test tfstate is managed internally by terraform (which is something relatively new to us users that are used to manage it ourselves). To clearly state that for now, we have no access to it, neither locally or remotely.

Would that make sense that I propose a documentation update in that sense ?

alexis-renard avatar Feb 14 '24 16:02 alexis-renard

Yes, that does make sense. Apologies, I missed the documentation tag. I've reopened this, and will ask the docs team to have a look!

liamcervante avatar Feb 15 '24 09:02 liamcervante

Hello @liamcervante should I wait for some of the docs team input / guidelines or directly submit some proposal ? Thanks !

alexis-renard avatar Mar 05 '24 18:03 alexis-renard

@alexis-renard Directly submitting a proposal is fine! In that case the docs team will do a style and correctness review after it is submitted. Thanks!

crw avatar Mar 05 '24 21:03 crw

Closed per the conversation in https://github.com/hashicorp/terraform/pull/34858

crw avatar Jul 30 '24 22:07 crw