lukasaron / terraform-provider-stripe

Terraform Stripe Provider
https://registry.terraform.io/providers/lukasaron/stripe/latest
Mozilla Public License 2.0
57 stars 24 forks source link

importing price with tiered/graduated price #80

Closed dbarrosop closed 2 weeks ago

dbarrosop commented 2 months ago

Hello, thanks for this awesome terraform provider. I am trying to import a price with a tiered/graduate scheme and looks like the tiers aren't correctly imported:

$ terraform state show stripe_price.xxx
# stripe_price.xxx:
resource "stripe_price" "xxx" {
    active         = true
    billing_scheme = "tiered"
    currency       = "usd"
    id             = "price_xxxx"
    lookup_key     = null
    metadata       = {}
    nickname       = null
    product        = "prod_xxx"
    tax_behavior   = "inclusive"
    tiers_mode     = "graduated"
    type           = "recurring"

    recurring {
        aggregate_usage = "max"
        interval        = "month"
        interval_count  = 1
        usage_type      = "metered"
    }
}

This is a problem because if I try to apply afterwards it wants to add all the tiers causing the price to be destroyed and recreated.

Regards

lukasaron commented 2 months ago

Hi @dbarrosop,

Thank You for using the Terraform Stripe Provider and also reporting issues!

I've found the bug and please try the next version 3.2.1 which should give you tier levels for price resource during import.

dbarrosop commented 2 months ago

Hi @lukasaron, thanks for the super quick response. I can confirm it works now. I noticed a couple of issues though:

  1. After the import I need to specify inside the tier both the unit_amount and the unit_amount_decimal (same for flat_amount and flat_amount_decimal):
    tiers {
    up_to               = 100
    unit_amount         = 0
    flat_amount         = 500
    flat_amount_decimal = 500
    }

If I don't specify both it flags it as a change, which leads to the issue below.

  1. If I change something in the tier the changes are detected properly but it doesn't trigger creating a new price. Instead it claims it will be updated in place, it will say it succeeded but the change actually didn't go through (which I think as expected as stripe doesn't let you change tiers I believe)

I can open separate issues if you want. The first one must be due to the import process as I didn't see it in newly created prices. Second one I can replicate in both imported and new prices created with the terraform provider.

Thanks again for the provider, it is so much easier to keep the test and production environments in synch now.

Regards

lukasaron commented 2 months ago

@dbarrosop,

Thanks for these points! It helps me understand your use case and also improve this provider.

Let me investigate on my side.

lukasaron commented 2 weeks ago

Please have a look at the latest release.