metaforecast/tf/main.tf
2022-04-12 11:01:55 +03:00

88 lines
1.9 KiB
HCL

terraform {
required_providers {
# official vercel/vercel provider seems less stable
vercel = {
source = "registry.terraform.io/chronark/vercel"
version = ">=0.10.3"
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
heroku = {
source = "heroku/heroku"
version = "~> 5.0.2"
}
local = {
source = "hashicorp/local"
version = "~> 2"
}
}
}
provider "vercel" {
token = var.vercel_api_token
}
provider "digitalocean" {
token = var.digital_ocean_token
}
provider "heroku" {
email = "me@berekuk.ru"
api_key = var.heroku_api_key
}
resource "digitalocean_database_cluster" "metaforecast_db" {
name = "postgres-green"
engine = "pg"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
version = 14
}
locals {
generated_env = merge(var.metaforecast_env, {
DIGITALOCEAN_POSTGRES = digitalocean_database_cluster.metaforecast_db.uri
})
}
resource "heroku_app" "metaforecast_backend" {
name = "metaforecast-backend"
region = "us"
config_vars = local.generated_env
}
resource "vercel_project" "metaforecast" {
name = "metaforecast"
team_id = var.vercel_team
git_repository {
type = "github"
repo = "quantified-uncertainty/metaforecast"
}
domain {
name = "metaforecast.org"
}
}
resource "vercel_env" "metaforecast" {
project_id = vercel_project.metaforecast.id
team_id = var.vercel_team
type = "plain"
for_each = local.generated_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"
# }