Skip to content

Commit d5ae586

Browse files
authored
Merge pull request #14399 from MinaProtocol/steven-ci-metrics
This test currently passes all required CI tests, with the exception of `versioned type linter`. This test fails due to an error of the test and does not relate to eh code in the PR. Linter error = `FileNotFoundError: [Errno 2] No such file or directory: '-type_shape.txt'` Full buildkite build details: https://buildkite.com/o-1-labs-2/mina-o-1-labs/builds/31230
2 parents 56a2ea8 + 8a52589 commit d5ae586

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Google Cloud Postgres Deployment
2+
3+
This terraform configuration is used to deploy an instance of Google Cloud Postgres. Although the default configuration works without creating a conflict, it is recommended to deploy the postgres instance as a module within a larger terraform deployment (which passes it unique var values).
4+
5+
The default configuration uses Google Secret Manager to pull in a password for the default `postgres` user. After deployment, the assigned IP addresses, username, and password will be printed to the terminal as shown below:
6+
7+
```
8+
Outputs:
9+
10+
cloud_postgres_ip = tolist([
11+
{
12+
"ip_address" = "35.35.35.35" <---- example IP
13+
"time_to_retire" = ""
14+
"type" = "PRIMARY"
15+
},
16+
{
17+
"ip_address" = "34.34.34.34" <---- example IP
18+
"time_to_retire" = ""
19+
"type" = "OUTGOING"
20+
},
21+
])
22+
db_password = "PASSWORD_HERE"
23+
db_user = "postgres"
24+
```
25+
26+
The `PRIMARY` IP should be used when connecting to the new instance. By default, not database or schema is defined on the newly deployed db.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Configure the Google Cloud provider
2+
provider "google" {
3+
project = var.gcp_project
4+
region = var.gcp_region
5+
}
6+
7+
resource "random_id" "instance_id" {
8+
byte_length = 4
9+
}
10+
11+
data "google_secret_manager_secret_version" "db_password" {
12+
provider = google
13+
secret = var.db_pass
14+
}
15+
16+
# Create a Google Cloud SQL PostgreSQL instance
17+
resource "google_sql_database_instance" "postgres_instance" {
18+
name = "${var.db_name}-${random_id.instance_id.hex}"
19+
database_version = var.postgres_version
20+
project = var.gcp_project
21+
region = var.gcp_region
22+
settings {
23+
tier = var.db_spec
24+
user_labels = {
25+
service = var.service_label
26+
}
27+
}
28+
deletion_protection = var.deletion_protection
29+
}
30+
31+
# Define the database user
32+
resource "google_sql_user" "database_user" {
33+
name = var.db_user
34+
instance = google_sql_database_instance.postgres_instance.name
35+
password = data.google_secret_manager_secret_version.db_password.secret_data
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
output "cloud_postgres_ip" {
2+
value = google_sql_database_instance.postgres_instance.ip_address
3+
}
4+
5+
output "db_user" {
6+
value = google_sql_user.database_user.name
7+
}
8+
9+
output "db_password" {
10+
value = data.google_secret_manager_secret_version.db_password.secret_data
11+
}
12+
13+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "gcp_project" {
2+
default = "o1labs-192920"
3+
}
4+
5+
variable "gcp_region" {
6+
default = "us-east4"
7+
}
8+
9+
variable "gcp_zone" {
10+
default = "us-east4-b"
11+
}
12+
13+
variable "db_name" {
14+
default = "o1db"
15+
}
16+
17+
variable "db_user" {
18+
default = "postgres"
19+
}
20+
21+
variable "db_pass" {
22+
default = "o1db-pass"
23+
}
24+
25+
variable "deletion_protection" {
26+
default = false
27+
}
28+
29+
variable "postgres_version" {
30+
default = "POSTGRES_14"
31+
}
32+
33+
variable "db_spec" {
34+
default = "db-g1-small"
35+
}
36+
37+
variable "service_label" {
38+
default = "none"
39+
}

0 commit comments

Comments
 (0)