Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions infra/environments/artifacts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

terraform {
backend "gcs" {
bucket = "infra-new-state"
prefix = "artifacts"
}
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}

provider "google" {
project = "launchflow-services-dev"
region = "us-west1"
}

resource "google_artifact_registry_repository" "app" {
location = "us-west1"
repository_id = "app"
description = "Docker repository for application images"
format = "DOCKER"
}

output "repository_path" {
description = "The full path to the Artifact Registry repository"
value = "${google_artifact_registry_repository.app.location}-docker.pkg.dev/${google_artifact_registry_repository.app.project}/${google_artifact_registry_repository.app.repository_id}"
}
38 changes: 38 additions & 0 deletions infra/environments/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

terraform {
backend "gcs" {
bucket = "infra-new-state"
prefix = "dev"
}
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}

provider "google" {
project = "launchflow-services-dev"
region = "us-west1"
}

# Reference the artifact registry for the image
data "google_artifact_registry_repository" "app" {
location = "us-west1"
repository_id = "app"
}

module "cloud_run_service" {
source = "../../modules/cloud-run"

project_id = "launchflow-services-dev"
location = "us-west1"
service_name = "app-dev"
image = "${data.google_artifact_registry_repository.app.location}-docker.pkg.dev/${data.google_artifact_registry_repository.app.project}/${data.google_artifact_registry_repository.app.repository_id}/service:latest"
}

output "service_url" {
description = "The URL of the deployed service"
value = module.cloud_run_service.service_url
}
39 changes: 39 additions & 0 deletions infra/modules/cloud-run/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

module "cloud_run" {
source = "GoogleCloudPlatform/cloud-run/google"
version = "0.17.2"

# Required variables
project_id = var.project_id
location = var.location
service_name = var.service_name
image = var.image

# Optional configurations
service_account_email = google_service_account.service_account.email

template_annotations = {
"run.googleapis.com/client-name" = "terraform"
"generated-by" = "terraform"
"autoscaling.knative.dev/maxScale" = "4"
"autoscaling.knative.dev/minScale" = "1"
}

service_annotations = {
"run.googleapis.com/ingress" = "all"
}
}

# Create a service account for the Cloud Run service
resource "google_service_account" "service_account" {
project = var.project_id
account_id = "${var.service_name}-sa"
display_name = "Service Account for ${var.service_name} Cloud Run service"
}

# Grant the service account access to GCS
resource "google_project_iam_member" "gcs_access" {
project = var.project_id
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.service_account.email}"
}
15 changes: 15 additions & 0 deletions infra/modules/cloud-run/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

output "service_url" {
description = "The URL of the deployed service"
value = module.cloud_run.service_url
}

output "service_account_email" {
description = "The email of the service account"
value = google_service_account.service_account.email
}

output "service_name" {
description = "The name of the Cloud Run service"
value = module.cloud_run.service_name
}
20 changes: 20 additions & 0 deletions infra/modules/cloud-run/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

variable "project_id" {
description = "The project ID to deploy to"
type = string
}

variable "location" {
description = "The location to deploy to"
type = string
}

variable "service_name" {
description = "The name of the Cloud Run service"
type = string
}

variable "image" {
description = "The container image to deploy"
type = string
}