Description
Description
My team is attempting to manually create a Deployment, then promote it to a specific domain using vercel_alias
resource. The terraform code looks something like this.
# API that the UI is dependent on
resource "aws_ecs_service" "api" { }
resource "vercel_project" "ui" {
name = "ui"
auto_assign_custom_domains = false
}
resource "vercel_project_domain" "ui_domain" {
project_id = vercel_project.ui.id
domain = "my-app-domain.example.com"
}
# Create the Vercel deployment, but do not assign the domain yet
resource "vercel_deployment" "ui" {
project_id = vercel_project.ui.id
files = data.vercel_project_directory.ui.files
production = true
}
resource "vercel_alias" "ui" {
alias = vercel_project_domain.ui_domain.domain
deployment_id = vercel_deployment.ui.id
# Wait to assign prod until downstream services are ready
depends_on = [aws_ecs_service.api]
}
The resulting terraform plan looks like this.
Start Destroy: `vercel_alias.ui`
Start Change: `aws_ecs_service.api`
Start Change: `vercel_deployment.ui`
End Destroy: `vercel_alias.ui`
# some time...
End Change: `vercel_deployment.ui`
# some time...
End Change: `aws_ecs_service.api`
Start Create: `vercel_alias.ui`
End Create: `vercel_alias.ui`
The problem here is that by design terraform destroys resources in reverse order of their creation, which means that vercel_alias.ui
will be destroyed before everything else, and the new alias will not be created until after all of it's dependencies have been updated. The end user will then see a 404: DEPLOYMENT_NOT_FOUND
error if they attempt to load the specified domain between the start of the terraform run and the end of the terraform run.
Desired Outcome
The goal here is that we want to have zero-downtime deployments when assigning domains manually to a deployment.
Solutions Attempted
We tried updating the vercel_alias.ui
resource lifecycle to only add the alias after the destroy
resource "vercel_alias" "ui" {
# ...
lifecycle {
create_before_destroy = true
}
This looked promising, as the alias was still active while waiting for all of vercel_alias.ui
's dependencies to finish, it ended up destroying the alias completely, resulting in a 404: DEPLOYMENT_NOT_FOUND
after terraform had finished applying changes.
Other thoughts
The create alias api is definitely strange, as there isn't a PATCH
or PUT
resource available for it. However, it does appear that the POST
resource behaves very similar to an update.
Creates a new alias for the deployment with the given deployment ID. The authenticated user or team must own this deployment. If the desired alias is already assigned to another deployment, then it will be removed from the old deployment and assigned to the new one.
From my limited understanding of this repo & terraform providers, it looks like updating of aliases aren't supported. Could this be implemented using the POST
alias endpoint? This would then allow terraform to update the resource in place in the correct order, without any downtime.