-
Notifications
You must be signed in to change notification settings - Fork 31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ type ProjectSettings struct { | |
RootDirectory types.String `tfsdk:"root_directory"` | ||
} | ||
|
||
// 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"` | ||
} | ||
|
||
Comment on lines
+23
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// Deployment represents the terraform state for a deployment resource. | ||
type Deployment struct { | ||
Domains types.List `tfsdk:"domains"` | ||
|
@@ -33,6 +40,7 @@ type Deployment struct { | |
TeamID types.String `tfsdk:"team_id"` | ||
URL types.String `tfsdk:"url"` | ||
DeleteOnDestroy types.Bool `tfsdk:"delete_on_destroy"` | ||
GitSource *GitSource `tfsdk:"git_source"` | ||
} | ||
|
||
// setIfNotUnknown is a helper function to set a value in a map if it is not unknown. | ||
|
@@ -46,6 +54,16 @@ func setIfNotUnknown(m map[string]interface{}, v types.String, name string) { | |
} | ||
} | ||
|
||
// toRequest takes the input of GitSource and converts them into the required | ||
// format for a CreateDeploymentRequest. | ||
func (g *GitSource) toRequest() client.GitSource { | ||
return client.GitSource{ | ||
Ref: g.Ref.Value, | ||
RepoId: g.RepoId.Value, | ||
Type: g.Type.Value, | ||
} | ||
} | ||
|
||
// toRequest takes a set of ProjectSettings and converts them into the required | ||
// format for a CreateDeploymentRequest. | ||
func (p *ProjectSettings) toRequest() map[string]interface{} { | ||
|
@@ -187,5 +205,19 @@ func convertResponseToDeployment(response client.DeploymentResponse, plan Deploy | |
PathPrefix: fillStringNull(plan.PathPrefix), | ||
ProjectSettings: plan.ProjectSettings.fillNulls(), | ||
DeleteOnDestroy: plan.DeleteOnDestroy, | ||
GitSource: plan.GitSource, | ||
} | ||
} | ||
|
||
// checkMutualyExclusiveAttributes checks whether git_source and files are not set at the same time | ||
func (d *Deployment) checkMutualyExclusiveAttributes() error { | ||
Comment on lines
+212
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 :) |
||
// Error if both are nil | ||
if d.Files != nil && d.GitSource != nil { | ||
return fmt.Errorf("only one of \"files\" or \"git_source\" must be set, not both") | ||
} | ||
// Error if both are set | ||
if d.Files == nil && d.GitSource == nil { | ||
return fmt.Errorf("either \"files\" or \"git_source\" must be set") | ||
} | ||
return nil | ||
} |
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?
Uh oh!
There was an error while loading. Please reload this page.
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 thevercel_project
resource and thevercel_project
data source.This would mean you can use it like:
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 theref
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 thevercel_deployment
resource.For example
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:
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 😓