README ¶
Terraform Stripe Provider
This terraform provider allows to perform Create ,Read ,Update, Delete and Import stripe User(s).
Requirements
Setup Stripe Account
❗ [IMPORTANT] : This provider can be successfully tested on any Stripe developer account.
- Create a Stripe account. (https://dashboard.stripe.com/register)
- Sign in to the stripe account (https://dashboard.stripe.com/login)
- Go to the Get your API keys.
This app will provide us with the Secret Key which will be needed to configure our provider and make request.
Initialise Stripe Provider in local machine
- Clone the repository to $GOPATH/src/github.com/stripe/terraform-provider-stripe
- Add the Refresh Secret Key generted in Stripe App to respective fields in
main.tf
- Run the following command :
go mod init terraform-provider-stripe
go mod tidy
- Run
go mod vendor
to create a vendor directory that contains all the provider's dependencies.
Installation
- Run the following command to create a vendor subdirectory which will comprise of all provider dependencies.
~/.terraform.d/plugins/${host_name}/${namespace}/${type}/${version}/${target}
Command:
mkdir -p ~/.terraform.d/plugins/hashicorp.com/edu/stripe/0.2.0/[OS_ARCH]
For eg. mkdir -p ~/.terraform.d/plugins/hashicorp.com/edu/stripe/0.2.0/windows_amd64
- Run
go build -o terraform-provider-stripe.exe
. This will save the binary (.exe
) file in the main/root directory. - Run this command to move this binary file to appropriate location.
move terraform-provider-stripe.exe %APPDATA%\terraform.d\plugins\hashicorp.com\edu\stripe\0.2.0\[OS_ARCH]
Otherwise you can manually move the file from current directory to destination directory.
[OR]
- Download required binaries
- move binary
~/.terraform.d/plugins/[architecture name]/
Run the Terraform provider
Create User
- Add the user email, first name, last name in the respective field in
main.tf
- Initialize the terraform provider
terraform init
- Check the changes applicable using
terraform plan
and apply usingterraform apply
- You will see that a user has been successfully created.
Update the user
Update the data of the user in the main.tf
file and apply using terraform apply
Read the User Data
Add data and output blocks in the main.tf
file and run terraform plan
to read user data.
Delete the user
Delete the resource block of the particular user from main.tf
file and run terraform apply
.
Import a User Data
- Write manually a resource configuration block for the User in
main.tf
, to which the imported object will be mapped. - Run the command
terraform import stripe_user.user1 [EMAIL_ID]
- Check for the attributes in the
.tfstate
file and fill them accordingly in resource block.
Testing the Provider
- Navigate to the test file directory.
- Run command
go test
. This command will give combined test result for the execution or errors if any failure occur. - If you want to see test result of each test function individually while running test in a single go, run command
go test -v
- To check test cover run
go test -cover
Example Usage
terraform {
required_providers{
stripe ={
version ="0.2"
source = "hashicorp.com/edu/stripe"
}
}
}
provider "stripe" {
token = "[Secret Key]"
}
data "stripe_user" "user" {
email = "[EMAIL]"
}
output "user" {
value = data.stripe_user.user
}
resource "stripe_user" "user1" {
email = "[EMAIL]"
first_name = "[FIRST NAME]"
last_name = "[LAST_NAME]"
}
Click to show internal directories.
Click to hide internal directories.