ops: DO, new vercel provider

This commit is contained in:
Vyacheslav Matyukhin 2022-04-11 23:44:23 +03:00
parent 5f19ff1c98
commit bf08d04862
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
2 changed files with 62 additions and 27 deletions

View File

@ -1,8 +1,13 @@
terraform {
required_providers {
# official vercel/vercel provider seems less stable
vercel = {
source = "vercel/vercel"
version = "~> 0.1"
source = "registry.terraform.io/chronark/vercel"
version = ">=0.10.3"
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
local = {
source = "hashicorp/local"
@ -12,37 +17,58 @@ terraform {
}
provider "vercel" {
api_token = var.vercel_api_token
token = var.vercel_api_token
}
provider "digitalocean" {
token = var.digital_ocean_token
}
resource "digitalocean_database_cluster" "metaforecast_db" {
name = "postgres-green"
engine = "pg"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
version = 14
}
resource "vercel_project" "metaforecast" {
name = "metaforecast"
team_id = "quantified-uncertainty"
framework = "nextjs"
name = "metaforecast"
team_id = var.vercel_team
environment = [
for k, v in var.metaforecast_env : {
key = k
value = v
target = ["production"]
}
]
git_repository = {
git_repository {
type = "github"
repo = "QURIresearch/metaforecast"
}
domain {
name = "metaforecast.org"
}
}
resource "vercel_project_domain" "metaforecast" {
resource "vercel_env" "metaforecast" {
project_id = vercel_project.metaforecast.id
domain = "metaforecast.org"
team_id = "quantified-uncertainty"
team_id = var.vercel_team
type = "plain"
for_each = var.metaforecast_env
key = each.key
value = each.value
target = ["preview", "production"]
}
// should probably be replaced with local bash script
resource "local_file" "foo" {
content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"]))
filename = "${path.module}/../.env.prod"
file_permission = "0644"
resource "vercel_env" "metaforecast_db" {
project_id = vercel_project.metaforecast.id
team_id = var.vercel_team
type = "plain"
key = "DIGITALOCEAN_POSTGRES"
value = digitalocean_database_cluster.metaforecast_db.uri
target = ["preview", "production"]
}
# should probably be replaced with local bash script
# resource "local_file" "foo" {
# content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"]))
# filename = "${path.module}/../.env.prod"
# file_permission = "0644"
# }

View File

@ -1,7 +1,16 @@
variable "metaforecast_env" {
type = map(string)
}
variable "vercel_api_token" {
type = string
}
variable "digital_ocean_token" {
type = string
}
variable "vercel_team" {
type = string
default = "quantified-uncertainty"
}
variable "metaforecast_env" {
type = map(string)
}