This message was deleted.
# discuss-terraform
a
This message was deleted.
b
What do you mean you lost it? Was it deleted? When using the local backend Terraform makes a backup state, do you have any of those?
My first thought on a resolution would be to look at the remote location (maybe an S3 bucket?) and see if there are any recovery options there.
If your state is completely lost then there is one option, but it is time consuming and risk prone. You could import all of the objects with the Terraform cli and rebuild the state like that.
☝️ 1
b
State file is complectly losed and Please guide how can I know the existing resource list to import the resource to rebuild the state file
b
Welp, there isn't a way to know which resources your Terraform used to manage so you are going to have to decide which resources in your cloud provider you want to manage and how they relate to your config.
Like I said, this is going to be time consuming and risk prone.
An easier alternative might be to use your current config to deploy a new set of resources and migrate your workloads from the unmanaged set to the managed one.
b
I was deployed RKE2 downstream cluster through terraform and I have the same workspace.
Also I have same config identical accores all the environment (dev,sit,uat and prod).
b
ok, you are saying that the one state file (that was lost) was serving multiple workspaces (dev, sit, uat, and prod), and was deploying identical environments, so when you lost your state file you now have a jumble of identical resources that was kept separate by Terraform workspace, right?
b
All the environment has separate workspace with own state file Now I lost uat and Prod environment state file only, I have the dev,sit state file and all terraform config are identical
b
If you are deploying clusters through Rancher then you only need to find the Rancher resources and import them. These would be a rancher2_cluster_v2 resource.
b
Yes, we deployed through Rancher custom downstream cluster, how to know existing resources list for the import?
b
Just import the cluster resource
b
Hi Matt, I have tried to import the rancher2_cluster_v2 resource and getting below error.
b
Is the downstream cluster rke1 or rke2?
b
It's RKE2
b
Does you cluster have a name in Rancher?
b
Yes, we have named it dev-cluster, sit-cluster and prd-cluster
b
When you view the yaml version of the cluster in the Rancher UI does it have a Status.Name ?
b
Please find the below screenshot of status and name through Rancher UI
b
hmm, welp, sounds like Terraform is having trouble reading it. Try setting TF_LOG to TRACE and see if you can find the API call and responses.
b
Hi Matt, I successfully imported the downstream cluster resources, and the Terraform state file has been generated and stored remotely. the error which I encountered during import before "Error: Setting cluster V2 legacy data: cluster_v1 id is empty" Root Cause: This issue occurred due to an incorrect Cluster ID being provided during the import process. Solution: Ensure that the correct Cluster ID is used when running the Terraform import command. The correct format is:
Copy code
terraform import <resource_type>.<resource_name> <resource_id>
Example: terraform import rancher2_cluster_v2.cluster fleet-default/prd-cluster
Thank you Matt for your support and assistance.
b
Great News!!
np, glad we could get it sorted.