diff --git a/infra/environments/artifacts/main.tf b/infra/environments/artifacts/main.tf new file mode 100644 index 0000000..27655b8 --- /dev/null +++ b/infra/environments/artifacts/main.tf @@ -0,0 +1,25 @@ + +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" +} diff --git a/infra/environments/dev/main.tf b/infra/environments/dev/main.tf new file mode 100644 index 0000000..587a2f8 --- /dev/null +++ b/infra/environments/dev/main.tf @@ -0,0 +1,35 @@ + +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" +} + +module "cloud_run" { + source = "../../modules/cloud-run" + + project_id = "launchflow-services-dev" + location = "us-west1" + service_name = "python-app-dev" + container_image = "us-west1-docker.pkg.dev/launchflow-services-dev/app/python-app:latest" + cpu = "1000m" + memory = "512Mi" + public_access = true +} + +output "service_url" { + description = "The URL of the deployed service" + value = module.cloud_run.service_url +} diff --git a/infra/modules/cloud-run/main.tf b/infra/modules/cloud-run/main.tf new file mode 100644 index 0000000..eb21bda --- /dev/null +++ b/infra/modules/cloud-run/main.tf @@ -0,0 +1,41 @@ + +resource "google_service_account" "service_account" { + account_id = var.service_name + display_name = "Service Account for ${var.service_name}" + description = "Service account for Cloud Run service ${var.service_name}" +} + +resource "google_cloud_run_v2_service" "service" { + name = var.service_name + location = var.location + + template { + containers { + image = var.container_image + + resources { + limits = { + cpu = var.cpu + memory = var.memory + } + } + + env { + name = "PROJECT_ID" + value = var.project_id + } + } + + service_account = google_service_account.service_account.email + } +} + +# IAM binding for public access (if enabled) +resource "google_cloud_run_v2_service_iam_member" "public" { + count = var.public_access ? 1 : 0 + project = google_cloud_run_v2_service.service.project + location = google_cloud_run_v2_service.service.location + name = google_cloud_run_v2_service.service.name + role = "roles/run.invoker" + member = "allUsers" +} diff --git a/infra/modules/cloud-run/outputs.tf b/infra/modules/cloud-run/outputs.tf new file mode 100644 index 0000000..a82d38c --- /dev/null +++ b/infra/modules/cloud-run/outputs.tf @@ -0,0 +1,15 @@ + +output "service_url" { + description = "The URL of the deployed service" + value = google_cloud_run_v2_service.service.uri +} + +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 = google_cloud_run_v2_service.service.name +} diff --git a/infra/modules/cloud-run/variables.tf b/infra/modules/cloud-run/variables.tf new file mode 100644 index 0000000..abae768 --- /dev/null +++ b/infra/modules/cloud-run/variables.tf @@ -0,0 +1,38 @@ + +variable "project_id" { + description = "The project ID where resources will be created" + type = string +} + +variable "location" { + description = "The location where resources will be created" + type = string +} + +variable "service_name" { + description = "The name of the Cloud Run service" + type = string +} + +variable "container_image" { + description = "The container image to deploy" + type = string +} + +variable "cpu" { + description = "The amount of CPU to allocate to the service" + type = string + default = "1000m" +} + +variable "memory" { + description = "The amount of memory to allocate to the service" + type = string + default = "512Mi" +} + +variable "public_access" { + description = "Whether to allow public access to the service" + type = bool + default = true +}