From 5f19ff1c98f0f5443ce7b9b85bef05224e05d59c Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 11 Apr 2022 22:38:00 +0300 Subject: [PATCH] ops: domain, .env generator --- tf/.gitignore | 1 + tf/main.tf | 33 ++++++++++++++++++++++++--------- tf/variables.tf | 7 +++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 tf/variables.tf diff --git a/tf/.gitignore b/tf/.gitignore index 3fd4f08..3e4aae0 100644 --- a/tf/.gitignore +++ b/tf/.gitignore @@ -1,2 +1,3 @@ /*.tfstate* /.terraform* +/prod.tfvars diff --git a/tf/main.tf b/tf/main.tf index 17f4a71..cad41c0 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -4,30 +4,45 @@ terraform { source = "vercel/vercel" version = "~> 0.1" } + local = { + source = "hashicorp/local" + version = "~> 2" + } } } provider "vercel" { - # Or omit this for the api_token to be read - # from the VERCEL_API_TOKEN environment variable - # api_token = var.vercel_api_token + api_token = var.vercel_api_token } -resource "vercel_project" "with_git" { - name = "metaforecast-test" +resource "vercel_project" "metaforecast" { + name = "metaforecast" team_id = "quantified-uncertainty" framework = "nextjs" environment = [ - { - key = "NEXT_PUBLIC_ALGOLIA_APP_ID" - value = "96UD3NTQ7L" + for k, v in var.metaforecast_env : { + key = k + value = v target = ["production"] } ] git_repository = { type = "github" - repo = "berekuk/metaforecast" + repo = "QURIresearch/metaforecast" } } + +resource "vercel_project_domain" "metaforecast" { + project_id = vercel_project.metaforecast.id + domain = "metaforecast.org" + team_id = "quantified-uncertainty" +} + +// 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" +} diff --git a/tf/variables.tf b/tf/variables.tf new file mode 100644 index 0000000..bf3b7fd --- /dev/null +++ b/tf/variables.tf @@ -0,0 +1,7 @@ +variable "metaforecast_env" { + type = map(string) +} + +variable "vercel_api_token" { + type = string +}