Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sanctuary db and user resources to terraform #106

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/api/.env-example
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=testpass
POSTGRES_SANCTUARY_USER=sanctuary_user
POSTGRES_SANCTUARY_PASSWORD=sanctuary_testpass
POSTGRES_HOST=localhost
POSTGRES_DB=example
POSTGRES_SANCTUARY_DB=sanctuary-example
POSTGRES_PORT=5432
SECRET_KEY=space-pants
MIN_PASSWORD_LEN=8
Expand Down
10 changes: 10 additions & 0 deletions operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ in "config.gcs.tfbackend".
4. Run "terraform init" if using ENV variables, or "terraform init -backend-config=config.gcs.tfbackend"
if providing variables in that file, followed by "terraform plan" and "terraform apply".
Terraform should move the state files to the storage bucket.

### Additional terraform changes

To apply new changes to the infrastructure you need to ensure that Terraform finds the state file located in the storage bucket.

- Make sure you have the correct project selected:
- `gcloud config get-value project` to view current project.
- `gcloud config set project PROJECT_ID` to select project.
- Initialize terraform with `terraform init` or `terraform init -backend-config="bucket=name_of_bucket" -backend-config="prefix=path/of/state/file"` if terraform cannot find the state file.
- Run `terraform plan` to view changes and then `terraform apply`
27 changes: 27 additions & 0 deletions operations/infra/application/cloud_run.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,32 @@ resource "google_sql_database_instance" "db-instance" {
}
}

# Medical database
resource "google_sql_database" "database" {
name = local.POSTGRES_DB
instance = "${google_sql_database_instance.db-instance.name}"
}

# Medical db user
resource "google_sql_user" "users" {
instance = "${google_sql_database_instance.db-instance.name}"
name = local.POSTGRES_USER
password = var.POSTGRES_PASSWORD
}

# Sanctuary database
resource "google_sql_database" "sanctuary_database" {
name = local.POSTGRES_SANCTUARY_DB
instance = "${google_sql_database_instance.db-instance.name}"
}

# Sanctuary db user
resource "google_sql_user" "sanctuary_user" {
instance = "${google_sql_database_instance.db-instance.name}"
name = local.POSTGRES_SANCTUARY_USER
password = var.POSTGRES_SANCTUARY_PASSWORD
}

#cloudrun service for the web container
resource "google_cloud_run_service" "web" {
name = "project-ct"
Expand Down Expand Up @@ -79,17 +94,29 @@ resource "google_cloud_run_service" "api" {
name = "POSTGRES_USER"
value = local.POSTGRES_USER
}
env {
name = "POSTGRES_SANCTUARY_USER"
value = local.POSTGRES_SANCTUARY_USER
}
env {
name = "POSTGRES_PASSWORD"
value = var.POSTGRES_PASSWORD
}
env {
name = "POSTGRES_SANCTUARY_PASSWORD"
value = var.POSTGRES_SANCTUARY_PASSWORD
}
env {
name = "POSTGRES_HOST"
value = var.POSTGRES_HOST
}
env {
name = "POSTGRES_DB"
value = local.POSTGRES_DB
}
env {
name = "POSTGRES_DB"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? or should it be POSTGRES_SANCTUARY_DB

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to break production we would keep it as is.

value = local.POSTGRES_SANCTUARY_DB
}
env {
name = "POSTGRES_PORT"
Expand Down
2 changes: 2 additions & 0 deletions operations/infra/application/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ resource "google_storage_bucket" "storage_bucket" {
#See operations/README
terraform {
backend "gcs" {
bucket = "project-ct-beta-app-sb"
prefix = "terraform/state"
}
}
3 changes: 3 additions & 0 deletions operations/infra/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ locals {
GAR_location = "${ var.region }-docker.pkg.dev/${ var.project_id }/"
service_account = "${ var.project_id }-deploy-sa"
POSTGRES_DB = "${var.project_id}-db"
POSTGRES_SANCTUARY_DB = "${var.project_id}-sanctuary-db"
POSTGRES_USER = "${var.project_id}-db-user"
POSTGRES_SANCTUARY_USER = "${var.project_id}-sanctuary-db-user"
ARTIFACT_TAG = "prod"
}
variable "POSTGRES_PASSWORD" {}
variable "POSTGRES_SANCTUARY_PASSWORD" {}
variable "POSTGRES_HOST" {}
variable "POSTGRES_PORT" {}
variable "SECRET_KEY" {}
Expand Down
Loading