franckverrot / terraform-provider-stripe

A Terraform Provider for Stripe
https://registry.terraform.io/providers/franckverrot/stripe/latest
Mozilla Public License 2.0
242 stars 51 forks source link

'terraform apply' with deleted coupon in state gives error code 'resource_missing' #46

Open jlucktay opened 3 years ago

jlucktay commented 3 years ago

Hi there, and thank you for this provider! Looking forward to making use of it. I was fiddling with some of the basic usage stuff outlined in the README and ran into a snag.

  1. Created the example MLK coupon with code = "MLK_DAY"
  2. Changed the code value in my .tf file
  3. Ran terraform apply --auto-approve
  4. Noted in the Stripe Dashboard UI that the coupon code did not change, and remained as MLK_DAY
  5. Ran terraform apply --auto-approve again
  6. Coupon code still stubbornly staying on MLK_DAY
  7. Deleted coupon manually in Stripe Dashboard UI
  8. Ran terraform apply --auto-approve again and got the following:
Error: {
  "code": "resource_missing",
  "doc_url": "https://stripe.com/docs/error-codes/resource-missing",
  "status": 404,
  "message": "No such coupon: 'MLK_DAY'",
  "param": "coupon",
  "request_id": "req_bCoPRMtuRHTxLW",
  "type": "invalid_request_error"
}

Will take a quick look and see if I can put a PR together to straighten things out.

The 2 issues as I see them:

mpereira commented 2 years ago

For other folks landing on this issue with the same problem: a workaround is to manually remove all resources that this TF provider reports as missing and then re-running TF plan/apply.

For example, for an output like this:

$ terraform apply
Acquiring state lock. This may take a few moments...
stripe_plan.tier_0_monthly_subscription: Refreshing state... [id=plan_JMq4PtQeTJIdrZ]

Error: {"code":"resource_missing","doc_url":"https://stripe.com/docs/error-codes/resource-missing","status":404,"message":"No such plan: 'plan_JMq4PtQeTJIdrZ'","param":"plan","request_id":"req_hdinACXCrr1Mw0","type":"invalid_request_error"}

Running

terraform state rm 'stripe_plan.tier_0_monthly_subscription'

and then re-running terraform apply would likely fix the problem. It's possible that the TF provider will complain of other missing resources, so just keep terraform state rming them until it doesn't complain.

qck4fun commented 1 year ago

Is removing resources manually considered as final resolution? It is quite unfortunate to solve it this way I think.

@franckverrot do you plan to address this? :pray: