-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathmain.tf
More file actions
103 lines (87 loc) · 2.27 KB
/
main.tf
File metadata and controls
103 lines (87 loc) · 2.27 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 = ""
}
# Products
resource "stripe_product" "basic" {
name = "Basic"
description = "Basic plan"
}
resource "stripe_product" "premium" {
name = "Premium"
description = "Premium plan"
}
# Prices - Monthly recurring subscriptions with lookup_keys
resource "stripe_price" "basic_monthly" {
product = stripe_product.basic.id
currency = "usd"
unit_amount = 1800
lookup_key = "sample_basic"
recurring {
interval = "month"
interval_count = 1
trial_period_days = 0
usage_type = "licensed"
}
}
resource "stripe_price" "premium_monthly" {
product = stripe_product.premium.id
currency = "usd"
unit_amount = 1800
lookup_key = "sample_premium"
recurring {
interval = "month"
interval_count = 1
trial_period_days = 0
usage_type = "licensed"
}
}
# 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 = [
"invoice.payment_succeeded",
"invoice.payment_failed",
"invoice.finalized",
"customer.subscription.deleted",
]
}
# Outputs
output "basic_product_id" {
description = "The ID of the Basic product"
value = stripe_product.basic.id
}
output "premium_product_id" {
description = "The ID of the Premium product"
value = stripe_product.premium.id
}
output "basic_price_id" {
description = "The ID of the Basic price ($18/month)"
value = stripe_price.basic_monthly.id
}
output "premium_price_id" {
description = "The ID of the Premium price ($18/month)"
value = stripe_price.premium_monthly.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
}