|
| 1 | +--- |
| 2 | +page_title: "Getting Started" |
| 3 | +description: "Getting Started with Hookdeck Provider" |
| 4 | +--- |
| 5 | + |
| 6 | +# Getting Started with Hookdeck Provider |
| 7 | + |
| 8 | +## Hookdeck |
| 9 | + |
| 10 | +The Hookdeck Event Gateway enables engineering teams to build, deploy, observe, and scale event-driven applications. |
| 11 | + |
| 12 | +Once integrated, Hookdeck unlocks an entire suite of tools: [alerting](https://hookdeck.com/docs/notifications), [rate limiting](https://hookdeck.com/docs/set-a-rate-limit), [automatic retries](https://hookdeck.com/docs/automatically-retry-events), [one-to-many delivery](https://hookdeck.com/docs/create-a-destination), [payload transformations](https://hookdeck.com/docs/transformations), local testing via the [CLI](https://hookdeck.com/docs/using-the-cli), a feature-rich [API](https://hookdeck.com/docs/using-the-api), and more. It acts as a proxy – routing webhooks from any [source](https://hookdeck.com/docs/sources) to a specified [destination](destinations). |
| 13 | + |
| 14 | +Visit the [Hookdeck documentation](https://hookdeck.com/docs/introduction) to learn more. |
| 15 | + |
| 16 | +## Terraform |
| 17 | + |
| 18 | +[Terraform](https://developer.hashicorp.com/terraform/intro) is an open-source Infrastructure as Code (IaC) tool that allows you to define and manage infrastructure resources using HashiCorp Configuration Language (HCL). It can be used to manage a wide range of resources, including servers, storage, networks, and cloud services. Terraform is a popular choice for infrastructure automation because it is easy to use, flexible, and powerful. |
| 19 | + |
| 20 | +The Hookdeck Terraform provider helps you utilize Terraform to configure your workspace declaratively instead of relying on the Hookdeck dashboard. You can run Terraform in your CI/CD pipeline and maintain Hookdeck workspace configuration programmatically as part of your deployment workflow. |
| 21 | + |
| 22 | + |
| 23 | +## Tutorial |
| 24 | + |
| 25 | +Before you begin, make sure you have [Terraform CLI](https://developer.hashicorp.com/terraform/downloads) installed locally and a Hookdeck API Key obtained from [the dashboard](https://dashboard/hookdeck.com/workspace/secrets). |
| 26 | + |
| 27 | +### Initialize Terraform |
| 28 | + |
| 29 | +In a directory of your choice, create a Terraform config file `main.tf`: |
| 30 | + |
| 31 | +```hcl |
| 32 | +# main.tf |
| 33 | +
|
| 34 | +terraform { |
| 35 | + required_providers { |
| 36 | + hookdeck = { |
| 37 | + source = "hookdeck/hookdeck" |
| 38 | + version = "~> 0.1" |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | +
|
| 43 | +provider "hookdeck" { |
| 44 | + api_key = "<YOUR_API_KEY>" |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +Replace `<YOUR_API_KEY>` with your Hookdeck workspace API key. |
| 49 | + |
| 50 | +After creating your basic configuration in HCL, initialize Terraform and ask it to apply the configuration to Hookdeck. |
| 51 | + |
| 52 | +```sh |
| 53 | +$ terraform init |
| 54 | +``` |
| 55 | + |
| 56 | +Running `terraform init` will download the plugins required in the configuration file, such as the Hookdeck Terraform provider, to a local `.terraform` directory. |
| 57 | + |
| 58 | +Afterward, you can run `terraform plan` to confirm that you have Terraform properly installed. As you haven't added any resources for Terraform to manage yet, it will indicate that there are no planned changes with your infrastructure's current state. |
| 59 | + |
| 60 | +``` |
| 61 | +$ terraform plan |
| 62 | +``` |
| 63 | + |
| 64 | +### Source |
| 65 | + |
| 66 | +First, let's create a source resource with Terraform. You can add this resource block to the end of your Terraform configuration file |
| 67 | + |
| 68 | +```hcl |
| 69 | +resource "hookdeck_source" "my_source" { |
| 70 | + name = "my_source" |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +Now, try `terraform plan` again to see what Terraform may suggest |
| 75 | + |
| 76 | +```sh |
| 77 | +$ terraform plan |
| 78 | +``` |
| 79 | + |
| 80 | +``` |
| 81 | +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: |
| 82 | + + create |
| 83 | +
|
| 84 | +Terraform will perform the following actions: |
| 85 | +
|
| 86 | + # hookdeck_source.my_source will be created |
| 87 | + + resource "hookdeck_source" "my_source" { |
| 88 | + + allowed_http_methods = [ |
| 89 | + + "POST", |
| 90 | + + "PUT", |
| 91 | + + "PATCH", |
| 92 | + + "DELETE", |
| 93 | + ] |
| 94 | + + archived_at = (known after apply) |
| 95 | + + created_at = (known after apply) |
| 96 | + + id = (known after apply) |
| 97 | + + name = "my_source" |
| 98 | + + team_id = (known after apply) |
| 99 | + + updated_at = (known after apply) |
| 100 | + + url = (known after apply) |
| 101 | + } |
| 102 | +
|
| 103 | +Plan: 1 to add, 0 to change, 0 to destroy. |
| 104 | +
|
| 105 | +───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
| 106 | +
|
| 107 | +Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. |
| 108 | +``` |
| 109 | + |
| 110 | +You can execute this change and create a source in your workspace like so. |
| 111 | + |
| 112 | +```sh |
| 113 | +$ terraform apply |
| 114 | +``` |
| 115 | + |
| 116 | +You can check the dashboard to confirm that a new source was created in your workspace. |
| 117 | + |
| 118 | +To learn more about what options you have with Hookdeck's Source on Terraform, check out the [`hookdeck_source` docs](https://registry.terraform.io/providers/hookdeck/hookdeck/latest/docs/resources/source). |
| 119 | + |
| 120 | +### Destination |
| 121 | + |
| 122 | +Next, add a simple destination resource: |
| 123 | + |
| 124 | +```hcl |
| 125 | +resource "hookdeck_destination" "my_destination" { |
| 126 | + name = "my_destination" |
| 127 | + url = "https://mock.hookdeck.com" |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +This is a Mock destination which will accepts all of your events so you can inspect on Hookdeck's dashboard. |
| 132 | + |
| 133 | +Now, run `terraform apply` to create your new destination. Terraform will show the plan and ask for your confirmation before executing it, so you don't need to run `terraform plan` beforehand. |
| 134 | + |
| 135 | +To learn more about what options you have with Hookdeck's Destination on Terraform, check out the [`hookdeck_destination` docs](https://registry.terraform.io/providers/hookdeck/hookdeck/latest/docs/resources/destination). |
| 136 | + |
| 137 | +### Connection |
| 138 | + |
| 139 | +Lastly, define a Hookdeck connection to connect the source and destination: |
| 140 | + |
| 141 | +```hcl |
| 142 | +resource "hookdeck_connection" "my_connection" { |
| 143 | + source_id = hookdeck_source.my_source.id |
| 144 | + destination_id = hookdeck_destination.my_destination.id |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +As before, run `terraform apply` to review the plan and apply the changes. |
| 149 | + |
| 150 | +To learn more about what options you have with Hookdeck's Connection on Terraform, check the [`hookdeck_connection` docs](https://registry.terraform.io/providers/hookdeck/hookdeck/latest/docs/resources/connection). |
| 151 | + |
| 152 | +### Summary |
| 153 | + |
| 154 | +In this tutorial, you have: |
| 155 | + |
| 156 | +- Installed Terraform CLI locally and initialized a Terraform project with Hookdeck provider with `terraform init` |
| 157 | +- Written the configuration code for a Hookdeck source, destination, and connection using Terraform's declarative programming language, HCL |
| 158 | +- Reviewed and executed the Terraform plan with `terraform plan` and `terraform apply` |
| 159 | + |
| 160 | +Here's the final `main.tf` file: |
| 161 | + |
| 162 | +``` |
| 163 | +terraform { |
| 164 | + required_providers { |
| 165 | + hookdeck = { |
| 166 | + source = "hookdeck/hookdeck" |
| 167 | + version = "~> 0.1" |
| 168 | + } |
| 169 | + } |
| 170 | +} |
| 171 | +
|
| 172 | +provider "hookdeck" { |
| 173 | + api_key = "<YOUR_API_KEY>" |
| 174 | +} |
| 175 | +
|
| 176 | +resource "hookdeck_source" "my_source" { |
| 177 | + name = "my_source" |
| 178 | +} |
| 179 | +
|
| 180 | +resource "hookdeck_destination" "my_destination" { |
| 181 | + name = "my_destination" |
| 182 | + url = "https://mock.hookdeck.com" |
| 183 | +} |
| 184 | +
|
| 185 | +resource "hookdeck_connection" "my_connection" { |
| 186 | + source_id = hookdeck_source.my_source.id |
| 187 | + destination_id = hookdeck_destination.my_destination.id |
| 188 | +} |
| 189 | +``` |
0 commit comments