Skip to content

Commit 9568eb6

Browse files
committed
feat: add api db
1 parent cc2caa2 commit 9568eb6

File tree

13 files changed

+146
-120
lines changed

13 files changed

+146
-120
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ repos:
2323
- --args=--path=./terraform
2424
verbose: true
2525
- id: terraform_fmt
26-
- id: terraform_validate
26+
# - id: terraform_validate

terraform/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json
22
TF_VAR_bucket_name=bucket-name-to-store-tfstate
33
TF_VAR_project_id=name-of-gcp-project
4-
TF_VAR_sql_ckan_production_user_password=password-to-ckan-production-user
5-
TF_VAR_sql_ckan_staging_user_password=password-to-ckan-stagin-user
64
TF_VAR_sql_id_server_user_password=password-to-id-server-user
75
TF_VAR_sql_metabase_user_password=password-to-metabase-user
6+
TF_VAR_sql_passbolt_user_password=password-to-passbolt-user
87
TF_VAR_sql_prefect_user_password=password-to-prefect-user

terraform/cloud_sql/.terraform.lock.hcl

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/cloud_sql/main.tf

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
# ...........................................................................
2+
# Create Random Data
3+
# https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id
4+
# ...........................................................................
15
resource "random_id" "db_name_suffix" {
26
byte_length = 4
37
}
48

9+
resource "random_password" "api_staging_db_password" {
10+
length = 22
11+
special = true
12+
override_special = "!#$%&*()-_=+[]{}<>:?"
13+
}
14+
15+
# ...........................................................................
16+
# Write data to Secret Manager
17+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/secret_manager_secret
18+
# ...........................................................................
19+
resource "google_secret_manager_secret" "api_staging_db_password" {
20+
secret_id = "api-staging-db-password"
21+
22+
replication {
23+
automatic = true
24+
}
25+
}
26+
27+
resource "google_secret_manager_secret_version" "api_staging_db_password" {
28+
secret = google_secret_manager_secret.api_staging_db_password.id
29+
secret_data = random_password.api_staging_db_password.result
30+
}
31+
32+
# ...........................................................................
33+
# Create Cloud SQL
34+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance
35+
# ...........................................................................
536
resource "google_sql_database_instance" "main" {
637
name = "${var.project_id}-${random_id.db_name_suffix.hex}"
738
region = var.region
@@ -31,26 +62,20 @@ resource "google_sql_database_instance" "main" {
3162
}
3263
}
3364

34-
resource "google_sql_user" "ckan_production" {
35-
name = var.sql_ckan_production_user_name
36-
instance = google_sql_database_instance.main.name
37-
password = var.sql_ckan_production_user_password
38-
}
39-
40-
resource "google_sql_database" "ckan_production" {
41-
name = var.sql_ckan_production_db_name
42-
instance = google_sql_database_instance.main.name
43-
}
44-
45-
resource "google_sql_user" "ckan_staging" {
46-
name = var.sql_ckan_staging_user_name
65+
# ...........................................................................
66+
# Create Cloud SQL Databases and Users
67+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database
68+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_user
69+
# ...........................................................................
70+
resource "google_sql_database" "api_staging" {
71+
name = var.sql_api_staging_db_name
4772
instance = google_sql_database_instance.main.name
48-
password = var.sql_ckan_staging_user_password
4973
}
5074

51-
resource "google_sql_database" "ckan_staging" {
52-
name = var.sql_ckan_staging_db_name
75+
resource "google_sql_user" "api_staging" {
76+
name = var.sql_api_staging_user_name
5377
instance = google_sql_database_instance.main.name
78+
password = random_password.api_staging_db_password.result
5479
}
5580

5681
resource "google_sql_database" "id_server" {
@@ -61,7 +86,7 @@ resource "google_sql_database" "id_server" {
6186
resource "google_sql_user" "id_server" {
6287
name = var.sql_id_server_user_name
6388
instance = google_sql_database_instance.main.name
64-
password = var.sql_ckan_production_user_password
89+
password = var.sql_id_server_user_password
6590
}
6691

6792
resource "google_sql_user" "metabase" {

terraform/cloud_sql/variables.tf

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,16 @@ variable "sql_db_max_connections" {
6969
description = "The maximum number of connections for the Cloud SQL instance."
7070
}
7171

72-
variable "sql_ckan_production_user_name" {
72+
variable "sql_api_staging_user_name" {
7373
type = string
74-
description = "The name of the CKAN production database user."
75-
default = "ckan_production"
74+
description = "The name of the API staging database user."
75+
default = "api_staging"
7676
}
7777

78-
variable "sql_ckan_production_user_password" {
78+
variable "sql_api_staging_db_name" {
7979
type = string
80-
description = "The password of the CKAN production database user."
81-
sensitive = true
82-
}
83-
84-
variable "sql_ckan_production_db_name" {
85-
type = string
86-
description = "The name of the CKAN production database."
87-
default = "ckan_production"
88-
}
89-
90-
variable "sql_ckan_staging_user_name" {
91-
type = string
92-
description = "The name of the CKAN staging database user."
93-
default = "ckan_staging"
94-
}
95-
96-
variable "sql_ckan_staging_user_password" {
97-
type = string
98-
description = "The password of the CKAN staging user."
99-
sensitive = true
100-
}
101-
102-
variable "sql_ckan_staging_db_name" {
103-
type = string
104-
description = "The name of the CKAN staging database."
105-
default = "ckan_staging"
80+
description = "The name of the API staging database."
81+
default = "api_staging"
10682
}
10783

10884
variable "sql_id_server_user_name" {

terraform/cloud_sql_mysql/.terraform.lock.hcl

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/gke/.terraform.lock.hcl

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/iam/.terraform.lock.hcl

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/iam/bindings/.terraform.lock.hcl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/iam/bindings/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Add IAM policy binding for Cloud SQL SA
2-
resource "google_project_iam_member" "cloudsql" {
3-
project = var.project_id
4-
role = "roles/cloudsql.client"
5-
member = "serviceAccount:${var.gsa-cloudsql.email}"
6-
}
2+
# resource "google_project_iam_member" "cloudsql" {
3+
# project = var.project_id
4+
# role = "roles/cloudsql.client"
5+
# member = "serviceAccount:${var.gsa-cloudsql.email}"
6+
# }
77

88
# Allow the Kubernetes service account to impersonate the Google
99
# service account by creating an IAM policy binding between the

0 commit comments

Comments
 (0)