From 860fc1eb7037e692ebcba8723587c1230c7cb3fa Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 00:32:34 +0300 Subject: [PATCH] ops: heroku --- tf/main.tf | 33 +++++++++++++++++++++++---------- tf/variables.tf | 4 ++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tf/main.tf b/tf/main.tf index 4b99bf0..69029a7 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -9,6 +9,10 @@ terraform { source = "digitalocean/digitalocean" version = "~> 2.0" } + heroku = { + source = "heroku/heroku" + version = "~> 5.0.2" + } local = { source = "hashicorp/local" version = "~> 2" @@ -24,6 +28,11 @@ 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" @@ -33,6 +42,19 @@ resource "digitalocean_database_cluster" "metaforecast_db" { 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 @@ -51,21 +73,12 @@ resource "vercel_env" "metaforecast" { project_id = vercel_project.metaforecast.id team_id = var.vercel_team type = "plain" - for_each = var.metaforecast_env + for_each = local.generated_env key = each.key value = each.value target = ["preview", "production"] } -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"])) diff --git a/tf/variables.tf b/tf/variables.tf index d42020d..fc652ce 100644 --- a/tf/variables.tf +++ b/tf/variables.tf @@ -6,6 +6,10 @@ variable "digital_ocean_token" { type = string } +variable "heroku_api_key" { + type = string +} + variable "vercel_team" { type = string default = "quantified-uncertainty"