|
1 | | -# Terraform Provider Scaffolding (Terraform Plugin Framework) |
| 1 | +# Terraform Provider for PostHog |
2 | 2 |
|
3 | | -_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework). The template repository built on the [Terraform Plugin SDK](https://github.com/hashicorp/terraform-plugin-sdk) can be found at [terraform-provider-scaffolding](https://github.com/hashicorp/terraform-provider-scaffolding). See [Which SDK Should I Use?](https://developer.hashicorp.com/terraform/plugin/framework-benefits) in the Terraform documentation for additional information._ |
| 3 | +Terraform provider for managing [PostHog](https://posthog.com) resources. |
4 | 4 |
|
5 | | -This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing: |
| 5 | +## Documentation |
6 | 6 |
|
7 | | -- A resource and a data source (`internal/provider/`), |
8 | | -- Examples (`examples/`) and generated documentation (`docs/`), |
9 | | -- Miscellaneous meta files. |
10 | | - |
11 | | -These files contain boilerplate code that you will need to edit to create your own Terraform provider. Tutorials for creating Terraform providers can be found on the [HashiCorp Developer](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework) platform. _Terraform Plugin Framework specific guides are titled accordingly._ |
12 | | - |
13 | | -Please see the [GitHub template repository documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for how to create a new repository from this template on GitHub. |
14 | | - |
15 | | -Once you've written your provider, you'll want to [publish it on the Terraform Registry](https://developer.hashicorp.com/terraform/registry/providers/publishing) so that others can use it. |
| 7 | +For usage documentation and supported resources, see the [Terraform Registry](https://registry.terraform.io/providers/posthog/posthog/latest/docs). |
16 | 8 |
|
17 | 9 | ## Requirements |
18 | 10 |
|
19 | 11 | - [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.0 |
20 | 12 | - [Go](https://golang.org/doc/install) >= 1.24 |
21 | 13 |
|
22 | | -## Building The Provider |
23 | | - |
24 | | -1. Clone the repository |
25 | | -1. Enter the repository directory |
26 | | -1. Build the provider using the Go `install` command: |
| 14 | +## Building the Provider |
27 | 15 |
|
28 | 16 | ```shell |
29 | 17 | go install |
30 | 18 | ``` |
31 | 19 |
|
32 | | -## Adding Dependencies |
| 20 | +## Local Development |
| 21 | + |
| 22 | +The `playground/` directory lets you test provider changes locally without publishing. |
| 23 | + |
| 24 | +### Setup |
33 | 25 |
|
34 | | -This provider uses [Go modules](https://github.com/golang/go/wiki/Modules). |
35 | | -Please see the Go documentation for the most up to date information about using Go modules. |
| 26 | +1. Create your Terraform config in `playground/` (e.g., `playground/demo.tf`) |
36 | 27 |
|
37 | | -To add a new dependency `github.com/author/dependency` to your Terraform provider: |
| 28 | +2. Build the provider and run terraform: |
38 | 29 |
|
39 | 30 | ```shell |
40 | | -go get github.com/author/dependency |
41 | | -go mod tidy |
42 | | -``` |
| 31 | +# Plan changes |
| 32 | +make playground-plan |
43 | 33 |
|
44 | | -Then commit the changes to `go.mod` and `go.sum`. |
45 | | - |
46 | | -## Using the provider |
47 | | - |
48 | | -Configure the provider with your PostHog host, personal API key, and default project/environment ID. All resources inherit this project scope. |
49 | | - |
50 | | -```hcl |
51 | | -provider "posthog" { |
52 | | - host = "https://us.posthog.com" |
53 | | - api_key = var.posthog_api_key |
54 | | - project_id = var.posthog_project_id |
55 | | -} |
56 | | -
|
57 | | -resource "posthog_insight" "weekly_signups" { |
58 | | - name = "Weekly signups" |
59 | | - description = "Tracks sign up volume per week" |
60 | | - derived_name = "Weekly signups" |
61 | | -
|
62 | | - query_json = jsonencode({ |
63 | | - kind = "InsightVizNode" |
64 | | - source = { |
65 | | - kind = "TrendsQuery" |
66 | | - series = [{ |
67 | | - kind= "EventsNode" |
68 | | - name = "$pageview" |
69 | | - event = "$pageview" |
70 | | - math= "total" |
71 | | - }] |
72 | | - version = 2 |
73 | | - trendsFilter = {} |
74 | | - } |
75 | | - }) |
76 | | - tags = ["managed-by:terraform"] |
77 | | - create_in_folder = "Unfiled/Insights" |
78 | | -} |
| 34 | +# Apply changes |
| 35 | +make playground-apply |
79 | 36 | ``` |
80 | 37 |
|
81 | | -To import an existing insight, run: |
| 38 | +This builds the provider binary and configures Terraform to use your local build via `dev_overrides` - no `terraform init` required. |
| 39 | + |
| 40 | +### Manual Setup |
| 41 | + |
| 42 | +If you prefer to test outside the playground directory: |
82 | 43 |
|
83 | 44 | ```shell |
84 | | -terraform import posthog_insight.weekly_signups "<insight_id>" |
| 45 | +# Build the provider |
| 46 | +make playground-binary |
| 47 | + |
| 48 | +# Point Terraform to your local build |
| 49 | +export TF_CLI_CONFIG_FILE=/path/to/terraform-provider-posthog/playground/terraformrc |
| 50 | + |
| 51 | +# Run terraform commands in any directory |
| 52 | +terraform plan |
| 53 | +terraform apply |
85 | 54 | ``` |
86 | 55 |
|
87 | | -## Developing the Provider |
| 56 | +### Cleanup |
88 | 57 |
|
89 | | -If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above). |
| 58 | +```shell |
| 59 | +make playground-clean |
| 60 | +``` |
| 61 | + |
| 62 | +## Testing |
90 | 63 |
|
91 | | -To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. |
| 64 | +### Unit Tests |
92 | 65 |
|
93 | | -To generate or update documentation, run `make generate`. |
| 66 | +```shell |
| 67 | +go test ./... |
| 68 | +``` |
94 | 69 |
|
95 | | -In order to run the full suite of Acceptance tests, run `make testacc`. |
| 70 | +### Acceptance Tests |
96 | 71 |
|
97 | | -*Note:* Acceptance tests create real resources, and often cost money to run. |
| 72 | +Acceptance tests run against a real PostHog instance and create actual resources: |
98 | 73 |
|
99 | 74 | ```shell |
| 75 | +export POSTHOG_API_KEY="your-api-key" |
| 76 | +export POSTHOG_PROJECT_ID="12345" |
| 77 | +export POSTHOG_HOST="https://us.posthog.com" |
| 78 | + |
100 | 79 | make testacc |
101 | 80 | ``` |
102 | 81 |
|
| 82 | +## Generating Documentation |
| 83 | + |
| 84 | +```shell |
| 85 | +make generate |
| 86 | +``` |
| 87 | + |
103 | 88 | ## Releasing |
104 | 89 |
|
105 | | -Releases are automated via GoReleaser when a signed tag is pushed. The Makefile provides convenience targets for creating releases: |
| 90 | +Releases are automated via GoReleaser when a signed tag is pushed. The Makefile provides convenience targets: |
106 | 91 |
|
107 | 92 | ```shell |
108 | 93 | # Alpha releases (pre-release, for early testing) |
109 | | -make release-alpha VERSION=0.1.0 NUM=1 # creates v0.1.0-alpha.1 |
| 94 | +make release-alpha VERSION=1.0.0 NUM=1 # creates v1.0.0-alpha.1 |
110 | 95 |
|
111 | 96 | # Beta releases (pre-release, feature complete) |
112 | | -make release-beta VERSION=0.1.0 NUM=1 # creates v0.1.0-beta.1 |
| 97 | +make release-beta VERSION=1.0.0 NUM=1 # creates v1.0.0-beta.1 |
113 | 98 |
|
114 | 99 | # Stable releases |
115 | | -make release VERSION=0.1.0 # creates v0.1.0 |
| 100 | +make release VERSION=1.0.0 # creates v1.0.0 |
116 | 101 | ``` |
117 | 102 |
|
118 | 103 | **Requirements:** |
119 | 104 | - GPG key configured for signing (`git tag -s`) |
120 | 105 | - GPG key added to your GitHub account (for the "Verified" badge) |
121 | 106 |
|
122 | | -Pre-release versions (alpha, beta) won't be installed by default — users must explicitly pin to them in their Terraform configuration. |
| 107 | +Pre-release versions (alpha, beta) won't be installed by default - users must explicitly pin to them in their Terraform configuration. |
| 108 | + |
| 109 | +## License |
| 110 | + |
| 111 | +See [LICENSE](LICENSE). |
0 commit comments