metaforecast/tf/main.tf

90 lines
2.0 KiB
Terraform
Raw Normal View History

2022-04-11 18:03:47 +00:00
terraform {
required_providers {
2022-04-11 20:44:23 +00:00
# official vercel/vercel provider seems less stable
2022-04-11 18:03:47 +00:00
vercel = {
2022-04-11 20:44:23 +00:00
source = "registry.terraform.io/chronark/vercel"
version = ">=0.10.3"
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
2022-04-11 18:03:47 +00:00
}
2022-04-11 21:32:34 +00:00
heroku = {
source = "heroku/heroku"
version = "~> 5.0.2"
}
2022-04-11 19:38:00 +00:00
local = {
source = "hashicorp/local"
version = "~> 2"
}
2022-04-11 18:03:47 +00:00
}
}
provider "vercel" {
2022-04-11 20:44:23 +00:00
token = var.vercel_api_token
}
provider "digitalocean" {
token = var.digital_ocean_token
}
2022-04-11 21:32:34 +00:00
provider "heroku" {
email = var.heroku_email
2022-04-11 21:32:34 +00:00
api_key = var.heroku_api_key
}
2022-04-11 20:44:23 +00:00
resource "digitalocean_database_cluster" "metaforecast_db" {
name = "postgres-green"
engine = "pg"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
version = 14
2022-04-11 18:03:47 +00:00
}
2022-04-11 21:32:34 +00:00
locals {
generated_env = merge(var.metaforecast_env, {
# should we bring proper DO certificates to prod instead?
DIGITALOCEAN_POSTGRES = replace(digitalocean_database_cluster.metaforecast_db.uri, "/\\?sslmode=require$/", "")
2022-04-11 21:32:34 +00:00
})
}
resource "heroku_app" "metaforecast_backend" {
name = "metaforecast-backend"
region = "us"
config_vars = local.generated_env
}
2022-04-11 19:38:00 +00:00
resource "vercel_project" "metaforecast" {
name = "metaforecast"
team_id = var.vercel_team
framework = "nextjs"
2022-04-11 18:03:47 +00:00
2022-04-11 20:44:23 +00:00
git_repository {
2022-04-11 18:03:47 +00:00
type = "github"
2022-04-12 08:01:55 +00:00
repo = "quantified-uncertainty/metaforecast"
2022-04-11 18:03:47 +00:00
}
2022-04-11 20:44:23 +00:00
domain {
name = "metaforecast.org"
}
2022-04-11 18:03:47 +00:00
}
2022-04-11 19:38:00 +00:00
2022-04-11 20:44:23 +00:00
resource "vercel_env" "metaforecast" {
2022-04-11 19:38:00 +00:00
project_id = vercel_project.metaforecast.id
2022-04-11 20:44:23 +00:00
team_id = var.vercel_team
type = "plain"
2022-04-11 21:32:34 +00:00
for_each = local.generated_env
2022-04-11 20:44:23 +00:00
key = each.key
value = each.value
target = ["preview", "production"]
2022-04-11 19:38:00 +00:00
}
2022-04-11 20:44:23 +00:00
# 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"
# }