• Stars
    star
    242
  • Rank 167,018 (Top 4 %)
  • Language
    Go
  • License
    Mozilla Public Li...
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Terraform Provider for Stripe

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)

Since Terraform 13 and the Terraform Registry, no need to download a release or compile this on your own machine (unless you really want to.) Just jump to the Basic Usage section and get going!

Requirements

  • Terraform 0.11.x to 0.13.x
  • Go 1.8 to 1.14 (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
terraform {
  required_providers {
    stripe = {
      source = "franckverrot/stripe"
      version = "1.8.0"
    }
  }
}

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
  • Prices

    • active (Default: true)
    • currency
    • metadata (map)
    • nickname
    • product
    • recurring
    • unit_amount
    • billing_scheme
    • unit_amount_decimal
    • tiers (Stripe API doesn't provide the API to update this at the moment, so the deletion should be done via dashboard page)
    • tiers mode
  • 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
  • Customer Portal

    • business_profile
      • headline
      • privacy_policy_url
      • terms_of_service_url
    • features
      • customer_update
        • allowed_updates
      • invoice_history
      • payment_method_update
      • subscription_cancel
      • subscription_pause
      • subscription_update
    • default_return_url
    • metadata

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-2020

More Repositories

1

activevalidators

Collection of ActiveModel/ActiveRecord validators
Ruby
306
star
2

holycorn

Community version of the PostgreSQL multi-purpose Ruby Foreign Data Wrapper
C
167
star
3

EmulationResources

Collection of resources for emulator developers
HTML
91
star
4

no_querying_views

No more querying views in your Rails apps
Ruby
60
star
5

git_fdw

PostgreSQL Git Foreign Data Wrapper
C
47
star
6

clamav-client

ClamAV::Client connects to a Clam Anti-Virus clam daemon and send commands
Ruby
40
star
7

trek

Trek is a CLI/ncurses explorer for HashiCorp Nomad clusters.
Go
33
star
8

blake2

BLAKE2 - fast secure hashing - for Ruby
Ruby
28
star
9

mruby-r

mruby-r: Use (m)Ruby for returning data to R
Ruby
26
star
10

fruby

A French version of Ruby (based on mruby)
C
19
star
11

rb_import

rb_import: ES6 `import`/Node's `require`, for Ruby.
Ruby
19
star
12

codes-bic-france

Code BIC des Banques Françaises
13
star
13

arnoldc.rb

The ugliest implementation of the Arnold Schwarzenegger based programming language, in Ruby.
Ruby
10
star
14

terraform-provider-homebrew

Terraform provider for Homebrew
Go
8
star
15

ers

ers - ERb-like templating engine for Rust
Rust
8
star
16

yamlsh

Interactive REPL for authoring YAML files
Ruby
8
star
17

git-mine-commit

Mine your git commit hash (SHA1) because you know... YOLO
Shell
7
star
18

tictactoe-elm

Tic Tac Toe with Elm
JavaScript
7
star
19

paybox

Paybox's payment gateway -- UNMAINTAINED
Ruby
7
star
20

awesome-rfcs

Curated list of RFCs / Community Processes
6
star
21

isolate

Prevent processes from accessing unauthorized files
C
6
star
22

gendarme

Gendarme checks for preconditions and postrelations on the methods you want it to monitor.
Ruby
6
star
23

wtf

Secret project, sssshhhh
Ruby
5
star
24

namos

🚀 Naming and Synchronization in a Decentralized Computer System 🚀 (Author: David P. Reed)
CSS
5
star
25

tweetnacl

TweetNaCl Ruby C-extension
C
5
star
26

OpenNICSwitcher

OSX app that makes using an OpenNIC DNS server a no-brainer (under development)
Ruby
4
star
27

adversarial-ml

Adversarial Machine Learning
3
star
28

bmmlexporter

Simple exporter from Bmml files
Ruby
3
star
29

Reader.elm

RSS front-end a-la Google Reader created with Elm (elm-lang.org)
Elm
3
star
30

postgresql-performance-subquery-vs-join

R
2
star
31

game-of-life-in-elm

Game of Life in Elm
HTML
2
star
32

raven

Consul-based Control Plane for Envoy Proxy
Go
2
star
33

dependency_revealer

Extract dependencies info from a Gemfile (and a Gemfile.lock)
Ruby
2
star
34

gem-license-check

License reporter and checker for your Ruby projects
Ruby
2
star
35

TCL

Des données, des transports en communs lyonnais.
JavaScript
1
star
36

golo-hs

Playground, parsing Golo with Haskell's attoparsec
Haskell
1
star
37

TaskRunner

Experimental Task Runner in Haskell
Haskell
1
star
38

fr-lang

Functional Ruby Programming Language Experiment
Ruby
1
star
39

dalek

dalek is an experimental (and unfinished) campfire bot that can self-upgrade, watch the video for more information
Ruby
1
star
40

ar2json

ActiveRecord extension that uses the database to build a record's JSON representation
Ruby
1
star
41

live-note

Live-Note
Python
1
star
42

Reader.ex

REST API for Reader.elm
Elixir
1
star
43

dotfiles

Vim Script
1
star
44

CodeBeautifier

This Rails plugin modifies the content that goes out your Rails application and format it nicely.
Ruby
1
star
45

gemtalker

Talk to Gemcutter's API using XMPP/Google Talk [Invite [email protected] to chat in GTalk]
Python
1
star
46

exportable

exportable will help you export arrays of objects and reuse the export definitions across your classes
Ruby
1
star
47

chrust

Changes the current Rust
Shell
1
star
48

hudson-git-flow

discover new github topic/feature branches and add as Hudson jobs
Ruby
1
star
49

heroku-cedar-examples

Ruby, NodeJS and Clojure app examples to run on Heroku's Cedar stack
Shell
1
star
50

pivotbot

A Pivotal Tracker Command Line Tool
Haskell
1
star
51

lmftfy

Let Me Fork That For You, the best way to get your patch applied to your favorite project
Ruby
1
star
52

autostopper

Simple script that stops your running AWS EC2 instances.
Ruby
1
star
53

jruby-experiments

Some personal JRuby experiments
Ruby
1
star
54

Blink-FPGA-LED

VHDL
1
star