Skip to content

Commit

Permalink
Deploy client with terraform. (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
anybodys authored Jul 6, 2024
1 parent 19ee9fc commit 2e006b6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
53 changes: 53 additions & 0 deletions infra/app/app.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
################################################################
## Client
################################################################

resource "google_service_account" "client" {
account_id = "cloud-run-client"
display_name = "Service account for Cloud Run Client"
}

resource "google_cloud_run_v2_service" "client" {
name = "client"
location = var.region
ingress = "INGRESS_TRAFFIC_ALL"

template {

containers {
name = "client"
image = local.client_image

ports {
container_port = 3000
}

env {
name = "ENV"
value = "prod"
}
env {
name = "GOOGLE_CLOUD_PROJECT"
value = var.project
}
env {
name = "REACT_APP_VOTING_API_BASE_URL"
value = "https://${local.api_domain}"
}
}

service_account = google_service_account.client.email
}
}

# Allow unauthed requests.
resource "google_cloud_run_service_iam_binding" "client" {
location = google_cloud_run_v2_service.client.location
service = google_cloud_run_v2_service.client.name
role = "roles/run.invoker"
members = [
"allUsers"
]
}


################################################################
## API
################################################################
Expand Down
3 changes: 2 additions & 1 deletion infra/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ data "google_client_config" "current" {
}

locals {
api_image = docker_registry_image.app["api"].name
client_image = docker_registry_image.app["client"].name
api_image = docker_registry_image.app["api"].name
}
21 changes: 7 additions & 14 deletions infra/app/networking.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ locals {
api_domain = "api.${var.domain}"
}

# TODO: This should be built in Terraform.
data "google_cloud_run_service" "client" {
name = "client"
location = var.region
project = var.project
}

resource "google_compute_region_network_endpoint_group" "client_neg" {
name = "client-neg"
network_endpoint_type = "SERVERLESS"
region = var.region
cloud_run {
service = data.google_cloud_run_service.client.name
service = google_cloud_run_v2_service.client.name
}
}

Expand Down Expand Up @@ -163,19 +156,19 @@ module "lb-http" {

resource "google_cloud_run_domain_mapping" "client" {
name = var.domain
location = data.google_cloud_run_service.client.location
location = google_cloud_run_v2_service.client.location
metadata {
namespace = data.google_cloud_run_service.client.project
namespace = google_cloud_run_v2_service.client.project
}
spec {
route_name = data.google_cloud_run_service.client.name
route_name = google_cloud_run_v2_service.client.name
}
}

resource "google_cloud_run_service_iam_member" "public-access" {
location = data.google_cloud_run_service.client.location
project = data.google_cloud_run_service.client.project
service = data.google_cloud_run_service.client.name
location = google_cloud_run_v2_service.client.location
project = google_cloud_run_v2_service.client.project
service = google_cloud_run_v2_service.client.name
role = "roles/run.invoker"
member = "allUsers"
}
Expand Down
2 changes: 1 addition & 1 deletion infra/app/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "app_versions" {
type = map(string)
default = {
client : "0.2.0",
client : "0.2.0.p0",
api : "0.1.0.p1",
}

Expand Down

0 comments on commit 2e006b6

Please sign in to comment.