Why is tfstate file getting deleted frequently ? Is there any way to prevent it from getting deleted

My Tfstate file is getting deleted very frequently, post which i have download the previous version from S3 and restore it . Is there any specific amount of builds post which the tfstate file will get deleted . Is there any way to prevent tfstate file being deleted/lost automatically and why does this happen. Please suggest !

Hi @Noel2602!

Can you say a little more about what the situation looks like after your state file is deleted? For example, is the object in S3 just gone altogether, or is it zero-length, or is it still valid but contains no resources?

I’ve not previously heard of Terraform silently removing a state snapshot from S3, so I’m not sure yet what to suggest to debug further but perhaps knowing what it looks like after the state is deleted will help me think of what to try next.

@apparentlymart I would not be able to run the Job in jenkins and would get the below error post which i have to download previous artifact and upload the same after which the run will succeed in jenkins .

Error message " No artifacts found that match the file pattern “**/*.tfstate”.configuration error "

Hi @Noel2602,

I recognize that as being an error from Jenkins rather than from Terraform. If you are using remote state in S3 then Terraform will write state snapshots directly to your chosen S3 bucket and not to the local filesystem, and so it’s expected behavior that there would be no state snapshots in the local filesystem in that case.