Good morning everyone. I am very new to terraform and I was trying to deploy resources to my azure subscription, the deployment was successful but the problem is I deleted the resources from the cloud and the terraform files from my computer including the tfstate and now I am trying to do fresh deployments but nothing seems to work. I have tried terraform show and it says my subscription has no resource which is true and also terraform init with -reconfigure and -migrate-state. Is there a way I can reset everything and go back to new on a fresh slate. Thank you for your help
Hi, @kellynthy!
As for Terraform, you can simply initialize a new project (i.e., create the TF code in another directory), and this will be a brand new/fresh environment from the Terraform point of view. Assuming you’re using a local state file with no additional state configuration.
As for Azure, it’s hard to guess what is really happening on your end. If you could provide an example of the error that you’re getting — it would help! I assume it is something about the Azure Subscription (did you try to create a new one?), but it’s hard to guess without details.
Thank you for your reply @vasylenko I initialize in a new directory but it did not work. I did create a subscription. The terraform validate command shows it is a valid configuration but nothing happens. And also when I ran terraform init, i could not find the . terrfaorm folder that houses the terraform configurations
Hey!
you can simply delete the below file/directories from your repo where you did init&apply terraform command:
- .terraform (directory)
- terraform.tfstate
- terraform.tfstate.backup
- .terraform.lock.hcl
Basically deleting the terraform.tfstate
should be enough, but if you need a totally fresh repo, you can remove above file/directories.
Br,
Meraj
I did that but nothing seems to work
@kellynthy, I see that terraform init
was executed on the screenshot you provided. This command initialize (kind of starts, bootstraps, etc.) the Terraform project: it performs several tasks to prepare your code for the actual work against the real resources. You can read more about this command here: Command: init | Terraform by HashiCorp
But I don’t see anything related to the apply command on your screenshots. Did you run terraform apply
? It is the apply command that makes the actual changes with the resources.
As for the .terraform
directory, perhaps you don’t see it because PowerShell hides it from the listing by default because its name starts with a dot. Instead, try using the following command to list the content of your project: Get-ChildItem -Hidden
.
Yea. The solution was to saved save everything manually from the start.