I am using terraform to manage IaC on AWS. There was a s3 bucket created by my terraform project and later I moved the s3 bucket terraform to a different project. So I deleted all s3 related code in my project. When I run terraform apply
I get an error saying Error: error deleting S3 Bucket (xxxx): BucketNotEmpty: The bucket you tried to delete is not empty
I understand that terraform tries to delete the bucket since I removed the code from there.
I tried to use terraform refresh
but got forbidden error: Error: Forbidden: Forbidden
status code: 403, request id: 8351F9C3663AF8FB, host id:
.
I know I can delete the terraform state file from local but this requires me to import all resources. How can I solve this issue? I am using local state not remote state.
You can remove any resource added to your Terraform by:-
List All state:-
terraform state list
remove state which you want to:-
terraform state rm <name>
First you need to remove the resource from the state file by running terraform state rm <resource-id>
and then you need to delete the associated configuration from your codebase. After that run init
, plan
and you will see no changes are required
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With