forked from stripe-samples/accept-a-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
65 lines (55 loc) · 1.53 KB
/
Copy pathmain.tf
File metadata and controls
65 lines (55 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
terraform {
required_providers {
stripe = {
source = "stripe/stripe"
version = "0.1.3"
}
}
}
variable "stripe_api_key" {
description = "Stripe API key (set via TF_VAR_stripe_api_key env var)"
type = string
sensitive = true
}
provider "stripe" {
api_key = var.stripe_api_key
}
variable "webhook_url" {
description = "URL for Stripe webhook endpoint (e.g., https://your-server.com/webhook)"
type = string
default = ""
}
# Product
resource "stripe_product" "sample_product" {
name = "Sample Product"
description = "A sample product for accepting payments"
}
# Price - $10.00 USD one-time payment
resource "stripe_price" "sample_price" {
product = stripe_product.sample_product.id
currency = "usd"
unit_amount = 1000
}
# Webhook endpoint (only created if webhook_url is provided)
resource "stripe_webhook_endpoint" "webhook" {
count = var.webhook_url != "" ? 1 : 0
url = var.webhook_url
enabled_events = [
"checkout.session.completed",
"payment_intent.succeeded",
"payment_intent.payment_failed",
]
}
# Outputs
output "product_id" {
description = "The ID of the created product"
value = stripe_product.sample_product.id
}
output "price_id" {
description = "The ID of the created price (use this for PRICE env var)"
value = stripe_price.sample_price.id
}
output "webhook_endpoint_id" {
description = "The ID of the webhook endpoint (if created)"
value = var.webhook_url != "" ? stripe_webhook_endpoint.webhook[0].id : null
}