terraform-provider-vercel: Error when trying to deploy prebuilt project
Hi,
I have a monorepo setup:
.vercel/
src/
frontend/
...
terraform/
main.tf
(Note how the .vercel folder is at the root of the monorepo - this is required for vercel build to work correctly).
I can build & deploy this manually just fine:
pnpm vercel build --prod --token=$VERCEL_TOKEN
pnpm vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN
Now I want to do the same, deploying with terraform. Following the docs, I do:
data "vercel_prebuilt_project" "frontend_dir" {
path = "../../../"
}
# TODO: How does this interact with the .vercel/project.json stuff?
resource "vercel_deployment" "prod_deployment" {
project_id = vercel_project.frontend_project.id
files = data.vercel_prebuilt_project.frontend_dir.output
path_prefix = data.vercel_prebuilt_project.frontend_dir.path
production = true
}
But this raises an error when running terraform -chdir=src/frontend/terraform apply (after having run pnpm vercel build --prod --token=$VERCEL_TOKEN already):
│ Error: Error reading prebuilt output
│
│ with data.vercel_prebuilt_project.frontend_dir,
│ on main.tf line 61, in data "vercel_prebuilt_project" "frontend_dir":
│ 61: data "vercel_prebuilt_project" "frontend_dir" {
│
│ An unexpected error occurred reading files from the .vercel directory: could not read file
│ ../../../.vercel/output/functions/_not-found.rsc.func: read ../../../.vercel/output/functions/_not-found.rsc.func: is a directory
And that’s correct, .vercel/output/functions/_not-found.rsc.func is indeed a directory, not sure why terraform expects it to be a file. The vercel provider version is vercel/vercel v2.3.0, and I am using next 14.2.
I couldn’t find anything about this error online. Do you have an idea? Thanks!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27
Commits related to this issue
- Change prebuilt data source to follow symlinks Closes #236 — committed to vercel/terraform-provider-vercel by dglsparsons 2 years ago
- Change prebuilt data source to follow symlinks Closes #236 — committed to vercel/terraform-provider-vercel by dglsparsons 2 years ago
- Change prebuilt data source to follow symlinks (#247) Closes #236 — committed to vercel/terraform-provider-vercel by dglsparsons 2 years ago
Maybe just do
terraform init -upgradethen. Probably because of your lock file.Ahh damn, yeah, that makes sense. It’s interesting that i didn’t get these issues when i was doing a reproduction of your use case and testing out the fixes. It looks like the fix should be fairly simple though - just appending the
path_prefixonto the files read from thefilePathMap. I’ll look and see if i can get a fix out. 🙏Hey @dglsparsons, thanks for your reactivity. I believe I need to give you more context on my monorepo structure. Once I ran
vercel pullandvercel buildfrom the root of my repository, here’s how it looks like when I try to apply my terraform stack located oninfrastructure/vercel/project_A:I gave v2.13.0 a go and seems to encounter other issues :
First of all the
path_prefixis well applied on the files inside the.vercelfolder When I outputdata.vercel_prebuilt_project.preview.output, I have some files well prefixed like that :"../../../../../MyRepo/.vercel/output/builds.json": "793~279f82e969d7edd9f18b5ce87461bdc9dc0690ba",But also not so well prefixed like dependency files :And applying terraform gives me error like :
Could not get info for file ui/dist/index.js, unexpected error: lstat ui/dist/index.js: no such file or directoryI believe thedata.vercel_prebuilt_project.preview.outputoutput should looks like :Please let me know if you need further information
@dglsparsons Congratulations on your baby! 😃
Thank you, looking forward to see this fixed. It’s hard to create a simple repo to reproduce, since this is a monorepo with a bunch of other code. This is my entire
main.tfconfiguration:The structure of my project is:
And the error is still the same: