I am using terraform oci provider. While I was trying to create compute instances using k8 nodepools I encountered failure , so I deleted that tfstate file and ran the script again which resulted in creation of few duplicate resources like vcn , LB . Due to few constraints I want to retain the old resources (the ones those were created during failed execution) and delete the new ones . Both are created with same name and new tfstate file is having the details of new (duplicate) resources. How can I delete the new duplicate resources and make tfstate file consistent with required resources?
1 Answers
2
votes
This is a good use case for Terraform Import.
As long as the resource supports it you can import the existing resource terraform import <resource.path> after running terraform delete -target <resource to delete>
terraform destroywith a new state file, it must delete only newly created resources it created irrespective of the duplication? - harshavmb