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 { terraform {
required_providers { required_providers {
# official vercel/vercel provider seems less stable
vercel = { vercel = {
source = "vercel/vercel" source = "registry.terraform.io/chronark/vercel"
version = "~> 0.1" version = ">=0.10.3"
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
} }
local = { local = {
source = "hashicorp/local" source = "hashicorp/local"
@ -12,37 +17,58 @@ terraform {
} }
provider "vercel" { 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" { resource "vercel_project" "metaforecast" {
name = "metaforecast" name = "metaforecast"
team_id = "quantified-uncertainty" team_id = var.vercel_team
framework = "nextjs"
environment = [ git_repository {
for k, v in var.metaforecast_env : {
key = k
value = v
target = ["production"]
}
]
git_repository = {
type = "github" type = "github"
repo = "QURIresearch/metaforecast" repo = "QURIresearch/metaforecast"
} }
domain {
name = "metaforecast.org"
}
} }
resource "vercel_project_domain" "metaforecast" { resource "vercel_env" "metaforecast" {
project_id = vercel_project.metaforecast.id project_id = vercel_project.metaforecast.id
domain = "metaforecast.org" team_id = var.vercel_team
team_id = "quantified-uncertainty" 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 "vercel_env" "metaforecast_db" {
resource "local_file" "foo" { project_id = vercel_project.metaforecast.id
content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"])) team_id = var.vercel_team
filename = "${path.module}/../.env.prod" type = "plain"
file_permission = "0644" 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" { variable "vercel_api_token" {
type = string type = string
} }
variable "digital_ocean_token" {
type = string
}
variable "vercel_team" {
type = string
default = "quantified-uncertainty"
}
variable "metaforecast_env" {
type = map(string)
}