Giter Club home page Giter Club logo

terraform-provider-stripe's Introduction

๐Ÿ‘‹ Hi, Iโ€™m @lukasaron

๐Ÿ‘จโ€๐Ÿ’ป I'm a seasoned software engineer and technology leader currently serving as the Chief Technology Officer. With a strong background in Computer Science and Programming, I combine my technical expertise with strategic vision to drive innovation and shape the technological direction of the company.

๐Ÿš€ Passionate about cutting-edge technologies, cloud platforms, software architectures and software implementations my current focus is not limited to lies in leveraging Go (Golang), Terraform, and Cloud to architect scalable and resilient solutions that empower businesses to thrive in the digital landscape.

๐Ÿ’ก With years of experience in software development and a deep understanding of software architecture and system design, I lead teams in building high-performance, scalable, and secure software systems.

๐ŸŒŸ Committed to continuous learning, I actively stay updated with the latest advancements in the tech industry. I enjoy sharing my knowledge and insights with the community, mentoring aspiring developers, and fostering a culture of innovation.

๐Ÿ“ง Let's connect! Feel free to reach out to me! I'm always open to exciting collaborations, speaking opportunities, or exploring ways to make a positive impact through technology.

terraform-provider-stripe's People

Contributors

alexandrapersea avatar augustoccesar avatar hazel-shen avatar internethostage avatar jabinb avatar lukasaron avatar m0un10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terraform-provider-stripe's Issues

Add Package Pricing Pricing model

Hello,

Thank you for this awesome provider, I have been using it on multiple projects, It's better than anything out there currently.

Lately I've been wanting to to add some products with the "Package Pricing" option but the provider doesn't offer this option yet.
This pricing model exists in Stripe.

Example : 40$ per 100units, 70$ per 200units.

It would be cool to have this added to the module if you have some time ! If not I could also find some time to submit a PR to implement this since I'm the only one who needs it atm.

Thank you !

Request being made with all amount params for tiered price

When creating a volume based tiered price, the request is including all the possible amount params with default to "0" for the ones not specified.

example.tf

resource "stripe_product" "product" {
  name = "Product"
}

resource "stripe_price" "price" {
  product        = stripe_product.product.id
  billing_scheme = "tiered"
  tiers_mode     = "volume"
  currency       = "usd"
  tax_behaviour  = "exclusive"

  tiers {
    up_to       = 24
    unit_amount = 10000
  }

  recurring {
    interval       = "year"
    interval_count = 1
  }
}

Output

Error: {"status":400,"message":"You may only specify one of these parameters: unit_amount, unit_amount_decimal.","param":"tiers[0][unit_amount]","request_id":"req_xxx","type":"invalid_request_error"}

Dashboard Body for request

{
  "active": "true",
  "billing_scheme": "tiered",
  "currency": "usd",
  "product": "prod_xxx",
  "recurring": {
    "interval": "year",
    "interval_count": "1",
    "usage_type": "licensed"
  },
  "tax_behavior": "exclusive",
  "tiers": {
    "0": {
      "flat_amount": "0",
      "flat_amount_decimal": "0",
      "unit_amount": "10000",
      "unit_amount_decimal": "0",
      "up_to": "24"
    }
  },
  "tiers_mode": "volume"
}

Dashboard Body for response

{
  "error": {
    "message": "You may only specify one of these parameters: unit_amount, unit_amount_decimal.",
    "param": "tiers[0][unit_amount]",
    "type": "invalid_request_error"
  }
}

Add notice to `stripe_card` resource about sensitive data in Terraform State

Hello @lukasaron!

I came across this provider on the Terraform Registry and love the idea of configuring Stripe resources with it.

For the stripe_card resource, I'm wondering if I could convince you to add a notice along the lines of:

Using the stripe_card resource may potentially leak credit card information into your Terraform State.
Please see these recommendations on how to treat sensitive data in Terraform State.

I feel that a notice like this might bring this to a bit more attention.

Thank you for your work on the provider!

Wrong import stripe_price

@lukasaron thank your work! There is one more bug report.

Reproducing steps:

  1. Create product and price
resource "stripe_product" "product" {
  name = "minimalist product"
}

resource "stripe_price" "price" {
  product        = stripe_product.product.id
  currency       = "usd"
  active         = true
  billing_scheme = "per_unit"
  unit_amount    =  14999

  recurring {
    interval       = "month"
    interval_count = 1
    usage_type     = "licensed"
  }
}
  1. Run terraform console and check stripe_price.price resource. unit_amount will be correct. Record id for future import.
  2. Run terraform state rm stripe_price.price
  3. Run terraform import stripe_price.price price_XXX. Use id from step 2.
  4. Run terraform console and check stripe_price.price resource. unit_amount will be tonumber(null) instead of correct value.

On price update new one created but old not archived

When updating a price, a new price is created (which I know is expected as prices are not deletable via api), but nothing happens with the old one.

My expectation was that the original price gets archived when updated, which I believe would give us a better working flow where we don't need to actually go into the dashboard and archive it (set it as inactive), or create duplicates on the terraform file (basically creating a duplicate of the price thats is being updated, and set the original active as false)

Example:

resource "stripe_product" "test" {
  name = "Test"
}

resource "stripe_price" "test_price" {
  product     = stripe_product.test.id
  currency    = "usd"
  unit_amount = 100
  billing_scheme = "per_unit"
}

Then I update the price to 200

resource "stripe_price" "test_price" {
  product     = stripe_product.test.id
  currency    = "usd"
  unit_amount = 200
  billing_scheme = "per_unit"
}

Terraform plan looks good:

Terraform will perform the following actions:

  # stripe_price.test_price3 must be replaced
-/+ resource "stripe_price" "test_price" {
        active              = true
        billing_scheme      = "per_unit"
        currency            = "usd"
      ~ id                  = "price_1L3QzvGSY3yttFEYXbw4aRbB" -> (known after apply)
      - metadata            = {} -> null
        product             = "prod_Lkwn9obUtoxp2j"
      - tax_behaviour       = "unspecified" -> null
        transfer_lookup_key = false
      ~ type                = "one_time" -> (known after apply)
      ~ unit_amount         = 100 -> 200 # forces replacement
    }

Plan: 1 to add, 0 to change, 1 to destroy.
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

This results in a new 200 price, while the 100 one is kept active. (View screenshot below)

Screen Shot 2022-05-25 at 4 16 16 PM

What I believe should happen, is that the 100 price entry should be archived (set active status to false).

Free price (`unit_price` -1) is not idempotence

Hello,
I found a bug about free pricing, and would like to report it.

How to reproduce

  1. Create a price resource with free price. Set unit_amount to -1.

like this;

resource "stripe_price" "free_price" {
  product        = stripe_product.example.id
  currency       = "usd"
  billing_scheme = "per_unit"
  unit_amount    = -1
  tax_behaviour  = "unspecified"
}
  1. Do terraform apply.

  2. Do terraform plan.

I expected to be No changes., but it actually was replaced.

Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # stripe_price.example must be replaced
-/+ resource "stripe_price" "free_price" {
      ~ id                  = "price_1MjHlDAoExos3Ym4w6AKoNw3" -> (known after apply)
      - metadata            = {} -> null
      ~ type                = "one_time" -> (known after apply)
      ~ unit_amount         = 0 -> -1 # forces replacement
        # (6 unchanged attributes hidden)
    }

Workaround

Set unit_amount to 0 after apply, terraform plan will be No Changes.

Appendix

I reffered:

Versions:

Terraform v1.3.9
on darwin_arm64
+ provider registry.terraform.io/lukasaron/stripe v1.6.3

stripe_portal_configuration doesn't store subscription_update.products

The resource config is:

resource "stripe_product" "base" {
  name      = "Base"
  active    = true
  shippable = false
}

resource "stripe_price" "base" {
  product        = stripe_product.base.id
  currency       = "usd"
  active         = true
  billing_scheme = "per_unit"
  tax_behaviour  = "inclusive"
  unit_amount    = 999

  recurring {
    interval       = "month"
    interval_count = 1
    usage_type     = "licensed"
  }
}

resource "stripe_product" "premium" {
  name      = "premium"
  active    = true
  shippable = false
}

resource "stripe_price" "premium" {
  product        = stripe_product.premium.id
  currency       = "usd"
  active         = true
  billing_scheme = "per_unit"
  tax_behaviour  = "inclusive"
  unit_amount    = 9999


  recurring {
    interval       = "month"
    interval_count = 1
    usage_type     = "licensed"
  }
}

resource "stripe_portal_configuration" "portal_configuration" {
  business_profile {
    headline             = "SITE"
    privacy_policy_url   = "https://domain.com/privacy-policy"
    terms_of_service_url = "https://domain.com/terms-of-use"
  }
  default_return_url = "https://domain.com/"
  features {
customer_update {
      enabled         = true
      allowed_updates = ["tax_id"]
    }
    invoice_history {
      enabled = true
    }
    payment_method_update {
      enabled = true
    }
    subscription_pause {
      enabled = false
    }
    subscription_cancel {
      enabled = true
      cancellation_reason {
        enabled = true
        options = ["too_expensive", "missing_features", "switched_service", "unused", "customer_service", "too_complex", "low_quality", "other"]
      }
      mode               = "at_period_end"
      proration_behavior = "none"
    }
    subscription_update {
      enabled                 = true
      default_allowed_updates = ["price"]
      proration_behavior      = "none"
      products {
        product = stripe_product.base.id
        prices  = [stripe_price.base.id]
      }
      products {
        product = stripe_product.premium.id
        prices  = [stripe_price.premium.id]
      }
    }
  }
}

terraform plan after every apply will have:

resource "stripe_portal_configuration" "portal_configuration" {
        id                 = "bpc_ID"
        # (3 unchanged attributes hidden)

      ~ features {
          ~ subscription_update {
                # (3 unchanged attributes hidden)

              + products {
                  + prices  = [
                      + "price_ID",
                    ]
                  + product = "prod_ID"
                }
              + products {
                  + prices  = [
                      + "price_ID",
                    ]
                  + product = "prod_ID"
                }
            }

            # (5 unchanged blocks hidden)
        }

        # (2 unchanged blocks hidden)
    }

Prices are duplicated when running terraform apply

I've created a product with a price:

resource "stripe_product" "tier_1" {
  name        = "item 1"
  unit_label  = "week"
}


resource "stripe_price" "tier_1" {
  product        = stripe_product.tier_1.id
  currency       = "aud"
  billing_scheme = "per_unit"
  unit_amount    = "10"

  recurring {
    interval       = "week"
    interval_count = 1
  }
}

When I run terraform apply, the plan shows that stripe_price.tier_1 must be replaced:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # stripe_price.tier_1 must be replaced
-/+ resource "stripe_price" "tier_1" {
      ~ id                  = "<sensitive>" -> (known after apply)
      - metadata            = {} -> null
      - tax_behaviour       = "unspecified" -> null
      ~ type                = "recurring" -> (known after apply)
      - unit_amount_decimal = 10 -> null # forces replacement
        # (6 unchanged attributes hidden)

      ~ recurring {
            # (3 unchanged attributes hidden)
        }
    }

The original price resource isn't deleted but a new one is created.

image

It is impossible to create ZeroPrice Tier in PriceResource.

I chose this repository out of several StripeProvider repositories because it is the most recently maintained and well documented. Thank you for the development!!

By the way, I noticed that I can't set ZeroPrice in the PriceObject tier settings.

For example, in someone else's Provider, the ! = nil condition, but

This product is ! = 0 condition for this product.

I noticed this when I tried to create a TierPrice where less than 100 users are free and 101 users are paid, but I couldn't create it with Terraform.

Proposal.
Would you like to modify it to accept zero-price?

Metadata entries not removed

I noticed that metadata entries are only added or the value updated, but not removed or key updated.

For example if I add a metadata field to a resource (I tested this on price)

  metadata = {
    foo = "bar"
  }

Then I change it to

  metadata = {
    bar = "foo"
  }

I end up with foo and bar as metadata keys with their respective values.
My expectation is that the foo key should have been removed.

Screen Shot 2022-06-15 at 4 34 03 PM

I have resolved this by setting foo = "" and running an apply, then removing from the terraform resource declaration, but I think we could resolve this better on the provider. This is necessary otherwise the terraform plan always picks this up as a pending change when comparing to source.

I believe that the fix is to send to stripe the value of the keys to be removed as an empty string.

Recurring price without interval_count will always show change

If you have a price with a recurring block but do not set the interval_count it will always show in a plan as being changed to null.

This is because when it is set there is no default value but when it is read from the stripe API there always is a value, which then gets written into the state.

429 Rate Limits

Context: I create 63 subscription products with 2 prices each, and hit the HTTP 429 wall.

Error: {"code":"rate_limit","doc_url":"https://stripe.com/docs/error-codes/rate-limit","status":429,"message":"Testmode request rate limit exceeded, the rate limits in testmode are lower than livemode. You can learn more about rate limits here https://stripe.com/docs/rate-limits.","type":"invalid_request_error"}
โ”‚
โ”‚ with stripe_product.local_template["abp"],
โ”‚ on stripe.tf line 91, in resource "stripe_product" "local_template":
โ”‚ 91: resource "stripe_product" "local_template" {

More context here: https://stripe.com/docs/error-codes/rate-limit

Running a large volume of closely-spaced requests can lead to rate limiting. Often this is part of an analytical or migration operation. When engaging in these activities, you should try to control the request rate on the client side (see Handling limiting gracefully).

Cheers, and keep up the good work.

stripe_portal_configuration issue on 1.6.3 version

After upgrade from 1.6.0 to 1.6.3 I had this error:

โ”‚ Error: business_profile: '': source data must be an array or slice, got struct
โ”‚
โ”‚   with stripe_portal_configuration.portal_configuration,
โ”‚   on 12_stripe.tf line 21, in resource "stripe_portal_configuration" "portal_configuration":
โ”‚   21: resource "stripe_portal_configuration" "portal_configuration" {
โ”‚
โ•ต
โ•ท
โ”‚ Error: features: '': source data must be an array or slice, got struct
โ”‚
โ”‚   with stripe_portal_configuration.portal_configuration,
โ”‚   on 12_stripe.tf line 21, in resource "stripe_portal_configuration" "portal_configuration":
โ”‚   21: resource "stripe_portal_configuration" "portal_configuration" {
โ”‚
โ•ต

The resource config is:

resource "stripe_portal_configuration" "portal_configuration" {
  business_profile {
    privacy_policy_url   = "https://${local.domain_landing}/privacy"
    terms_of_service_url = "https://${local.domain_landing}/terms"
  }
  default_return_url = "http://${local.domain_app}/"
  features {
    customer_update {
      enabled         = true
      allowed_updates = ["email", "address"]
    }
    invoice_history {
      enabled = false
    }
    payment_method_update {
      enabled = true
    }
  }
}

Versions:
Terraform v1.3.9
on darwin_arm64

  • provider registry.terraform.io/hashicorp/google v4.55.0
  • provider registry.terraform.io/hashicorp/google-beta v4.55.0
  • provider registry.terraform.io/hashicorp/random v3.4.3
  • provider registry.terraform.io/integrations/github v5.18.0
  • provider registry.terraform.io/lukasaron/stripe v1.6.0
  • provider registry.terraform.io/trois-six/sendgrid v0.2.1

Promotion code expitres_at sync

When I run terraform plan I get this change:

# module.account2_resources.stripe_promotion_code.promo_XX must be replaced
-/+ resource "stripe_promotion_code" "promo_XX" {
      - expires_at      = "1970-01-01T00:00:00Z" -> null # forces replacement
      ~ id              = "promo_XX" -> (known after apply)
        # (5 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

1970-01-01T00:00:00Z is 0 timestamp!

Create webhook with "connect" endpoint type

When you create a webhook on Stripe's website, you are given an option that says "Listen to events on connected accounts". Checking this option will change the endpoint type. Does the stripe_webhook_endpoint resource support this option? I couldn't see an argument in the docs that looked like it would fit.

Unable to remove a product when it has prices

Error: {"status":400,"message":"This product cannot be deleted because it has one or more user-created prices.","request_id":"req_...","request_log_url":"https://dashboard.stripe.com/test/logs/req_...?t=1705116524","type":"invalid_request_error"}
โ”‚

This provider already archives prices when deleted from state. Is it possible to modify the provider so that when a product is deleted, if it has prices, the product will be archived instead of deleted?

Associate a default Price for a Product

There doesn't seem to be a way to associate a default_price to a Product.

I assume this is because it's not possible to do it at creation of the Product (Price depends on the creation of the Product). One idea would be to model it like an "attachment", akin to aws_iam_user_policy_attachment which can happen after both the Product and Price exist.

As a workaround I'm using hashicorp/http to send the Product update request manually.

data "http" "stripe_api_set_default_price" {
  url = "https://api.stripe.com/v1/products/${stripe_product.my_product.id}"
  method = "POST"
  request_headers = {
    Accept = "application/json"
    "Content-Type" = "application/x-www-form-urlencoded"
    Authorization = sensitive("Bearer ${var.api_key}")
  }

  request_body = "default_price=${stripe_price.my_price.id}"

  lifecycle {
    postcondition {
      condition     = contains([200, 201, 204], self.status_code)
      error_message = "Stripe default price POST request returned invalid status code"
    }
  }

  depends_on = [stripe_price.my_price]
}

API_KEY is not read when the provider has an alias

Hi, we noticed a bug in our repository that if you alias your stripe provider like this:

provider "stripe" {
  alias   = "stripe_account_1"
  api_key = var.stripe_account_1_api_key
}

it will not read out the api_key property correctly. It will therefore ask you for it in the manual prompt and fail in CI/CD. With the env var STRIPE_API_KEY it works.

"An entry in the tiers array is missing an amount."

The error in the title appears when following the example of tiers in the terraform provider documentation of the resource stripe_price

Workaround is using flat_amount_decimal attribute and removing a for free tier

How to specify Product ID?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.