-
Notifications
You must be signed in to change notification settings - Fork 32
Aliases: Add aliases deployment #32
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
How does this look in the Vercel UI? And also, what's your use case for it? :) I think there's the ability to specify aliases on a per deployment basis via the My initial instinct would be to omit this, preferring project domains to be configured (potentially even on a per-branch basis?) instead, as that's more cohesive across the entirety of Vercel, but happy to hear your thoughts. |
The Vercel API is responding 204 for not found aliases
Resource alias custom provider
Just an update on this. Vercel released the Alias api documentation. And so we adapted our code to embrace it. |
Excellent. Apologies for the slow review on this one. I'm hoping to have a look at it soon :) |
No apologise needed and no rush here at all please, thanks for all your help @dglsparsons |
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.
Thanks for submitting this. The code mostly looks perfect! It's missing some acceptance tests, but I'd also like to take a deeper look at the 204
status code if you don't mind me holding off on this change in the meantime.
// Add query parameters | ||
q := req.URL.Query() | ||
if teamID != "" { | ||
q.Add("teamId", teamID) | ||
} | ||
req.URL.RawQuery = q.Encode() |
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.
It's interesting that the delete endpoint does the teamId parameter differently to the create/get endpoints. 🤔
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.
Hi. I think this file was copied/modified from deployment_delete.go
which also uses req.URL.Query
to add the parameter. So we picked the 1 inconsistent file to use as our starting point. Every other file uses fmt.Sprintf
to do the same thing.
terraform-provider-vercel % grep teamId client/* | grep fmt.Sprintf
client/alias_create.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/alias_get.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/deployment_create.go: url = fmt.Sprintf("%s&teamId=%s", url, teamID)
client/deployment_get.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/environment_variable_upsert.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/environment_variables_delete.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/environment_variables_get.go: url = fmt.Sprintf("%s&teamId=%s", url, teamID)
client/project_create.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_delete.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_domain_create.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_domain_delete.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_domain_get.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_domain_update.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_get.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/project_list.go: url = fmt.Sprintf("%s&teamId=%s", url, teamID)
client/project_update.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
client/team_get.go: url = fmt.Sprintf("%s?teamId=%s", url, teamID)
terraform-provider-vercel % grep teamId client/* | grep -v fmt.Sprintf
client/alias_delete.go: q.Add("teamId", teamID)
client/deployment_delete.go: q.Add("teamId", teamID)
if resp.StatusCode == 204 { | ||
//204 means "no content", we are treating it as an error | ||
return errors.New("no content") | ||
} |
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'm not sure we can do this as other API endpoints definitely return a 204
for certain success criteria. I'm currently looking into our API implementation for the GET alias
endpoint though to see if it's something I can change though. It may block this PR in the meantime though, so apologies for that.
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, we were discussing this 204
thing internally, It feels quite odd (almost like an API bug) to respond 204
for a not found element. I did not have a proper look at the rest of the endpoints but totally agree with you, if 204 != 404
then we should put there a bit more logic.
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 believe here, it behaves as a 404
. I think it's a mistake in our API though. I think it's something I'd be able to correct in the API though, so we get a 404
, as this makes much more 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.
That'd be ideal.
docs/index.md
Outdated
@@ -24,8 +24,8 @@ Use the navigation to the left to read about the available resources. | |||
terraform { | |||
required_providers { | |||
vercel = { | |||
source = "vercel/vercel" | |||
version = "~> 0.1" | |||
source = "streetteam/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.
Nice try ;)
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.
:D it got there by mistake
"uid": { | ||
Computed: true, | ||
Type: types.StringType, | ||
}, |
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 for provider consistency (and being in line with what the older terraform SDKs expect), we should expose this as id
rather than uid
.
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.
Looking at all of the API endpoints:
- https://vercel.com/docs/rest-api#endpoints/aliases/assign-an-alias
uid
in response
- https://vercel.com/docs/rest-api#endpoints/aliases/delete-an-alias
aliasId
in path
- https://vercel.com/docs/rest-api#endpoints/aliases/get-an-alias
idOrAlias
in pathuid
in response
- https://vercel.com/docs/rest-api#endpoints/aliases/list-deployment-aliases
uid
in response
- https://vercel.com/docs/rest-api#endpoints/aliases/list-aliases
uid
in response
It is consistently called uid
in the responses, so we thought it best to stick with that. Are you sure you want it named differently in the Terraform provider?
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.
For the testing framework data_sources have to have an id
field, and it's a semi-expected pattern that resources have an id
.
For projects, we have id
, Deployments - id
, Teams - id
. I think it's bizarre that this would have uid
as the field name.
The aliases API is quite an old API in terms of Vercel's history. I suspect that is why it refers to uid
(and the API shouldn't change for backwards compatibility), but we can expose it in a more consistent way.
PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.RequiresReplace()}, | ||
Type: types.StringType, | ||
}, | ||
"uid": { |
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.
Missing a Description
field on this, which doesn't look so nice in the generated documentation.
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.
The other resources in this provider don't have a Description
field for the id
attribute. If I rename this field to id
(as you requested in the other comment) the document generator adds the description automatically ("The ID of this resource."). Are you happy to leave the description out here, to stay consistent with the other resources?
Edit: as mentioned in the other comment, I'm not sure if we should rename it. I suppose if we rename to id
then we should leave out the description here, but if we keep it as uid
then we should add a description.
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.
In that case, i think omitting it would be totally fine, in line with the other resources in the provider :).
@dglsparsons feel free to close this PR in favor of #41 |
Closing in favour of #41 |
This is a feature that we use and so we implemented it. It is supported by the CLI (docs here) but sadly it is not documented on the Vercel's API specification.
We reverse engineered the API calls from the CLI code and it works like a charm.
If you feel like in adding this feature despite the lack of official API support then we'll create acceptance tests and update the PR.
Thanks to @raymondbutcher for helping out with this.