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

Can't create a $0 amount stripe_plan #32

Closed ukd1 closed 3 years ago

ukd1 commented 4 years ago
resource "stripe_plan" "base_platform_fee_0" {
  product    = stripe_product.base_platform_fee.id
  nickname   = "$0/month (Annual Prepaid)"
  amount     = 0
  interval   = "month"
  usage_type = "licensed"
  currency   = "usd"
}

ends up posting this to stripe:

{
  "active": "true",
  "billing_scheme": "per_unit",
  "currency": "usd",
  "interval": "month",
  "interval_count": "1",
  "nickname": "$0/month (Annual Prepaid)",
  "product": "prod_FM8XCymxvqHCB5",
  "usage_type": "licensed"
}

raising a 400 from stripe:

{
  "error": {
    "message": "If the billing scheme is set to per_unit, the amount parameter must be set.",
    "param": "amount",
    "type": "invalid_request_error"
  }
}

TF errors:

Error: {"status":400,"message":"If the billing scheme is set to per_unit, the amount parameter must be set.","param":"amount","request_id":"req_REKuHBMBjmHbEo","type":"invalid_request_error"}

  on modules/stripe/main.tf line 35, in resource "stripe_plan" "base_platform_fee_0":

  35: resource "stripe_plan" "base_platform_fee_0" {

Error: {"status":400,"message":"If the billing scheme is set to per_unit, the amount parameter must be set.","param":"amount","request_id":"req_AMXW3u1lDwXQGE","type":"invalid_request_error"}
  on modules/stripe/main.tf line 35, in resource "stripe_plan" "base_platform_fee_0":

  35: resource "stripe_plan" "base_platform_fee_0" {
ukd1 commented 4 years ago

Digging a little, it appears to be as on https://github.com/franckverrot/terraform-provider-stripe/blob/master/stripe/resource_stripe_plan.go#L188 getOk is used and returns false if something is zero - https://github.com/franckverrot/terraform-provider-stripe/blob/9996396e8f9aa66be41ec2d79cc01d094b5f3bf6/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go#L88 specifically on https://github.com/franckverrot/terraform-provider-stripe/blob/9996396e8f9aa66be41ec2d79cc01d094b5f3bf6/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go#L102

Seems like ValueOrZero might be useful; but not sure what the side effects are when it's supposed to be nil...

franckverrot commented 4 years ago

Hey there, thanks for reporting this.

Do you wanna give a try sending a PR or would you like me to investigate (not sure I'll have time this week though so you can go ahead and try if you'd like to speed things up.) Thanks!

ukd1 commented 4 years ago

@franckverrot we may have time to do a PR in a couple of weeks time - this is being put as an optional part of some internal work we're doing! If we start the work, I'll make sure we check here / comment here that we are doing so!

franckverrot commented 3 years ago

Implemented in https://github.com/franckverrot/terraform-provider-stripe/releases/tag/v1.7.0

Thanks @trea and thanks @ukd1 for reporting!