vercel / terraform-provider-vercel

Terraform Vercel Provider
Mozilla Public License 2.0
138 stars 21 forks source link

Creating Project Fails #125

Closed Nexushunter closed 11 months ago

Nexushunter commented 11 months ago

Hey 👋🏻 I'm trying to deploy to vercel via GHA. I'm looking for some guidance into what I'm doing wrong.

My main.tf looks like:

terraform {
  required_providers {
    vercel = {
      source  = "vercel/vercel"
      version = "~> 0.15"
    }
  }
  required_version = "1.5.3"
}

provider "vercel" {
  api_token = var.vercel_api_token
}

resource "vercel_project" "dev" {
  name      = "nexushunter"
  framework = "nextjs"

  git_repository = {
    type              = "github"
    production_branch = "main"
    repo              = "Nexushunter/nexushunterdev"
  }
  serverless_function_region = "iad1"
}

resource "vercel_project_domain" "dev" {
  project_id = vercel_project.dev.id
  git_branch = var.branch_name
  domain     = "staging.nexushunter.dev"
}

Variables file:

# Set in GHA env
variable "vercel_api_token" {
  type        = string
  description = "Vercel Api Token"
}

variable "vercel_project_id" {
  type        = string
  description = "Vercel Project Id"
}

variable "branch_name" {
  type        = string
  description = "Development Branch Name"
  default     = null 
}

Trace logs:

vercel_project.dev: Creating...
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Received request: tf_proto_version=6.3 tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_provider_addr=registry.terraform.io/vercel/vercel tf_resource_type=vercel_project tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov6/tf6server/server.go:806 @module=sdk.proto timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Sending request downstream: tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_resource_type=vercel_project tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov6/internal/tf6serverlogging/downstream_request.go:20 @module=sdk.proto tf_proto_version=6.3 tf_provider_addr=registry.terraform.io/vercel/vercel timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Checking ResourceTypes lock: @module=sdk.framework tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_rpc=ApplyResourceChange tf_resource_type=vercel_project @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server.go:342 tf_provider_addr=registry.terraform.io/vercel/vercel timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Checking ResourceSchemas lock: tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server.go:416 tf_provider_addr=registry.terraform.io/vercel/vercel tf_resource_type=vercel_project tf_rpc=ApplyResourceChange @module=sdk.framework timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: ApplyResourceChange received no PriorState, running CreateResource: tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_resource_type=vercel_project @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_applyresourcechange.go:45 @module=sdk.framework tf_rpc=ApplyResourceChange timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Resource implements ResourceWithConfigure: tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_createresource.go:47 @module=sdk.framework tf_resource_type=vercel_project timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [DEBUG] provider.terraform-provider-vercel_v0.15.0: Calling provider defined Resource Configure: tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_createresource.go:54 @module=sdk.framework tf_provider_addr=registry.terraform.io/vercel/vercel tf_resource_type=vercel_project timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [DEBUG] provider.terraform-provider-vercel_v0.15.0: Called provider defined Resource Configure: tf_rpc=ApplyResourceChange tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_resource_type=vercel_project @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_createresource.go:56 @module=sdk.framework timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [DEBUG] provider.terraform-provider-vercel_v0.15.0: Calling provider defined Resource Create: @module=sdk.framework tf_resource_type=vercel_project tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_createresource.go:100 tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.340Z [TRACE] provider.terraform-provider-vercel_v0.15.0: creating project: payload={"buildCommand":null,"devCommand":null,"environmentVariables":[],"framework":"nextjs","gitRepository":{"type":"github","repo":"Nexushunter/nexushunterdev"},"installCommand":null,"name":"nexushunterdev","outputDirectory":null,"publicSource":null,"rootDirectory":null,"serverlessFunctionRegion":"iad1"} tf_provider_addr=registry.terraform.io/vercel/vercel tf_resource_type=vercel_project tf_rpc=ApplyResourceChange url=https://api.vercel.com/v8/projects @caller=github.com/vercel/terraform-provider-vercel/client/project_create.go:53 @module=vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c timestamp=2023-08-01T02:34:28.340Z
2023-08-01T02:34:28.897Z [DEBUG] provider.terraform-provider-vercel_v0.15.0: Called provider defined Resource Create: tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-framework@v1.3.1/internal/fwserver/server_createresource.go:102 @module=sdk.framework tf_resource_type=vercel_project timestamp=2023-08-01T02:34:28.897Z
2023-08-01T02:34:28.898Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Received downstream response: diagnostic_error_count=1 tf_req_duration_ms=557 tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c diagnostic_warning_count=0 tf_proto_version=6.3 tf_provider_addr=registry.terraform.io/vercel/vercel tf_resource_type=vercel_project @caller=github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov6/internal/tf6serverlogging/downstream_request.go:40 @module=sdk.proto tf_rpc=ApplyResourceChange timestamp=2023-08-01T02:34:28.897Z
Error: -01T02:34:28.898Z [ERROR] provider.terraform-provider-vercel_v0.15.0: Response contains error diagnostic: diagnostic_summary="Error creating project" tf_proto_version=6.3 tf_provider_addr=registry.terraform.io/vercel/vercel tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c @module=sdk.proto diagnostic_detail="Could not create project, unexpected error: internal_server_error - An unexpected internal error occurred" tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov6/internal/diag/diagnostics.go:58 diagnostic_severity=ERROR tf_resource_type=vercel_project timestamp=2023-08-01T02:34:28.897Z
2023-08-01T02:34:28.898Z [TRACE] provider.terraform-provider-vercel_v0.15.0: Served request: @caller=github.com/hashicorp/terraform-plugin-go@v0.16.0/tfprotov6/tf6server/server.go:832 tf_proto_version=6.3 tf_req_id=51fd04f6-bbbf-f3d1-5c0d-6683e2e35e4c tf_resource_type=vercel_project @module=sdk.proto tf_provider_addr=registry.terraform.io/vercel/vercel tf_rpc=ApplyResourceChange timestamp=2023-08-01T02:34:28.897Z
2023-08-01T02:34:28.898Z [TRACE] maybeTainted: vercel_project.dev encountered an error during creation, so it is now marked as tainted
2023-08-01T02:34:28.898Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for vercel_project.dev
2023-08-01T02:34:28.898Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for vercel_project.dev
2023-08-01T02:34:28.898Z [TRACE] evalApplyProvisioners: vercel_project.dev is tainted, so skipping provisioning
2023-08-01T02:34:28.898Z [TRACE] maybeTainted: vercel_project.dev was already tainted, so nothing to do
2023-08-01T02:34:28.898Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for vercel_project.dev
2023-08-01T02:34:28.898Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for vercel_project.dev
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: reading latest snapshot from terraform.tfstate
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: read nil snapshot
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: no original state snapshot to back up
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 1
2023-08-01T02:34:28.898Z [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2023-08-01T02:34:28.900Z [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
Error: -01T02:34:28.900Z [ERROR] vertex "vercel_project.dev" error: Error creating project
2023-08-01T02:34:28.900Z [TRACE] vertex "vercel_project.dev": visit complete, with errors
2023-08-01T02:34:28.900Z [TRACE] dag/walk: upstream of "vercel_project_domain.dev" errored, so skipping
2023-08-01T02:34:28.900Z [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/vercel/vercel\"] (close)" errored, so skipping
2023-08-01T02:34:28.900Z [TRACE] dag/walk: upstream of "root" errored, so skipping
2023-08-01T02:34:28.900Z [TRACE] statemgr.Filesystem: reading latest snapshot from terraform.tfstate
2023-08-01T02:34:28.900Z [TRACE] statemgr.Filesystem: read snapshot with lineage "ea830b2e-2d7c-76cf-b1eb-28d14aaf171a" serial 1
2023-08-01T02:34:28.900Z [TRACE] statemgr.Filesystem: no original state snapshot to back up
2023-08-01T02:34:28.900Z [TRACE] statemgr.Filesystem: no state changes since last snapshot
2023-08-01T02:34:28.900Z [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
╷
│ Error: Error creating project
│ 
│   with vercel_project.dev,
│   on dev.tf line 2, in resource "vercel_project" "dev":
│    2: resource "vercel_project" "dev" {
│ 
│ Could not create project, unexpected error: internal_server_error - An
│ unexpected internal error occurred
╵
2023-08-01T02:34:28.902Z [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2023-08-01T02:34:28.902Z [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
2023-08-01T02:34:28.903Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-08-01T02:34:28.904Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/vercel/vercel/0.15.0/linux_amd64/terraform-provider-vercel_v0.15.0 pid=2046
2023-08-01T02:34:28.904Z [DEBUG] provider: plugin exited
dglsparsons commented 11 months ago

Hi @Nexushunter, thanks for raising this. From a quick glance it's definitely not something you're doing wrong - our service shouldn't be returning an internal server error for you.

I'll have a go at reproducing this and get back to you. Apologies in advance if this takes me a few days - things are very busy at the moment! :)

Nexushunter commented 11 months ago

Thanks for getting back so quick! No problem, I can still use the app to deploy until then!

dglsparsons commented 11 months ago

Hi @Nexushunter - it seems like I'm unable to reproduce this, but I think the issue is related to your Github access.

Internally, this is the error that is occurring:

Error: GitHub fetch error - status: 403, message: {"message":"This installation has been suspended","documentation_url":"https://docs.github.com/rest/reference/apps#create-an-installation-access-token-for-an-app"}

Is your Vercel Account definitely linked to your Github account? And does the Vercel Github App show up in your Github account settings?

Nexushunter commented 11 months ago

I recently removed it. When I use terraform from CI + have the app installed I get double deploys.

I was following https://vercel.com/guides/integrating-terraform-with-vercel#deploy-directly-through-terraform to set up just terraform deploys. Am I misunderstanding the docs?

dglsparsons commented 11 months ago

Right, Vercel still needs the Github connection or it isn't able to read any data from Github. Your project is specifically linked to the Nexushunter/nexushunterdev repository.

If you're creating a deployment by using the vercel_project_directory and vercel_deployment resources, then you may not want to link your Vercel Project to a Github repository at all.

Alternatively, you can set github.enable to false inside a vercel.json file. This will prevent deployments from happening automatically whenever changes are pushed. source.

Hope this clears things up for you 🙏