-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from redbadger/gcp-infra
gcp infra wip
- Loading branch information
Showing
21 changed files
with
416 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Platform PoC wasmCloud on Google Cloud | ||
|
||
## Prerequisites | ||
|
||
- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) | ||
- [OpenTofu](https://opentofu.org/) | ||
- [wash](https://wasmcloud.com/docs/installation/) | ||
|
||
## Setup | ||
|
||
Login to Google Cloud: | ||
|
||
```fish | ||
# for interactive use of gcloud CLI ... | ||
gcloud auth login | ||
# for OpenTofu/Terraform ... | ||
gcloud auth application-default login | ||
``` | ||
|
||
Install the GKE gcloud auth plugin (so that the provision script can get the cluster credentials): | ||
|
||
```fish | ||
gcloud components install gke-gcloud-auth-plugin | ||
``` | ||
|
||
## Provisioning | ||
|
||
```fish | ||
./scripts/provision.fish | ||
``` | ||
|
||
## Destroying | ||
|
||
```fish | ||
./scripts/destroy.fish | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env fish | ||
set SCRIPT_DIR (dirname (realpath (status -f))) | ||
|
||
# STAGE 2 | ||
pushd $SCRIPT_DIR/../stage_2 | ||
tofu init | ||
tofu destroy --var-file=../terraform.tfvars | ||
popd | ||
|
||
# STAGE 1 | ||
pushd $SCRIPT_DIR/../stage_1 | ||
tofu init | ||
tofu destroy --var-file=../terraform.tfvars | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env fish | ||
set SCRIPT_DIR (dirname (realpath (status -f))) | ||
|
||
# STAGE 1 | ||
pushd $SCRIPT_DIR/../stage_1 | ||
tofu init | ||
tofu apply --var-file=../terraform.tfvars | ||
popd | ||
|
||
# Authenticate with the cluster | ||
gcloud container clusters get-credentials platform-poc-wasmcloud-cluster \ | ||
--project platform-poc-wasmcloud \ | ||
--location europe-west2 | ||
|
||
# STAGE 2 | ||
pushd $SCRIPT_DIR/../stage_2 | ||
tofu init | ||
tofu apply --var-file=../terraform.tfvars | ||
popd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
resource "google_container_cluster" "primary" { | ||
name = "${var.project_id}-cluster" | ||
location = var.region | ||
deletion_protection = false | ||
|
||
remove_default_node_pool = true | ||
initial_node_count = 1 | ||
|
||
workload_identity_config { | ||
workload_pool = "${var.project_id}.svc.id.goog" | ||
} | ||
} | ||
|
||
resource "google_container_node_pool" "primary_nodes" { | ||
name = "primary-node-pool" | ||
location = var.region | ||
cluster = google_container_cluster.primary.name | ||
node_count = 1 | ||
|
||
node_config { | ||
machine_type = "e2-standard-2" | ||
service_account = google_service_account.workload-identity-user-sa.email | ||
} | ||
} | ||
|
||
resource "google_service_account" "workload-identity-user-sa" { | ||
account_id = "cloud-sql-client-sa" | ||
display_name = "Cloud SQL Client Service Account" | ||
description = "Service account used for Cloud SQL Auth PRoxy" | ||
} | ||
|
||
resource "google_project_iam_member" "sql-client-role" { | ||
project = var.project_id | ||
role = "roles/cloudsql.client" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "datastore-user-role" { | ||
project = var.project_id | ||
role = "roles/datastore.user" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "artifact-registry-reader-role" { | ||
project = var.project_id | ||
role = "roles/artifactregistry.reader" | ||
member = "serviceAccount:${google_service_account.workload-identity-user-sa.email}" | ||
} | ||
|
||
output "node_pool_service_account" { | ||
value = google_service_account.workload-identity-user-sa.email | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "google" { | ||
project = var.project_id | ||
region = var.region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
resource "google_memorystore_instance" "redis" { | ||
instance_id = "${var.project_id}-redis" | ||
shard_count = 1 | ||
desired_psc_auto_connections { | ||
network = google_compute_network.producer_net.id | ||
project_id = data.google_project.project.project_id | ||
} | ||
location = var.region | ||
deletion_protection_enabled = false | ||
depends_on = [ | ||
google_network_connectivity_service_connection_policy.default | ||
] | ||
|
||
lifecycle { | ||
# we don't store any critical data | ||
prevent_destroy = false | ||
} | ||
} | ||
|
||
resource "google_network_connectivity_service_connection_policy" "default" { | ||
name = "${var.project_id}-redis-policy" | ||
location = var.region | ||
service_class = "gcp-memorystore" | ||
description = "redis connection policy" | ||
network = google_compute_network.producer_net.id | ||
psc_config { | ||
subnetworks = [google_compute_subnetwork.producer_subnet.id] | ||
} | ||
} | ||
|
||
resource "google_compute_subnetwork" "producer_subnet" { | ||
name = "my-subnet" | ||
ip_cidr_range = "10.0.0.248/29" | ||
region = var.region | ||
network = google_compute_network.producer_net.id | ||
} | ||
|
||
resource "google_compute_network" "producer_net" { | ||
name = "my-network" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
data "google_project" "project" { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "kubernetes_context" { | ||
value = "gke_${var.project_id}_${var.region}_${google_container_cluster.primary.name}" | ||
} | ||
|
||
output "workload-identity-user-sa" { | ||
value = google_service_account.workload-identity-user-sa.email | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
resource "google_sql_database" "database_orders" { | ||
name = "order-service" | ||
instance = google_sql_database_instance.instance.name | ||
} | ||
|
||
resource "google_sql_database" "database_inventory" { | ||
name = "inventory-service" | ||
instance = google_sql_database_instance.instance.name | ||
} | ||
|
||
resource "google_sql_user" "user" { | ||
name = var.pg_user | ||
instance = google_sql_database_instance.instance.name | ||
password = var.pg_password | ||
} | ||
|
||
resource "google_sql_database_instance" "instance" { | ||
name = "${var.project_id}-pg" | ||
region = var.region | ||
database_version = "POSTGRES_15" | ||
settings { | ||
tier = "db-f1-micro" | ||
database_flags { | ||
name = "max_connections" | ||
value = "50" | ||
} | ||
} | ||
|
||
deletion_protection = "false" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "google_artifact_registry_repository" "registry" { | ||
location = var.region | ||
repository_id = "registry" | ||
description = "OCI registry for wasmcloud services" | ||
format = "DOCKER" | ||
|
||
docker_config { | ||
immutable_tags = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "project_id" { | ||
type = string | ||
description = "The project ID" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
description = "The region" | ||
} | ||
|
||
variable "pg_user" { | ||
type = string | ||
description = "Username for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_password" { | ||
type = string | ||
description = "password for Postgres Cloud SQL database" | ||
} | ||
|
||
variable "pg_database" { | ||
type = string | ||
description = "Postgres Cloud SQL database name" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "6.19.0" | ||
} | ||
} | ||
|
||
backend "gcs" { | ||
bucket = "platform-poc-wasmcloud-tofu-state" | ||
prefix = "dev" | ||
} | ||
|
||
required_version = ">= 1.9.0" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
resource "google_project_iam_member" "workload_identity-role" { | ||
project = var.project_id | ||
role = "roles/iam.workloadIdentityUser" | ||
member = "serviceAccount:${var.project_id}.svc.id.goog[default/${kubernetes_service_account.ksa.metadata[0].name}]" | ||
} | ||
|
||
resource "kubernetes_service_account" "ksa" { | ||
metadata { | ||
name = "kubernetes-service-account" | ||
annotations = { | ||
"iam.gke.io/gcp-service-account" = data.terraform_remote_state.stage_1.outputs.workload-identity-user-sa | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "db_secrets" { | ||
metadata { | ||
name = "postgres-db-secrets" | ||
} | ||
|
||
data = { | ||
username = var.pg_user | ||
password = var.pg_password | ||
database = var.pg_database | ||
} | ||
} |
Oops, something went wrong.