From 77a3f19830b8670c1bff4fb14ea7342711a59b15 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 16 Apr 2025 14:17:50 -0700 Subject: [PATCH] infra.new code version 0.0.3 --- infra/environments/artifacts/main.tf | 35 +++++++++++++++++++++++ infra/environments/dev/main.tf | 42 ++++++++++++++++++++++++++++ infra/modules/cloud-run/main.tf | 25 +++++++++++++++++ infra/modules/cloud-run/outputs.tf | 15 ++++++++++ infra/modules/cloud-run/variables.tf | 25 +++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 infra/environments/artifacts/main.tf create mode 100644 infra/environments/dev/main.tf create mode 100644 infra/modules/cloud-run/main.tf create mode 100644 infra/modules/cloud-run/outputs.tf create mode 100644 infra/modules/cloud-run/variables.tf diff --git a/infra/environments/artifacts/main.tf b/infra/environments/artifacts/main.tf new file mode 100644 index 0000000..9584293 --- /dev/null +++ b/infra/environments/artifacts/main.tf @@ -0,0 +1,35 @@ + +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" +} + +resource "google_project_iam_member" "cloudbuild_push" { + project = "launchflow-services-dev" + role = "roles/artifactregistry.writer" + member = "serviceAccount:${data.google_project.project.number}@cloudbuild.gserviceaccount.com" +} + +data "google_project" "project" { + project_id = "launchflow-services-dev" +} diff --git a/infra/environments/dev/main.tf b/infra/environments/dev/main.tf new file mode 100644 index 0000000..8809509 --- /dev/null +++ b/infra/environments/dev/main.tf @@ -0,0 +1,42 @@ + +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" +} + +# Create service account for Cloud Run +resource "google_service_account" "cloud_run_service_account" { + account_id = "cloud-run-service-account" + display_name = "Cloud Run Service Account" +} + +module "cloud_run" { + source = "../../modules/cloud-run" + + project_id = "launchflow-services-dev" + location = "us-west1" + service_name = "python-app-dev" + image = "us-west1-docker.pkg.dev/launchflow-services-dev/app/python-app:latest" + service_account_email = google_service_account.cloud_run_service_account.email +} + +output "service_url" { + value = module.cloud_run.service_url +} + +output "service_status" { + value = module.cloud_run.service_status +} diff --git a/infra/modules/cloud-run/main.tf b/infra/modules/cloud-run/main.tf new file mode 100644 index 0000000..986e35f --- /dev/null +++ b/infra/modules/cloud-run/main.tf @@ -0,0 +1,25 @@ + +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 = var.service_account_email + + template_annotations = { + "run.googleapis.com/client-name" = "terraform" + "generated-by" = "terraform" + "autoscaling.knative.dev/maxScale" = "3" + "autoscaling.knative.dev/minScale" = "1" + } + + service_annotations = { + "run.googleapis.com/ingress" = "all" + } +} diff --git a/infra/modules/cloud-run/outputs.tf b/infra/modules/cloud-run/outputs.tf new file mode 100644 index 0000000..fa2c942 --- /dev/null +++ b/infra/modules/cloud-run/outputs.tf @@ -0,0 +1,15 @@ + +output "service_url" { + description = "The URL on which the deployed service is available" + value = module.cloud_run.service_url +} + +output "service_id" { + description = "Unique identifier for the Cloud Run service" + value = module.cloud_run.service_id +} + +output "service_status" { + description = "Status of the Cloud Run service" + value = module.cloud_run.service_status +} diff --git a/infra/modules/cloud-run/variables.tf b/infra/modules/cloud-run/variables.tf new file mode 100644 index 0000000..7e1ab20 --- /dev/null +++ b/infra/modules/cloud-run/variables.tf @@ -0,0 +1,25 @@ + +variable "project_id" { + description = "The project ID to deploy to" + type = string +} + +variable "location" { + description = "Cloud Run service deployment location" + type = string +} + +variable "service_name" { + description = "The name of the Cloud Run service to create" + type = string +} + +variable "image" { + description = "Container image to deploy" + type = string +} + +variable "service_account_email" { + description = "Service account email to run the service as" + type = string +}