1
votes

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?

1
terraform init definitely shouldn't wipe out the state. Are you sure you're writing state out properly in the first place?ydaetskcoR
@ydaetskcoR i may have assumed that terraform 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 maybe import is the only way to refresh the state for resources that are not yet in the state, but are in configuration?Gauthier

1 Answers

0
votes

Actually i needed to implement the import function for my provider, as terraform refresh can't refresh resources that are not in the State.