Skip to content

Commit

Permalink
Merge pull request #14399 from MinaProtocol/steven-ci-metrics
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stevenplatt authored Oct 24, 2023
2 parents 56a2ea8 + 8a52589 commit d5ae586
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
26 changes: 26 additions & 0 deletions automation/terraform/modules/google-cloud/cloud-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Google Cloud Postgres Deployment

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).

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:

```
Outputs:
cloud_postgres_ip = tolist([
{
"ip_address" = "35.35.35.35" <---- example IP
"time_to_retire" = ""
"type" = "PRIMARY"
},
{
"ip_address" = "34.34.34.34" <---- example IP
"time_to_retire" = ""
"type" = "OUTGOING"
},
])
db_password = "PASSWORD_HERE"
db_user = "postgres"
```

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.
36 changes: 36 additions & 0 deletions automation/terraform/modules/google-cloud/cloud-postgres/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Configure the Google Cloud provider
provider "google" {
project = var.gcp_project
region = var.gcp_region
}

resource "random_id" "instance_id" {
byte_length = 4
}

data "google_secret_manager_secret_version" "db_password" {
provider = google
secret = var.db_pass
}

# Create a Google Cloud SQL PostgreSQL instance
resource "google_sql_database_instance" "postgres_instance" {
name = "${var.db_name}-${random_id.instance_id.hex}"
database_version = var.postgres_version
project = var.gcp_project
region = var.gcp_region
settings {
tier = var.db_spec
user_labels = {
service = var.service_label
}
}
deletion_protection = var.deletion_protection
}

# Define the database user
resource "google_sql_user" "database_user" {
name = var.db_user
instance = google_sql_database_instance.postgres_instance.name
password = data.google_secret_manager_secret_version.db_password.secret_data
}
13 changes: 13 additions & 0 deletions automation/terraform/modules/google-cloud/cloud-postgres/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
output "cloud_postgres_ip" {
value = google_sql_database_instance.postgres_instance.ip_address
}

output "db_user" {
value = google_sql_user.database_user.name
}

output "db_password" {
value = data.google_secret_manager_secret_version.db_password.secret_data
}


39 changes: 39 additions & 0 deletions automation/terraform/modules/google-cloud/cloud-postgres/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "gcp_project" {
default = "o1labs-192920"
}

variable "gcp_region" {
default = "us-east4"
}

variable "gcp_zone" {
default = "us-east4-b"
}

variable "db_name" {
default = "o1db"
}

variable "db_user" {
default = "postgres"
}

variable "db_pass" {
default = "o1db-pass"
}

variable "deletion_protection" {
default = false
}

variable "postgres_version" {
default = "POSTGRES_14"
}

variable "db_spec" {
default = "db-g1-small"
}

variable "service_label" {
default = "none"
}

0 comments on commit d5ae586

Please sign in to comment.