Open mojavelinux opened 5 years ago
I did a lot more research on this and I think I've figured out what's going on. I'm happy to report that Terraform is not to blame.
The first problem has to do with the webhook. It appears that when a Netlify site is created using the open-api, Netlify refuses to recognize events from the webhook (at least, not the one for GitLab). (This is where that lock icon comes in).
I verified this theory by using the Netlify API directly to create the site. Assume in this case the site is public, so no deploy key is required.
const Netlify = require('netlify')
const client = new Netlify(process.env.NETLIFY_TOKEN)
;(async () => {
await client.createSite({
body: {
name: 'name-of-site-1234567890',
repo: {
provider: 'gitlab',
repo_path: 'organization/name-of-site',
repo_branch: 'master',
}
}
})
})()
The site gets set up and builds correctly. However, changes to the repository reported by the webhook (assuming one is already in place) are not detected.
This appears to be a bug in Netlify and I'll report it there.
The second issue was a user error regarding the deploy key. I had reported that Terraform does not setting up the site correctly when connecting to a private repository. This statement is incorrect. Instead, it turned out to be an ordering problem.
Netlify determines it is working with a private repository if:
a) A deploy_key_id is specified b) The deploy_key works at the time the site is created
Therefore, the Terraform resources must be executed in this order:
In my set up, the netlify_site resource was running before the gitlab_deploy_key, so Netlify was assuming the repository is public. I fixed this by using a depends_on clause:
resource "netlify_site" "docs_ui" {
name = "docs_ui-1234567890"
repo {
provider = "gitlab"
deploy_key_id = "${netlify_deploy_key.docs_ui.id}"
repo_path = "${substr(gitlab_project.docs_ui.web_url, length("https://gitlab.com/"), -1)}"
repo_branch = "master"
}
depends_on = ["gitlab_deploy_key.docs_ui"]
}
Once I made that change, the Netlify site was created correctly.
I'd still be interested in seeing a GitLab example make its way to the README. Let me know if you'd like me to send a PR.
Here's the upstream issue in Netlify: https://github.com/netlify/open-api/issues/143
When I try to use the netlify provider to establish a link between Netlify and a GitLab repository, it doesn't seem to work. The site gets set up and the repository is populated with both the web hook and the deploy key, but the connection seems broken.
Here are the two problems I observe:
I'm confident there's a problem with the linkage between Netlify and GitLab because I see a lock icon next to the repository on the Build Settings page. If I edit the Build Settings and reestablish the link to the repository, the lock goes away and everything starts working. (But then, I didn't use Terraform to set it up, so it defeats the whole point of using Terraform).
Here's the configuration I'm using:
If I can guess, the problem seems to be that Netlify is never given any auth information for GitLab. If that's possible, I don't understand where that is supposed to be set.
I'd be happy to contribute an GitLab example for the README if I can get it working.