I am developing a custom Terraform provider for our private cloud, and i struggle with the state file between my builds.
Basically every time i build a new version of the custom provider, i need to perform a terraform init
, which seems to wipe out the existing state.
I have some resources that still exist, but Terraform thinks they don't, since its state file is empty.
I tried to perform a terraform refresh
, but it doesn't do anything:
Empty or non-existent state file.
Refresh will do nothing. Refresh does not error or return an erroneous exit status because many automation scripts use refresh, plan, then apply and may not have a state file yet for the first run.
I saw in the documentation that one can import
existing infrastructure, but for this the provider needs to implement the import function.
Is there a way to force Terraform to refresh the state?
terraform init
definitely shouldn't wipe out the state. Are you sure you're writing state out properly in the first place? – ydaetskcoRterraform init
wipes the state. The state is written fine. I am also updating resources outside of terraform to perform some tests etc, so at some point i may have an out-of-sync state. But maybeimport
is the only way to refresh the state for resources that are not yet in the state, but are in configuration? – Gauthier