From bfbc573c4f187c1edafa5be25e502418f8cd54c2 Mon Sep 17 00:00:00 2001 From: Daniel Winther Date: Tue, 3 May 2022 21:12:22 +0200 Subject: [PATCH] feat: extract db ca from terraform for shared databases (#26) * feat: export db ca from terraform #24 * fix: expose db ca for shared databases * chore: fix typo in comment --- docs/Develop_GettingStarted.md | 3 +-- scripts/lib/render-projects.ts | 4 ++-- templates/terraform/db.hbs | 4 ++++ templates/terraform/project_main.hbs | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/Develop_GettingStarted.md b/docs/Develop_GettingStarted.md index 5c0fe3c..66411f3 100644 --- a/docs/Develop_GettingStarted.md +++ b/docs/Develop_GettingStarted.md @@ -32,11 +32,10 @@ Major libraries used: ## Structure -- `bin/` - contains all the scripts -- `lib/` - all common code used by the scripts - `docs/` - the documentation - `kubernetes/` - all rendered Kubernetes resources. Is automatically created by the scripts. - `projects/` - this is the central part for project definitions and the source for all files generated in this repo. To provision a new project a new folder is added here. This is basically the only thing that should be modified by non-contributors. +- `scripts/` - contains all the scripts - `templates/` - all Handlebars templates grouped by category - `terraform/` - rendered Terraform files and modules that is used to manage infrastructure - `users/` - a list of all unique users currently in use in all the projects diff --git a/scripts/lib/render-projects.ts b/scripts/lib/render-projects.ts index 6196768..277f8e1 100644 --- a/scripts/lib/render-projects.ts +++ b/scripts/lib/render-projects.ts @@ -124,8 +124,8 @@ export const renderProjects = ( }); }); - // Render terraform for stages - stages.forEach((stage, index) => { + // Render projects for stages + stages.forEach((stage) => { console.log(`Rendering templates for stage ${stage}...`); const context = { ...resources[stage], diff --git a/templates/terraform/db.hbs b/templates/terraform/db.hbs index 96edb2f..a2ff435 100644 --- a/templates/terraform/db.hbs +++ b/templates/terraform/db.hbs @@ -6,3 +6,7 @@ resource "digitalocean_database_cluster" "{{stage}}-shared" { region = var.region node_count = 1 } + +data "digitalocean_database_ca" "{{stage}}-db-ca" { + cluster_id = digitalocean_database_cluster.{{stage}}-shared.id +} diff --git a/templates/terraform/project_main.hbs b/templates/terraform/project_main.hbs index a4ce2a5..13cab00 100644 --- a/templates/terraform/project_main.hbs +++ b/templates/terraform/project_main.hbs @@ -56,6 +56,7 @@ output "project__{{tfName}}" { port: digitalocean_database_cluster.{{stage}}-shared.port host: digitalocean_database_cluster.{{stage}}-shared.host private_host: digitalocean_database_cluster.{{stage}}-shared.private_host + ca: data.digitalocean_database_ca.{{stage}}-db-ca.certificate }) } shared_databases_users = {