Skip to content

Commit

Permalink
Rough outline of terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Jul 4, 2024
1 parent ef90d2e commit 04e290f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
28 changes: 28 additions & 0 deletions deployment/live/example-gcp/terragrunt.hcl
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-gcs"
}

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"
}
}
}
73 changes: 73 additions & 0 deletions deployment/modules/gcs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
terraform {
backend "gcs" {}
}

# Services
resource "google_project_service" "serviceusage_googleapis_com" {
service = "serviceusage.googleapis.com"
}
resource "google_project_service" "storage_api_googleapis_com" {
service = "storage-api.googleapis.com"
}
resource "google_project_service" "storage_component_googleapis_com" {
service = "storage-component.googleapis.com"
}
resource "google_project_service" "storage_googleapis_com" {
service = "storage.googleapis.com"
}

## Resources

# Service accounts

resource "google_service_account" "log_writer" {
account_id = "${var.base_name}-writer"
display_name = "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/compute.networkUser"

members = [
google_service_account.log_writer.member
]
}
4 changes: 4 additions & 0 deletions deployment/modules/gcs/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "log_bucket" {
description = "Log GCS bucket"
value = google_storage_bucket.log_bucket
}
14 changes: 14 additions & 0 deletions deployment/modules/gcs/variables.tf
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"
type = string
}

variable "location" {
description = "Location in which to create resources"
type = string
}

0 comments on commit 04e290f

Please sign in to comment.