GithubHelp home page GithubHelp logo

jchorl / terraform-provider-stripe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from franckverrot/terraform-provider-stripe

0.0 1.0 0.0 6.13 MB

A Terraform Provider for Stripe

License: Mozilla Public License 2.0

Makefile 1.17% Go 91.12% HCL 7.28% Shell 0.43%

terraform-provider-stripe's Introduction

Terraform Stripe Provider

This provider enables Stripe merchants to manage certain parts of their Stripe infrastructure—products, plans, webhook endpoints—via Terraform.

Example use cases

  • Create and update resources in a repeatable manner
  • Clone resources across multiple Stripe accounts (e.g. different locales or brands)

Requirements

  • Terraform 0.11.x to 0.12.x
  • Go 1.8 to 1.12 (to build the provider plugin)

Building The Provider

Clone repository anywhere:

$ git clone https://github.com/franckverrot/terraform-provider-stripe.git

Enter the provider directory and build the provider

$ cd terraform-provider-stripe
$ make compile

Or alternatively, to install it as a plugin, run

$ cd terraform-provider-stripe
$ make install

Using the provider

If you're building the provider, follow the instructions to install it as a plugin. After placing it into your plugins directory, run terraform init to initialize it.

Basic Usage

Set an environment variable, TF_VAR_stripe_api_token to store your Stripe API token. This helps ensure you do not accidentally commit this sensitive token to your repository.

export TF_VAR_stripe_api_token=<your token>

Your token is now accessible in your Terraform configuration as var.stripe_api_token, and can be used to configure the provider.

The example below demonstrates the following operations:

  • create a product
  • create a plan for that product
  • create a webhook endpoint for a few events
provider "stripe" {
  # NOTE: This is populated from the `TF_VAR_stripe_api_token` environment variable.
  api_token = "${var.stripe_api_token}"
}

resource "stripe_product" "my_product" {
  name = "My Product"
  type = "service"
}

resource "stripe_plan" "my_product_plan1" {
  product  = "${stripe_product.my_product.id}"
  amount   = 12345
  interval = "month"                           # Options: day week month year
  currency = "usd"
}

resource "stripe_webhook_endpoint" "my_endpoint" {
  url = "https://mydomain.example.com/webhook"

  enabled_events = [
    "charge.succeeded",
    "charge.failed",
    "source.chargeable",
  ]
}

resource "stripe_coupon" "mlk_day_coupon_25pc_off" {
  code     = "MLK_DAY"
  name     = "King Sales Event"
  duration = "once"

  amount_off = 4200
  currency   = "usd" # lowercase

  metadata = {
    mlk   = "<3"
    sales = "yes"
  }

  max_redemptions = 1024
  redeem_by       = "2019-09-02T12:34:56-08:00" # RFC3339, in the future
}

Supported resources

  • Products
    • name
    • type
    • active (Default: true)
    • attributes (list)
    • metadata (map)
    • statement descriptor
    • unit label
  • Plans
    • active (Default: true)
    • aggregate usage
    • amount
    • amount_decimal
    • billing scheme (Default: per_unit)
    • currency
    • interval
    • interval_count (Default: 1)
    • metadata (map)
    • nickname
    • product
    • tiers
    • tiers mode
    • transform_usage
    • trial period days
    • usage type (Default: licensed)
  • Webhook Endpoints
    • url
    • enabled_events (list)
    • connect
    • Computed:
      • secret
  • Coupons
    • code (aka id)
    • name
    • amount off
      • currency
    • percent off
    • duration
      • duration_in_months
    • max redemptions
    • metadata
    • redeem by (should be RC3339-compliant)
    • Computed:
      • valid
      • created
      • livemode
      • times redeemed
  • TaxRates
    • code (aka id)
    • active
    • description
    • display_name
    • inclusive
    • jurisdiction
    • DELETE API (Stripe API doesn't provide the API at the moment, so the deletion should be done via dashboard page)
    • Computed:
      • created
      • livemode

Importing existing resources

Scenario: you create something manually and would like to start managing it with Terraform instead.

This provider support a straightforward/naive import procedure, here's how you could do it for a coupon.

First, import the resource:

$ terraform import stripe_coupon.mlk_day_coupon_25pc_off MLK_DAY

...
Before importing this resource, please create its configuration in the root module. For example:

resource "stripe_coupon" "mlk_day_coupon_25pc_off" {
  # (resource arguments)
}

Then after adding these lines to your Terraform file, a plan should result in:

$ terraform plan

...
-/+ stripe_coupon.mlk_day_coupon_25pc_off (new resource required)
      id:              "MLK_DAY" => <computed> (forces new resource)
      amount_off:      "4200" => "4200"
      code:            "" => "MLK_DAY"
      created:         "" => <computed>
      currency:        "usd" => "usd"
      duration:        "once" => "once"
      livemode:        "false" => <computed>
      max_redemptions: "1024" => "1024"
      metadata.%:      "2" => "2"
      metadata.mlk:    "<3" => "<3"
      metadata.sales:  "yes" => "yes"
      name:            "King Sales Event" => "King Sales Event"
      redeem_by:       "" => "2019-09-02T12:34:56-08:00" (forces new resource)
      times_redeemed:  "0" => <computed>
      valid:           "true" => <computed>

Some updates might require replacing existing resources with new ones.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.8+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

To compile the provider, run make. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make bin
...
$ $GOPATH/bin/terraform-provider-stripe
...

License

Mozilla Public License Version 2.0 – Franck Verrot – Copyright 2018

terraform-provider-stripe's People

Contributors

franckverrot avatar florisvdg avatar clintonb-stripe avatar kabesan avatar oleg-codaio avatar magni- avatar alephyud avatar bradrydzewski avatar mdreem avatar till avatar allanlegalstart avatar drselump14 avatar

Watchers

James Cloos avatar

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.