-
Notifications
You must be signed in to change notification settings - Fork 15
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
Break ground on the GCP implementation #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
terraform { | ||
source = "${get_repo_root()}/deployment/modules/gcs" | ||
} | ||
|
||
locals { | ||
project_id = "trillian-tessera" | ||
location = "us-central1" | ||
base_name = "example-gcp" | ||
} | ||
|
||
inputs = merge( | ||
local, | ||
{} | ||
) | ||
|
||
remote_state { | ||
backend = "gcs" | ||
|
||
config = { | ||
project = local.project_id | ||
location = local.location | ||
bucket = "${local.project_id}-${local.base_name}-terraform-state" | ||
|
||
gcs_bucket_labels = { | ||
name = "terraform_state_storage" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
terraform { | ||
backend "gcs" {} | ||
} | ||
|
||
# Services | ||
resource "google_project_service" "serviceusage_googleapis_com" { | ||
service = "serviceusage.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
resource "google_project_service" "storage_api_googleapis_com" { | ||
service = "storage-api.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
resource "google_project_service" "storage_component_googleapis_com" { | ||
service = "storage-component.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
resource "google_project_service" "storage_googleapis_com" { | ||
service = "storage.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
## Resources | ||
|
||
# Service accounts | ||
|
||
resource "google_service_account" "log_writer" { | ||
account_id = "${var.base_name}-writer" | ||
display_name = "Transparency log writer service account" | ||
} | ||
|
||
|
||
# Buckets | ||
|
||
resource "google_storage_bucket" "log_bucket" { | ||
name = "${var.project_id}-${var.base_name}-bucket" | ||
location = var.location | ||
storage_class = "STANDARD" | ||
uniform_bucket_level_access = true | ||
} | ||
|
||
resource "google_storage_bucket_iam_binding" "log_bucket_writer" { | ||
bucket = google_storage_bucket.log_bucket.name | ||
role = "roles/storage.legacyBucketWriter" | ||
members = [ | ||
google_service_account.log_writer.member | ||
] | ||
} | ||
|
||
# Spanner | ||
|
||
resource "google_spanner_instance" "log_spanner" { | ||
name = var.base_name | ||
config = "regional-${var.location}" | ||
display_name = "${var.base_name} Spanner Instance" | ||
processing_units = 100 | ||
} | ||
|
||
resource "google_spanner_database" "log_db" { | ||
instance = google_spanner_instance.log_spanner.name | ||
name = "${var.base_name}-db" | ||
ddl = [ | ||
"CREATE TABLE SeqCoord (id INT64 NOT NULL, next INT64 NOT NULL,) PRIMARY KEY (id)", | ||
"CREATE TABLE Seq (id INT64 NOT NULL, seq INT64 NOT NULL, v BYTES(MAX),) PRIMARY KEY (id, seq)", | ||
"CREATE TABLE IntCoord (id INT64 NOT NULL, seq INT64 NOT NULL,) PRIMARY KEY (id)", | ||
] | ||
} | ||
|
||
resource "google_spanner_database_iam_binding" "database" { | ||
instance = google_spanner_instance.log_spanner.name | ||
database = google_spanner_database.log_db.name | ||
role = "roles/spanner.databaseUser" | ||
|
||
members = [ | ||
google_service_account.log_writer.member | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "log_bucket" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to output the spanner resource too as that's needed for the binary? |
||
description = "Log GCS bucket" | ||
value = google_storage_bucket.log_bucket | ||
} | ||
|
||
output "log_spanner" { | ||
description = "Log Spanner database" | ||
value = google_spanner_database.log_db | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
variable "project_id" { | ||
description = "GCP project ID where the log is hosted" | ||
type = string | ||
} | ||
|
||
variable "base_name" { | ||
description = "Base name to use when naming resources" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docstring is a bit unclear and leaves some guesswork (or detective work, more likely). |
||
type = string | ||
} | ||
|
||
variable "location" { | ||
description = "Location in which to create resources" | ||
type = string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to look at using something like https://github.com/golang-migrate/migrate/tree/master/database/spanner to manage this when we do it for realz. This will be painful if this schema ever needs to be updated. I used to mysql version of this library for the experiments and it was cool.