hookdeck/terraform-provider-hookdeck

Creating an Source with "verification" set results in 422 API response

leggetter opened this issue · 5 comments

Using this definition:

resource "hookdeck_source_verification" "my_authenticated_source" {
  source_id = "my_authenticated_source"
  verification = {
    json = jsonencode({
      type = "BASIC_AUTH"
      configs = {
        username = "some-username"
        password = "blah-blah-blah"
      }
    })
  }
}

Running terraform apply results in the error shown below:

$ terraform apply                                                                                                                                                                                                 
hookdeck_source.my_source: Refreshing state... 
hookdeck_destination.my_destination: Refreshing state... 
hookdeck_connection.my_connection: Refreshing state... 

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # hookdeck_source_verification.my_authenticated_source will be created
  + resource "hookdeck_source_verification" "my_authenticated_source" {
      + source_id    = "my_authenticated_source"
      + verification = {
          + json = jsonencode(
                {
                  + configs = {
                      + password = "blah-blah-blah"
                      + username = "some-username"
                    }
                  + type    = "BASIC_AUTH"
                }
            )
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

hookdeck_source_verification.my_authenticated_source: Creating...
╷
│ Error: Error creating source verification
│ 
│   with hookdeck_source_verification.my_authenticated_source,
│   on main.tf line 26, in resource "hookdeck_source_verification" "my_authenticated_source":
│   26: resource "hookdeck_source_verification" "my_authenticated_source" {
│ 
│ 422: {"level":"info","handled":true,"report":true,"data":["verification does not match any of the allowed types"],"status":422,"code":"UNPROCESSABLE_ENTITY"}

I've confirmed that the Source API endpoint appears to work as expected:

curl --location 'https://api.hookdeck.com/2024-03-01/sources' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
  "name": "my-example-source-2",
  "verification": {
    "type": "BASIC_AUTH",
    "configs": {
      "username": "example_username",
      "password": "example_password"
    }
  }
}'

And the Connection API endpoint:

curl --location 'https://api.hookdeck.com/2024-03-01/connections' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
  "name": "connection-example-1",
  "destination": {
    "name": "my-destination",
    "url": "https://mock.hookdeck.com"
  },
  "source": {
  "name": "my-example-source-3",
  "verification": {
    "type": "BASIC_AUTH",
    "configs": {
      "username": "example_username",
      "password": "example_password"
    }
  }
}
}'

@alexluong within the following, how are we supposed to know the source_id? Should we be using name instead?

resource "hookdeck_source_verification" "my_authenticated_source" {
  source_id = "my_authenticated_source"
  verification = {
    json = jsonencode({
      type = "BASIC_AUTH"
      configs = {
        username = "some-username"
        password = "blah-blah-blah"
      }
    })
  }
}

Note: I've tested and you can create or update a Source with just the name and the id isn't required.

@leggetter you're supposed to use the source you created like so

resource "hookdeck_source" "my_authenticated_source" {
  name = "my_authenticated_source"
}

resource "hookdeck_source_verification" "my_authenticated_source" {
  source_id = hookdeck_source.my_authenticated_source.id
  verification = {
    json = jsonencode({
      type = "BASIC_AUTH"
      configs = {
        username = "some-username"
        password = "blah-blah-blah"
      }
    })
  }
}

@leggetter you're supposed to use the source you created like so

resource "hookdeck_source" "my_authenticated_source" {
  name = "my_authenticated_source"
}

resource "hookdeck_source_verification" "my_authenticated_source" {
  source_id = hookdeck_source.my_authenticated_source.id
  verification = {
    json = jsonencode({
      type = "BASIC_AUTH"
      configs = {
        username = "some-username"
        password = "blah-blah-blah"
      }
    })
  }
}

@alexluong - Ok, thanks 👍

Fixed in #63