Problem
When attempting to change the version control settings on a workspace a "Failed to create webhook repository" error is displayed.
Cause
- This is likely due to permissions on the version control side as admin level permissions are required to create a webhook on repositories.
Solutions:
- Create a test webhook to the repository outside of Terraform Cloud / Enterprise with the same token used in Terraform Cloud / Enterprise to see if the provider throws an error. In this example, we are using the Github API.
curl -H "Authorization: token $token" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/test-user/$repository-name/hooks" \
-d '{"name":"web","active":true,"events":["push","pull_request"],"config":{"url":"https://example.com/webhook","content_type":"json","insecure_ssl":"0"}}'
-
If successful, then the webhook will be created on the repository. You can verify this by navigating to the repository and webhooks. The issue is likely not related to permissions.
-
If the curl request failed then the API will report an error which will most likely be similar to what Terraform Cloud / Enterprise reported.
-
Check the permissions on the repository by using the version control providers API. In this example, we are listing the repositories and permissions that the user has access to.
curl -H "Authorization: token $token" \
https://api.github.com/user/repos | jq '.[] | "\(.permissions) \(.name)"'
# Results
"{\"admin\":false,\"maintain\":true,\"push\":true,\"triage\":true,\"pull\":true} hashicups"
"{\"admin\":false,\"maintain\":true,\"push\":true,\"triage\":true,\"pull\":true} localterraform"
"{\"admin\":true,\"maintain\":true,\"push\":true,\"triage\":true,\"pull\":true} moduletest"
"{\"admin\":true,\"maintain\":true,\"push\":true,\"triage\":true,\"pull\":true} null_resource"
"{\"admin\":true,\"maintain\":true,\"push\":true,\"triage\":true,\"pull\":true} planexportest"
In this example, you can see that the hashicups
and localterraform
repositories do not have admin permissions so webhooks cannot be created.
To resolve the issue, navigate to the repository and change the permissions for the user account to admin and try creating the webhook again either through the API or through the Terraform Cloud / Enterprise UI.
Additional Information
-
If this does not resolve the issue then please submit a support ticket to HashiCorp Support.