Open fabiendelpierre opened 6 years ago
I don't believe TF will let you remove resources and providers in the same apply
run as it needs the provider to remove said resources.
I had to deal with the exact same situation. This one definitely did the trick, As @fabiendelpierre mentioned
$ terraform state rm
But it's a pain when you have to delete quite a long list of grants and users associated with a single environment. I wonder if there's an option like this for such a use,
$ terraform state rm mysql_user.*
$ terraform state rm mysql_grant.*
So that it can find all the resources that starts with this common attribute and deletes the rest, marked by an *
.
@kennethgds Using some shell magic this can be solved quite nicely: terraform state list | grep mysql | while line -r read; do terraform state rm $line; done
(I did not verify this, but this should be fairly close to the answer)
Hi there,
So firstly I'm not sure if this is an issue with the mysql provider, or with Terraform itself, or something else... sorry if it's got nothing to do with this provider.
This is with macOS Terraform v0.11.7 and mysql provider v1.1.0.
I have a super simple setup like this:
I abridged the
aws_db_instance
resource because I don't believe it's relevant, and simply used bogus strings for the DB, users and passwords, but the resources are as simple in my code as they are shown here.The code above works fine. However, today, I found out I didn't need to manage the RDS endpoint because the DBA team "owns" these things and would simply set up the endpoint and provide me with credentials. So I deleted the above bits from my TF code and ran
terraform apply
. At that time, I was asked to provide values forprovider.mysql.endpoint
andprovider.mysql.username
.I tried to leave them blank (since they were no longer applicable), but TF said:
I tried filling in bogus values just to get past it, but TF also did not like that because it couldn't connect to the bogus endpoint I provided.
I then deleted the contents of
/.terraform/modules/
and/.terraform/modules/darwin_amd64/terraform-provider-mysql_v1.1.0_x4
, then ranterraform init
, and it reinstalled the mysql module. Again, the code calling the mysql provider and associated resources was gone at that point.I triple, quadruple checked that I had no other mention of
provider "mysql" {}
in my code. I knew I didn't, because I've never had to use this provider anywhere, so the instance I deleted was the only one, so this was indeed nowhere else.I figured then that something might be in my state file, so I did this:
I keep my state file in an AWS S3 remote, if it matters.
Only after doing this was I able to run
apply
without issue, and everything was normal after that.Again, I don't know if that's actually normal behavior when dealing with providers, and I've only ever dealt with the one provider (AWS), so deleting a provider from my code is not something I've ever done until today.
Expected Behavior
terraform apply
removes resources that I removed from my code.Actual Behavior
See above for details, but TF asked me to configure the mysql provider when running
apply
even though the code was gone.Steps to Reproduce
terraform apply
provider "mysql" {}
andmysql_...
bits from the code you just ran.terraform apply
Let me know if you have any questions. Obviously, not a big deal, and maybe that's working as intended. Thought I'd report it just in case.