-
Notifications
You must be signed in to change notification settings - Fork 32
GitSource: added git source deployment #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
After few tests this just worked well all the times, we're using our fork in prod, so please feel free to merge if you want/like or to propose changes. Thanks for your job guys! |
99d24b0
to
167d4c4
Compare
Could you please review and merge if you think it is ok? |
167d4c4
to
19cce9f
Compare
docs/resources/deployment.md
Outdated
- **files** (Map of String) A map of files to be uploaded for the deployment. This should be provided by a `vercel_project_directory` or `vercel_file` data source. | ||
- **git_source** (Attributes) A map with the Git repo information (see [below for nested schema](#nestedatt--git_source)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably validate that one of files
or git_source
is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/resources/deployment.md
Outdated
- **ref** (String) Branch or commit hash | ||
- **repo_id** (String) Frontend git repo ID | ||
- **type** (String) Type of git repo, supported values are: github |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these all optional? Aren't they required if specifying a git_source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set them as required, let me check why they appear as optional in the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was investigating a bit and could not find why this happens. tfplugindocs just renders them as optional even when they are set as required. if happens the same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh interesting. I guess it's because the parent property is optional then.
vercel/resource_deployment_model.go
Outdated
var gs client.GitSource | ||
gs.Ref = g.Ref.Value | ||
gs.RepoId = g.RepoId.Value | ||
gs.Type = g.Type.Value | ||
return gs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not:
return client.GitSource{
Ref: g.Ref.Value,
RepoId: g.RepoId.Value,
Type: g.Type.Value,
}
// GitSource represents the Git integration source for a deployment. | ||
type GitSource struct { | ||
RepoId types.String `tfsdk:"repo_id"` | ||
Ref types.String `tfsdk:"ref"` | ||
Type types.String `tfsdk:"type"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd also want to add acceptance tests specifically around creating a resource_deployment
with git_source
set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working on these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
0510334
to
1315b35
Compare
I think the tests are not passing because the PR is coming from an external repo and that mess the GH secrets maybe? the tests work locally on my end.
|
934df13
to
d984051
Compare
// checkMutualyExclusiveAttributes checks whether git_source and files are not set at the same time | ||
func (d *Deployment) checkMutualyExclusiveAttributes() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do this as a validation instead, but I'll merge the changes and fix this up retrospectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to clarify, are you merging this or you require more changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, i wasn't very clear. I meant i'd take a look at fixing that (either post merge, or by checking out your branch). I've only had a surface level skim so far :)
@@ -20,6 +20,11 @@ type DeploymentFile struct { | |||
Sha string `json:"sha"` | |||
Size int `json:"size"` | |||
} | |||
type GitSource struct { | |||
RepoId string `json:"repoId"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Digging into this, where does the repoId
come from?
I can see in the example that you have it as a number. 🤔. I wonder if we need some data source to expose this so it's more usable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so repoId
looks like it is exposed through a project. I think it could be exposed from both the vercel_project
resource and the vercel_project
data source.
This would mean you can use it like:
data "vercel_project" "my_project" {
name = "my-project"
}
resource "vercel_deployment" "example" {
team_id = var.vercel_team_id
project_id = data.vercel_project.my_project.id
git_source = {
ref = "main" // or any other branch you fancy.
repo_id = data.vercel_project.my_project.git_repository.repo_id
type = data.vercel_project.my_project.git_repository.type
}
}
I think this would be more preferable than having to dig out a repoId. What do you think @WCMinor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another issue I can see here is that Terraform would not know when the vercel_deployment
resource needs re-creating. Short of having something like the ref
set to a specific commit ID. So this would only act as a one-off deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/13902593/how-does-one-find-out-ones-own-repo-id
The number provided in the test is your repo btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true that you can find it out that way, but I think it's somewhat surprising to see (and results in a magic number). I think if we had the data source, or exposed it via a project it would be more intuitive on how to use the two together to trigger a deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity have you considered putting them in a single repository, behind something like https://turborepo.org/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're actually moving on from a monorepo to a distributed system to allow each team to manage their own code as the teams get bigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! As an update on this issue - I've been having a play around, and I'm coming to the belief that the only thing needed is a ref
field on the vercel_deployment
resource.
For example
resource "vercel_project" "example" {
name = "my-test-project"
git_repository = {
type = "github"
repo = "acme/example"
}
}
# Deploy the main branch of acme/example.
resource "vercel_deployment" "example" {
project_id = vercel_project.example.id
ref = "main" # or a commit ID.
}
The deployment resource can, itself, look up the relevant repoId / equivalent bitbucket/gitlab parameters, and pass these onto the deployment creation.
You could even use it with a data-source to pull a project by a name:
data "vercel_project" "example" {
name = "my-test-project"
}
resource "vercel_deployment" "example" {
project_id = data.vercel_project.example.id
ref = "main"
}
We already have a hard requirement that for a deployment to be created, a project must already exist. I think using the git-connection this way would work nicely, and also prevents any confusing fields being presented back out of the provider (like repoId or projectUuid or workspaceUuid). What do you think @WCMinor? Would this work for your use-case?
With my playing around I think i'm fairly close to a working version, so if this works for you, I should be able to have a PR up soonish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great yeah, much easier to understand and to configure.
Funny enough, if you pass a public github repo (not configured in your project) to the deploy API , it works, it deploys a project based on such public repo. That is the only case in which it would make sense to use a standalone git_source
parameter. Honestly, I think that functionality is kinda out of the scope of this provider as it is not really documented by Vercel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's probably more a result of accidental API design than anything else 😓
client/deployment_create.go
Outdated
ReadyState string `json:"readyState"` | ||
Target *string `json:"target"` | ||
URL string `json:"url"` | ||
GitSource GitSource `json:"git_source"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect the snake case here isn't correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, as per their recommendations it looks fine:
Attribute names within Terraform configuration blocks are conventionally named as all-lowercase with underscores separating words, as shown above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to change it if you think it is more consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the json response from the Vercel API, so not to do with the terraform configuration :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I just tested it
},
"gitSource": {
"repoId": 449314886,
"ref": "dario-terraform-deployment-test",
"type": "github",
"sha": "f4f09e995618dea3cd77e39a2cb710628ae03228"
changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray. We should probably set this back onto the terraform state, rather than using the value from plan
in that case (so it's readable). However... I think we probably need to fix the repoId
issue with different git providers first.
Followed the API documentation https://vercel.com/docs/rest-api#endpoints/deployments/create-a-new-deployment
d984051
to
5559450
Compare
Closing this in favour of #29 |
Followed the API documentation https://vercel.com/docs/rest-api#endpoints/deployments/create-a-new-deployment
This PR makes able the deployment from Git Source avoiding the need of upload the files to Vercel.
It works passing a new parameter called
git_source
, it is a map and it looks like this:Here is an example of output, it just works: