Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify Product ID? #31

Closed
arai-ta opened this issue Mar 3, 2023 · 6 comments
Closed

How to specify Product ID? #31

arai-ta opened this issue Mar 3, 2023 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@arai-ta
Copy link

arai-ta commented Mar 3, 2023

Hi,

I want to create a Product by specifying an ID, but it doesn't work.
Does this provider supports specifying product IDs?

My .tf is following;

terraform {
  required_providers {
    stripe = {
      source  = "lukasaron/stripe"
      version = "= 1.6.3"
    }
  }
}

provider "stripe" {}

resource "stripe_product" "myplan" {
  id   = "prod_myplan"
  name = "My Plan"
}

apply results;

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # stripe_product.myplan will be created
  + resource "stripe_product" "myplan" {
      + active = true
      + id     = (known after apply)
      + name   = "My Plan"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

stripe_product.myplan: Creating...
stripe_product.myplan: Creation complete after 0s [id=prod_NSKLZrMRKodugv]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

I expected the ID to be prod_myplan, but it is actually prod_NSKLZrMRKodugv.

I reffered:

Versions:

Terraform v1.3.9
on darwin_arm64
+ provider registry.terraform.io/lukasaron/stripe v1.6.3
@lukasaron
Copy link
Owner

Hello,
According to the Stripe API documentation:

"An identifier will be randomly generated by Stripe. You can optionally override this ID, but the ID must be unique across all products in your Stripe account."

Therefore I let Stripe generate the ID. However, when there is a desire to have individual ID I can update the logic.

You don't usually need the ID of the product.

May I ask what is the reason or use case?

@lukasaron lukasaron added the question Further information is requested label Mar 3, 2023
@lukasaron lukasaron self-assigned this Mar 3, 2023
@arai-ta
Copy link
Author

arai-ta commented Mar 3, 2023

Of course. Thanks for the reply.

I am trying to replace the subscription function of an existing web application with Stripe.
There are multiple ways to map Products in the application to Products in Stripe.

For example;

  • Embed the generated Stripe Product ID in the application code
  • Set the application identifier in the Product metadata
  • Set the Product ID as the application identifier

I think the last case is one of the simpler solutions.

To use this method, it is necessary to set the specified product ID in multiple environments, including Live and Test mode.
I wanted to use Terraform and this Stripe Provider for this purpose.

Also, the document following suggested using the same ID in Live and Test mode.

https://stripe.com/docs/development/checklist#:~:text=use%20the%20same%20ID%20values

When recreating necessary objects in live mode, be certain to use the same ID values (for example, the same plan ID, not the same name) to guarantee your code will continue to work without issue.

So, I think if Terraform can create a Product resource by specifying the ID, it would be useful. :)

Hope this helps your understanding.

@lukasaron
Copy link
Owner

Please have a look at the newly released version 1.6.5 where you can specify the product_id field.

@arai-ta
Copy link
Author

arai-ta commented Mar 31, 2023

I've tried version 1.6.6 and confirmed that the product_id field works.
Thank you!

@arai-ta
Copy link
Author

arai-ta commented Oct 4, 2023

Hello @lukasaron,
I wrote a blog about how this Stripe Provider has helped me in my work.
It is written in Japanese, but if you would like to read it. Thank you!!
https://creators-note.chatwork.com/entry/terraform-meets-stripe

@lukasaron
Copy link
Owner

Thanks a lot @arai-ta I am glad the Stripe provider helped you achieve your goals!
Unfortunately, my Japanese is very bad and I believe you wrote something nice there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants