Skip to content

Commit

Permalink
feat: Implement codegen for source verification providers (#100)
Browse files Browse the repository at this point in the history
* refactor: Implement interface for source verification provider

* chore: Use generated code

* refactor: Move generated code into its own package

* feat: Source verification codegen

* chore: Generate source verifications

* chore: Resolve lint errors

* chore: Use `/latest` OpenAPI spec route

Co-authored-by: Phil Leggetter <[email protected]>

* chore: Update Go SDK v0.5.0 and generate all supported verification

* feat: Add support for JSON verification for backward compatibility

* chore: Fix lint issue

* build: Separate TF docs & source verification codegen generate commands (#99)

* chore(deps): bump goreleaser/goreleaser-action from 5.1.0 to 6.0.0 (#69)

Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 5.1.0 to 6.0.0.
- [Release notes](https://github.com/goreleaser/goreleaser-action/releases)
- [Commits](goreleaser/goreleaser-action@5742e2a...286f3b1)

---
updated-dependencies:
- dependency-name: goreleaser/goreleaser-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ci: Separate codegen & tfdocs generate commands

* chore: add pre-commit git hook for docs generation

* fix: linting (#105)

* chore: add pre-commit git hook for docs generation (#103)

* chore(deps): bump goreleaser/goreleaser-action from 5.1.0 to 6.0.0 (#69)

Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 5.1.0 to 6.0.0.
- [Release notes](https://github.com/goreleaser/goreleaser-action/releases)
- [Commits](goreleaser/goreleaser-action@5742e2a...286f3b1)

---
updated-dependencies:
- dependency-name: goreleaser/goreleaser-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add pre-commit git hook for docs generation

* chore: fix lint

* fix: linting (#105)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: Upgrade SDK v0.6.0 and support SDK max attempts option (#110)

* chore: Upgrade SDK v0.6.0

* feat: Support SDK max retries

* docs: generate

* chore(docs): update API ref link

---------

Co-authored-by: Phil Leggetter <[email protected]>

* chore: generate

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Phil Leggetter <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Phil Leggetter <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 11, 2024
1 parent 730e9e9 commit 3f0bdc0
Show file tree
Hide file tree
Showing 139 changed files with 3,960 additions and 2,065 deletions.
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
hooksPath = .githooks
3 changes: 3 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

make generate-tfdocs
13 changes: 13 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ default: testacc
.PHONY: testacc
testacc:
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

generate:
go generate ./...

generate-codegen:
go generate ./cmd/codegen/...

generate-tfdocs:
go generate ./cmd/tfdocs/...

enable-git-hooks:
git config --local include.path ../.gitconfig
$(warning REMEMBER, YOU MUST HAVE REVIEWED THE CUSTOM HOOKS!)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ resource "hookdeck_connection" "my_connection" {
## Dependencies

This provider uses [Hookdeck API](https://hookdeck.com/docs/api) and [Hookdeck Go SDK](https://github.com/hookdeck/hookdeck-go-sdk) under the hood.

## Development

Enable pre-commit Git hooks to ensure any code changes are reflected in the documentation:

```sh
make enable-git-hooks
```
17 changes: 17 additions & 0 deletions cmd/codegen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"log"
"terraform-provider-hookdeck/internal/codegen"
)

func main() {
if err := codegen.RunCodeGen(); err != nil {
log.Panicln(err)
}
}

// Run "go generate" to generate Hookdeck source verification codes

//go:generate go run .
//go:generate gofmt -w ../../internal/provider/sourceverification/generated
15 changes: 15 additions & 0 deletions cmd/tfdocs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

// Run "go generate" to format example terraform files and generate the docs for the registry/website

// If you do not have terraform installed, you can remove the formatting command, but its suggested to
// ensure the documentation is formatted properly.
//go:generate terraform fmt -recursive ../../examples/

// Run the docs generation tool, check its repository for more information on how it works and how docs
// can be customized.
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-dir ../../

func main() {
// noop
}
66 changes: 56 additions & 10 deletions docs/resources/source_verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ Optional:
- `github` (Attributes) (see [below for nested schema](#nestedatt--verification--github))
- `gitlab` (Attributes) (see [below for nested schema](#nestedatt--verification--gitlab))
- `hmac` (Attributes) (see [below for nested schema](#nestedatt--verification--hmac))
- `hubspot` (Attributes) (see [below for nested schema](#nestedatt--verification--hubspot))
- `json` (String, Sensitive)
- `linear` (Attributes) (see [below for nested schema](#nestedatt--verification--linear))
- `mailchimp` (Attributes) (see [below for nested schema](#nestedatt--verification--mailchimp))
- `mailgun` (Attributes) (see [below for nested schema](#nestedatt--verification--mailgun))
- `nmi` (Attributes) (see [below for nested schema](#nestedatt--verification--nmi))
- `orb` (Attributes) (see [below for nested schema](#nestedatt--verification--orb))
- `oura` (Attributes) (see [below for nested schema](#nestedatt--verification--oura))
- `paddle` (Attributes) (see [below for nested schema](#nestedatt--verification--paddle))
- `paypal` (Attributes) (see [below for nested schema](#nestedatt--verification--paypal))
- `persona` (Attributes) (see [below for nested schema](#nestedatt--verification--persona))
- `pipedrive` (Attributes) (see [below for nested schema](#nestedatt--verification--pipedrive))
- `postmark` (Attributes) (see [below for nested schema](#nestedatt--verification--postmark))
Expand All @@ -80,9 +84,10 @@ Optional:
- `synctera` (Attributes) (see [below for nested schema](#nestedatt--verification--synctera))
- `tebex` (Attributes) (see [below for nested schema](#nestedatt--verification--tebex))
- `telnyx` (Attributes) (see [below for nested schema](#nestedatt--verification--telnyx))
- `threedeye` (Attributes) (see [below for nested schema](#nestedatt--verification--threedeye))
- `three_d_eye` (Attributes) (see [below for nested schema](#nestedatt--verification--three_d_eye))
- `tokenio` (Attributes) (see [below for nested schema](#nestedatt--verification--tokenio))
- `trello` (Attributes) (see [below for nested schema](#nestedatt--verification--trello))
- `twilio` (Attributes) (see [below for nested schema](#nestedatt--verification--twilio))
- `twitch` (Attributes) (see [below for nested schema](#nestedatt--verification--twitch))
- `twitter` (Attributes) (see [below for nested schema](#nestedatt--verification--twitter))
- `typeform` (Attributes) (see [below for nested schema](#nestedatt--verification--typeform))
Expand Down Expand Up @@ -116,7 +121,7 @@ Required:
Required:

- `api_key` (String, Sensitive)
- `header_key` (String)
- `header_key` (String, Sensitive)


<a id="nestedatt--verification--aws_sns"></a>
Expand All @@ -129,7 +134,7 @@ Required:
Required:

- `password` (String, Sensitive)
- `username` (String)
- `username` (String, Sensitive)


<a id="nestedatt--verification--bondsmith"></a>
Expand Down Expand Up @@ -237,9 +242,17 @@ Required:

Required:

- `algorithm` (String)
- `encoding` (String)
- `header_key` (String)
- `algorithm` (String, Sensitive)
- `encoding` (String, Sensitive)
- `header_key` (String, Sensitive)
- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--hubspot"></a>
### Nested Schema for `verification.hubspot`

Required:

- `webhook_secret_key` (String, Sensitive)


Expand All @@ -251,6 +264,14 @@ Required:
- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--mailchimp"></a>
### Nested Schema for `verification.mailchimp`

Required:

- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--mailgun"></a>
### Nested Schema for `verification.mailgun`

Expand Down Expand Up @@ -283,6 +304,22 @@ Required:
- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--paddle"></a>
### Nested Schema for `verification.paddle`

Required:

- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--paypal"></a>
### Nested Schema for `verification.paypal`

Required:

- `webhook_id` (String, Sensitive)


<a id="nestedatt--verification--persona"></a>
### Nested Schema for `verification.persona`

Expand All @@ -296,16 +333,17 @@ Required:

Required:

- `name` (String)
- `password` (String, Sensitive)
- `username` (String, Sensitive)


<a id="nestedatt--verification--postmark"></a>
### Nested Schema for `verification.postmark`

Required:

- `webhook_secret_key` (String, Sensitive)
- `password` (String, Sensitive)
- `username` (String, Sensitive)


<a id="nestedatt--verification--property_finder"></a>
Expand Down Expand Up @@ -444,8 +482,8 @@ Required:
- `public_key` (String, Sensitive)


<a id="nestedatt--verification--threedeye"></a>
### Nested Schema for `verification.threedeye`
<a id="nestedatt--verification--three_d_eye"></a>
### Nested Schema for `verification.three_d_eye`

Required:

Expand All @@ -468,6 +506,14 @@ Required:
- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--twilio"></a>
### Nested Schema for `verification.twilio`

Required:

- `webhook_secret_key` (String, Sensitive)


<a id="nestedatt--verification--twitch"></a>
### Nested Schema for `verification.twitch`

Expand Down
73 changes: 65 additions & 8 deletions examples/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ provider "hookdeck" {
api_key = var.HOOKDECK_API_KEY
}

resource "hookdeck_source" "my_source" {
resource "hookdeck_source" "first_source" {
name = "first_source"
}

resource "hookdeck_source" "second_source" {
name = "my_source"
}

resource "hookdeck_source_verification" "my_authenticated_source" {
source_id = hookdeck_source.my_source.id
resource "hookdeck_source_verification" "named_basic_auth_verification" {
source_id = hookdeck_source.first_source.id
verification = {
basic_auth = {
username = "example-username"
Expand All @@ -32,14 +36,38 @@ resource "hookdeck_source_verification" "my_authenticated_source" {
}
}

resource "hookdeck_destination" "my_destination" {
name = "my_destination"
resource "hookdeck_source_verification" "json_basic_auth_verification" {
source_id = hookdeck_source.second_source.id
verification = {
json = jsonencode({
type = "basic_auth"
configs = {
username = "some-username"
password = "blah-blah-blah"
}
})
}
}

resource "hookdeck_destination" "first_destination" {
name = "first_destination"
url = "https://mock.hookdeck.com"
}

resource "hookdeck_connection" "my_connection" {
source_id = hookdeck_source.my_source.id
destination_id = hookdeck_destination.my_destination.id
resource "hookdeck_destination" "second_destination" {
name = "second_destination"
url = "https://mock.hookdeck.com"
auth_method = {
basic_auth = {
username = "some-username"
password = "blah-blah-blah"
}
}
}

resource "hookdeck_connection" "first_connection" {
source_id = hookdeck_source.first_source.id
destination_id = hookdeck_destination.first_destination.id
rules = [
{
filter_rule = {
Expand All @@ -51,4 +79,33 @@ resource "hookdeck_connection" "my_connection" {
}
}
]
}

resource "hookdeck_connection" "second_connection" {
source_id = hookdeck_source.second_source.id
destination_id = hookdeck_destination.first_destination.id
}

data "hookdeck_source" "manually_created_source" {
id = "src_112rkwa855tb0z"
}

data "hookdeck_destination" "manually_created_destination" {
id = "des_tsrZIbyk0JBB"
}

data "hookdeck_connection" "manually_created_connection" {
id = "web_xDRnu9yq9GMl"
}

resource "hookdeck_connection" "first_connection_using_data_sources" {
name = "first_connection_using_data_sources"
source_id = data.hookdeck_source.manually_created_source.id
destination_id = data.hookdeck_destination.manually_created_destination.id
}

resource "hookdeck_connection" "second_connection_using_data_sources" {
name = "second_connection_using_data_sources"
source_id = data.hookdeck_connection.manually_created_connection.source_id
destination_id = data.hookdeck_connection.manually_created_connection.destination_id
}
13 changes: 11 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ go 1.21
toolchain go1.21.9

require (
github.com/getkin/kin-openapi v0.127.0
github.com/hashicorp/terraform-plugin-docs v0.19.2
github.com/hashicorp/terraform-plugin-framework v1.11.0
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hookdeck/hookdeck-go-sdk v0.6.0
github.com/iancoleman/strcase v0.3.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/sys v0.24.0
)

Expand All @@ -26,6 +29,8 @@ require (
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
Expand All @@ -46,13 +51,18 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -63,8 +73,7 @@ require (
github.com/zclconf/go-cty v1.14.4 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
Expand Down
Loading

0 comments on commit 3f0bdc0

Please sign in to comment.