Terraform-provider-vercel - Terraform Vercel Provider With Golang

Overview

Vercel Terraform Provider

Requirements

  • Terraform 1.1 or higher
  • Go 1.17 (to build the provider plugin)
  • Task v3 (to run Taskfile commands)

Building The Provider

Clone repository locally and run

$ task build

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.17+ is required).

To compile the provider, run task build. This will build the provider and put the provider binary in the repository root.

In addition, you can run task install to set up a developer overrides in your ~/.terraformrc. This will then allow you to use your locally built provider binary.

When you are finished using a local version of the provider, running task uninstall will remove all developer overrides.

Testing

In order to test the provider, you can simply run task test.

Note: This runs acceptance tests that will create real resources. You should expect that the full acceptance test suite will take some time to run.

The acceptance tests require a VERCEL_API_TOKEN (which can be generated here, and a VERCEL_TERRAFORM_TESTING_TEAM (which should be a Vercel team_id where resources can be created and destroyed) environment variable set.

$ task test

In order to run the tests with extra debugging context, prefix with TF_LOG (see the terraform documentation for details).

$ TF_LOG=trace task test

Building The Documentation

The documentation is autogenerated from Description fields within the provider, and the examples directory. Building the documentation generates markdown in the docs folder, ready for deployment to Hashicorp.

Comments
  • Support managing environment variables separately

    Support managing environment variables separately

    Hi,

    I wondered if we'd eventually get a resource that allows us to manage environment variables entirely separately from the vercel_project resource.

    I have multiple environments/terraform directories that look something like this:

    terraform/
    ├─ environments/
    │  ├─ root/
    │  │  ├─ main.tf
    │  │  ├─ (Houses root vercel project)
    │  │  ├─ (Houses overall DNS zones)
    │  │  ├─ (Creates separate aws accounts listed below)
    │  ├─ production/
    │  │  ├─ main.tf
    │  │  ├─ (Contains env specific resources such as DBs, APIs, etc...)
    │  ├─ staging/
    │  │  ├─ main.tf
    │  │  ├─ (Contains env specific resources such as DBs, APIs, etc...)
    

    Now those environment specific resources keys, urls and secrets are not accessible to the root account and I'd like to be able to manage those env vars in the individual terraform environments.

    I've noticed that the chonark vercel package terraform does have this, but it's not maintained anymore.

    opened by Inlustra 12
  • project_environment_variable values should be sensitive

    project_environment_variable values should be sensitive

    Hi,

    I've started to use your provider earlier today and I'm having a few issues and questions.

    My main issue is the difference of behavior between the vercel_project.environment block and the vercel_project_environment_variable resource: the first one marks all values as sensitive (which is good for security) but the later doesn't so I risk having values being output when I don't want them displayed.

    I also find weird having to specify an id is the vercel_project.environment blocks, but I won't be using them as I much prefer having dedicated resources anyway.

    Also, now that this new vercel_project_environment_variable resource exists, not specifying the environment property in a vercel_project shouldn't cause an update of the resource if I never had it specified before: this makes me think that every time I'll update a project property I risk breaking all my env vars and having to re-import them via the vercel_project_environment_variable resources, which I define in different TF runs (kind of like the architecture in #47).


    Update: I tried applying the changes on my project and it did break all the env vars (including those that were defined in the same run using vercel_project_environment_variable resources) as I had feared… I had to re-add all of them.
    This is not OK for a stable deployment process!

    opened by viki53 9
  • Aliases: Add aliases deployment

    Aliases: Add aliases deployment

    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.

    opened by WCMinor 7
  • Can't setup domain for project

    Can't setup domain for project

    Hello guys, very glad that you finally created your own terraform provider ❤️ Trying to set domain for project and getting this error:

    ╷
    │ Error: Error adding domain to project
    │ 
    │   with module.insurance-new.vercel_project_domain.main["texas"],
    │   on modules/vercel-official/main.tf line 89, in resource "vercel_project_domain" "main":
    │   89: resource "vercel_project_domain" "main" {
    │ 
    │ Could not add domain guychecker.com to project prj_JJHr9zb7COBo6APdLbemGopOmWwd, unexpected error: not_found - There is no project for "prj_JJHr9zb7COBo6APdLbemGopOmWwd".
    

    Tried with your free x.vercel.app domain and also tried with one already configured in current Vercel Team even with different setup for nameservers and every time same error.

    Terraform code: Screenshot 2022-04-13 at 16 20 05

    Vercel Team Settings: Screenshot 2022-04-13 at 16 20 23

    bug 
    opened by andreyluchianic 7
  • DNS record errors

    DNS record errors

    Running this terraform code:

    terraform {
      required_version = ">= 1.2.7"
    
      required_providers {
        digitalocean = {
          source  = "digitalocean/digitalocean"
          version = ">= 2.22.1"
        }
        vercel = {
          source  = "vercel/vercel"
          version = ">= 0.7.1"
        }
      }
    
      cloud {
        organization = "syncbase"
    
        workspaces {
          name = "syncbase"
        }
      }
    
    resource "vercel_project" "frontend" {
      name      = "frontend-syncbase"
      framework = "nextjs"
    }
    
    resource "vercel_project_domain" "default" {
      project_id = vercel_project.frontend.id
      domain     = "syncbase.tv"
    }
    
    resource "vercel_dns_record" "a" {
      domain = vercel_project_domain.default.domain
      name   = ""
      type   = "A"
    }
    
    resource "vercel_dns_record" "cname" {
      domain = vercel_project_domain.default.domain
      name   = "www"
      type   = "CNAME"
      value  = vercel_project_domain.default.domain
    }
    

    Raises the following two errors:

    ╷
    │ Error: Provider produced inconsistent result after apply
    │
    │ When applying changes to vercel_dns_record.cname, provider "provider[\"registry.terraform.io/vercel/vercel\"]" produced an unexpected new value: .ttl: was null, but
    │ now cty.NumberIntVal(60).
    │
    │ This is a bug in the provider, which should be reported in the provider's own issue tracker.
    ╵
    ╷
    │ Error: Error creating DNS Record
    │
    │   with vercel_dns_record.a,
    │   on main.tf line 103, in resource "vercel_dns_record" "a":
    │  103: resource "vercel_dns_record" "a" {
    │
    │ Could not create DNS Record, unexpected error: bad_request - Invalid request: missing required property `value`.
    ╵
    

    As stated in the docs: image Both the ttl and value option are optional so they shouldn't need be specified in the terraform configuration

    opened by Axedyson 6
  • vercel_dns_record is not a valid resource type

    vercel_dns_record is not a valid resource type

    Based on the documentation, examples and code it looks like there should be support for the resource type vercel_dns_record yet using this resource type leads to this error:

    The provider vercel/vercel does not support resource type "vercel_dns_record".
    

    Is this a bug or will there soon be support for managing vercel DNS records?

    opened by barsteadr 6
  • SHA1 Mismatch

    SHA1 Mismatch

    Hello,

    I'm trying to use the provider to deploy an app within a monorepo (turborepo).

    Whenever I try to deploy I get into SHA1 mismatches and I can't figure how nor why as there are no reason that the files taken from data.vercel_project_directory would change during the terraform run:

    data "vercel_project_directory" "project" {
      path = "${path.root}/../../../../app/browser"
    }
    
    resource "vercel_project" "project" {
      name      = "awesome"
      framework = "nextjs"
      serverless_function_region = "cdg1"
    
      environment = []
    
      # https://vercel.com/docs/concepts/monorepos/turborepo
      build_command = "cd ../.. && npx turbo run build --filter=browser"
      root_directory = "app/browser"
    }
    
    resource "vercel_deployment" "project" {
      project_id    = vercel_project.project.id
      files              = data.vercel_project_directory.project.files
      path_prefix = 
      production  = true
    }
    

    And then I get:

    Error: Error uploading deployment file
    [1266](?check_suite_focus=true#step:13:1267)
    │ 
    [1267](?check_suite_focus=true#step:13:1268)
    │   with module.platform.module.dashboard.vercel_deployment.project,
    [1268](?check_suite_focus=true#step:13:1269)
    │   on ../../recipes/vercel/main.tf line 16, in resource "vercel_deployment" "project":
    [1269](?check_suite_focus=true#step:13:1270)
    │   16: resource "vercel_deployment" "project" {
    [1270](?check_suite_focus=true#step:13:1271)
    │ 
    [1271](?check_suite_focus=true#step:13:1272)
    │ Could not upload deployment file
    [1272](?check_suite_focus=true#step:13:1273)
    │ ../../../../app/browser/packages/assets/images/bluetooth.svg, unexpected
    [1273](?check_suite_focus=true#step:13:1274)
    │ error: sha1sum_mismatch - SHA1 sum of the file
    [1274](?check_suite_focus=true#step:13:1275)
    │ (9bbe672f3b95401c035390bae38639915358c4f9) doesn't match the provided SHA1
    [1275](?check_suite_focus=true#step:13:1276)
    │ sum (296a875c1282c3f01a361f5f075faf99657d17e4)
    

    I'm using version 0.6.2 of the provider and terraform 1.2.6, and it runs on GitHub actions.

    opened by qpre 5
  • NS Domain Record not supported

    NS Domain Record not supported

    I was able to import a NS record but when I try to run plan I get the following error.

    Item must be one of MX SRV TXT A AAAA ALIAS CAA CNAME, got: NS

    resource "vercel_dns_record" "domainkey" {
      domain  = "b2b.store"
      name    = "e7a7dafdhajdhd"
      type    = "NS"
      ttl     = 60
      value   = "ns.vali.email."
      team_id = "team_d7ahdhah"
    }
    
    opened by DaleLJefferson 5
  • Error: Error adding domain to project

    Error: Error adding domain to project

    Issue 1

    According to the Provider Docs, the team_id is an optional field for the vercel_project_domain resource. However, not including the field results in a mismatch with used team_ids. The Provider attempts to use your personal team_id instead of the team_id associated with the vercel_project_domain's vercel_project.

    Screenshot: Screen Shot 2022-08-24 at 10 58 26

    Code for vercel_project_domain:

    resource "vercel_project" "ecom-storefront" {
      name      = "ecom-storefront-1"
      framework = "nextjs"
      git_repository = {
        type = "github"
        repo = "a-github-repo"
      }
      team_id                    = "a-team-id"
      serverless_function_region = "iad1"
      install_command            = "npm install -g npm-cli-login && npm-cli-login && npm install"
      public_source              = false
      environment = []
    }
    
    resource "vercel_project_domain" "production-domain" {
      project_id = vercel_project.ecom-storefront.id
      domain     = "ecom-storefront-1.vercel.app"
    }
    
    # Define the staging domain (pre-production testing)
    resource "vercel_project_domain" "staging-domain" {
      project_id = vercel_project.ecom-storefront.id
      domain     = "ecom-storefront-staging-1.vercel.app"
      git_branch = "dev"
    }
    

    Steps Taken to Debug:

    1. Verify terraform fmt -check
    2. Verify terraform validate
    3. Verify latest Provider version (using ~> 0.7.1)

    Details from terraform version:

    Terraform v1.2.6
    on darwin_amd64
    + provider registry.terraform.io/hashicorp/aws v4.27.0
    + provider registry.terraform.io/vercel/vercel v0.7.1
    

    Issue 2

    Ideally, vercel_project_domain resources should be able to be specified, even if they are implied Vercel defaults. Adding a vercel_project_domain that has a domain that matches its associated vercel_project.name triggers an error that the domain already belongs to a "different project", even though the error's "project_id" matches the desired vercel_project.

    Screenshot: Screen Shot 2022-08-24 at 11 12 14

    Code for vercel_project_domain:

    resource "vercel_project" "ecom-storefront" {
      name      = "ecom-storefront-1"
      framework = "nextjs"
      git_repository = {
        type = "github"
        repo = "a-github-repo"
      }
      team_id                    = "a-team-id"
      serverless_function_region = "iad1"
      install_command            = "npm install -g npm-cli-login && npm-cli-login && npm install"
      public_source              = false
      environment = []
    }
    
    resource "vercel_project_domain" "production-domain" {
      project_id = vercel_project.ecom-storefront.id
      team_id    = "a-team-id"
      domain     = "ecom-storefront-1.vercel.app"
    }
    

    Steps Taken to Debug:

    1. Verify terraform fmt -check
    2. Verify terraform validate
    3. Verify latest Provider version (using ~> 0.7.1)

    Details from terraform version:

    Terraform v1.2.6
    on darwin_amd64
    + provider registry.terraform.io/hashicorp/aws v4.27.0
    + provider registry.terraform.io/vercel/vercel v0.7.1
    
    opened by taylorsteiger-rad 4
  • Unexpected recreation of domain when adding env variables to vercel project

    Unexpected recreation of domain when adding env variables to vercel project

    When we added a new environment variable, I saw that the project domain must be replaced. Just want to double check that this is an expected behaviour.

    Terraform will perform the following actions:
    
      # vercel_project.web will be updated in-place
      ~ resource "vercel_project" "web" {
          + environment    = [
              + {
                  + id     = (known after apply)
                  + key    = "NEXT_PUBLIC_APP_CHECK_RECAPTCHAV3"
                  + target = [
                      + "production",
                    ]
                  + value  = (sensitive value)
                }
            ]
          ~ id             = "prj_XYZ" -> (known after apply)
            name           = "web"
            # (5 unchanged attributes hidden)
        }
    
      # vercel_project_domain.web_dev must be replaced
    -/+ resource "vercel_project_domain" "web_dev" {
          ~ id         = "id_XYZ" -> (known after apply)
          ~ project_id = "prj_XYZ" -> (known after apply) # forces replacement
            # (3 unchanged attributes hidden)
        }
    
    opened by cungminh2710 4
  • GitSource: added git source deployment

    GitSource: added git source deployment

    Followed the API documentation https://vercel.com/docs/rest-api#endpoints/deployments/create-a-new-deployment

    This PR makes able the deployment from Git Source avoiding the need of upload the files to Vercel.

    It works passing a new parameter called git_source, it is a map and it looks like this:

    resource "vercel_deployment" "deployment" {
      team_id = var.vercel_team_id
      project_id = var.vercel_project_id
      git_source = {
        ref = var.git_branch
        repo_id = var.fe_github_repo_id
        type = "github"
      }
    }
    

    Here is an example of output, it just works:

    vercel_deployment.deployment: Creating...
    vercel_deployment.deployment: Still creating... [10s elapsed]
    vercel_deployment.deployment: Still creating... [20s elapsed]
    vercel_deployment.deployment: Still creating... [30s elapsed]
    vercel_deployment.deployment: Still creating... [40s elapsed]
    vercel_deployment.deployment: Still creating... [50s elapsed]
    vercel_deployment.deployment: Still creating... [1m0s elapsed]
    vercel_deployment.deployment: Creation complete after 1m6s [id=dpl_EQBQgeWeo5PXesr1MLSjrQC9MRrZ]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
    
    opened by WCMinor 4
  • [feature] vercel_deployment data source

    [feature] vercel_deployment data source

    Hi,

    I have started moving my team's existing (created by hand before my arrival for the most part) infra to Terraform recently and am encountering a blockage due to some missing data sources in this provider.

    For context, I would like to manage some CNAME DNS records (directly on Cloudflare — or maybe some other provider in the future —, to avoid having to manage them on Vercel) during a dedicated run but can't seem to find a way to retrieve the generated domains assigned to various deployments (staging/development and production in this case) using data sources.

    Note: I am already using vercel_deployment resources to create those deployments, but in a different run that only manages the Vercel resource. Hence the need for a data source to retrieve the info in this new run.

    Is there a way to get the domain for specific deployments (ideally using a git_branch param or something like this) currently or would that be by creating this data source?

    opened by viki53 3
Releases(v0.10.1)
Owner
Vercel
Develop. Preview. Ship. Creators of Next.js.
Vercel
Terraform-provider-buddy - Terraform Buddy provider For golang

Terraform Provider for Buddy Documentation Requirements Terraform >= 1.0.11 Go >

Buddy 1 Jan 5, 2022
Terraform-provider-age - Age Terraform Provider with golang

Age Terraform Provider This provider lets you generate an Age key pair. Using th

ConsenSys Software 0 Feb 15, 2022
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)

terraform-provider-awsutils Terraform provider for performing various tasks that cannot be performed with the official AWS Terraform Provider from Has

Cloud Posse 22 Aug 26, 2022
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager) Version 2.x of the AzureRM Provider requires Terraform 0.12.x and later, but 1.0 is recommended. Terra

null 0 Oct 16, 2021
Terraform-provider-mailcow - Terraform provider for Mailcow

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository i

Owen Valentine 0 Dec 31, 2021
🚥 See the status of your vercel deployments on the pimoroni blinkt!

verpi ?? See the status of your vercel deployments on the pimoroni blinkt! verpi ?? Demo ?? Setup your own version ?? Getting the parts ?? Install the

Matt Gleich 33 May 22, 2022
kube-champ 42 Sep 22, 2022
Terraform-in-Terraform: Execute Modules directly from the Terraform Registry

Terraform-In-Terraform Provider This provider allows running Terraform in Terraform. This might seem insane but there are some edge cases where it com

WeakPixel 39 Aug 31, 2022
Terraform utility provider for constructing bash scripts that use data from a Terraform module

Terraform Bash Provider This is a Terraform utility provider which aims to robustly generate Bash scripts which refer to data that originated in Terra

Martin Atkins 33 Sep 6, 2022
Quick start repository for creating a Terraform provider using terraform-plugin-framework

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

HashiCorp 52 Sep 20, 2022
Terraform Provider Scaffolding (Terraform Plugin SDK)

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository is built on the Terraform Plugin SDK. The template repository built on

Brian Flad 0 Feb 8, 2022
OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)

Terraform Provider OpenAPI This terraform provider aims to minimise as much as possible the efforts needed from service providers to create and mainta

Daniel I. Khan Ramiro 218 Sep 14, 2022
Hashicups-tf-provider - HashiCups Terraform Provider Tutorial

Terraform Provider HashiCups Run the following command to build the provider go

Andrew Xie 1 Jan 10, 2022
Terraform-house - Golang Based terraform automation example using tf.json

Terraform House Manage your own terraform workflow using go language, with the b

Bayu Rizky Ramadhan 0 Feb 17, 2022
Terraform provider statuscake with golang

terraform-provider-statuscake Requirements Terraform >= 0.13.x Go >= 1.15 Building The Provider Clone the repository Enter the repository directory Bu

Ackama 1 Oct 11, 2021
Terraform provider nuage with golang

Terraform Provider Nuage Nuage provider based on Terraform Provider Hashicups Build provider Run the following command to build the provider $ go buil

Kevin Masseix 5 Aug 29, 2022
Terraform Provider Pulumi for golang

Terraform Provider Pulumi This is the transcend-io/pulumi provider available on the Terraform registry. It's goal is to allow terraform projects to co

Transcend 12 Sep 1, 2022
Terraform provider canvaslms for golang

Clone provider from github git clone https://github.com/sigurdkb/terraform-provider-canvaslms.git Build provider cd terraform-provider-canvaslms go i

Sigurd Brinch 0 Jan 4, 2022
Terraform-grafana-dashboard - Grafana dashboard Terraform module

terraform-grafana-dashboard terraform-grafana-dashboard for project Requirements

hadenlabs 1 May 2, 2022