Backend configuration changed

I’m confused with the error of terraform init.
So, I have an existing AKS cluster and now I want use the same terraform scripts to create new cluster but in another tenant and subscription. Backend should stay the same.
I want to keep my existing cluster working until I create new.

Terraform init gives me this error:
Error: Backend configuration changed

│ A change in the backend configuration has been detected, which may require
│ migrating existing state.

│ If you wish to attempt automatic migration of the state, use “terraform
│ init -migrate-state”.
│ If you wish to store the current configuration with no changes to the
│ state, use “terraform init -reconfigure”.

It is clear that terraform sees resources in state file which are in wrong tenant.

Now I don’t know which option to choose? Backend stays the same so, -migrate-state would migrate the state where?!

Thanks a lot!

The configuration referenced here is what is stored from the backend block in the root module. Changing that configuration will indicate to terraform that the state storage location may have changed, which is why you are being prompted to migrate the state. Terraform doesn’t know the meaning of each individual backend configuration option, it can only detect if they have changed, so it’s giving you the option to move the existing state, or start over with a new one.

If the actual location of the state file is unchanged, or the location changed but you want to start with a new empty state, then you want -reconfigure.

If the storage location has changed and you want to keep the existing state, then use -migrate-state to migrate the existing state from the old location to the new location.

1 Like