From 1fb3d59ebc9cfb35eea3f815631cf334406067ab Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 16 Apr 2025 16:58:19 -0700 Subject: [PATCH] infra.new code version 0.0.3 --- infra/environments/artifacts/main.tf | 26 ++++++++++++++++++++ infra/environments/dev/main.tf | 33 +++++++++++++++++++++++++ infra/modules/cloud-run/main.tf | 36 ++++++++++++++++++++++++++++ infra/modules/cloud-run/outputs.tf | 15 ++++++++++++ infra/modules/cloud-run/variables.tf | 20 ++++++++++++++++ 5 files changed, 130 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..babf376 --- /dev/null +++ b/infra/environments/artifacts/main.tf @@ -0,0 +1,26 @@ + +terraform { + backend "gcs" { + bucket = "infra-new-state" + prefix = "tanke/v3/artifacts" + } + + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.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..f2e8cc5 --- /dev/null +++ b/infra/environments/dev/main.tf @@ -0,0 +1,33 @@ + +terraform { + backend "gcs" { + bucket = "infra-new-state" + prefix = "tanke/v3/dev" + } + + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + project = "launchflow-services-dev" + region = "us-west1" +} + +module "cloud_run_service" { + source = "../../modules/cloud-run" + + project_id = "launchflow-services-dev" + location = "us-west1" + service_name = "app-dev" + image = "us-west1-docker.pkg.dev/launchflow-services-dev/app/service:latest" +} + +output "service_url" { + description = "The URL of the deployed Cloud Run service" + value = module.cloud_run_service.service_url +} diff --git a/infra/modules/cloud-run/main.tf b/infra/modules/cloud-run/main.tf new file mode 100644 index 0000000..2924ee3 --- /dev/null +++ b/infra/modules/cloud-run/main.tf @@ -0,0 +1,36 @@ + +module "cloud_run" { + source = "GoogleCloudPlatform/cloud-run/google" + version = "0.17.0" + + # Required variables + project_id = var.project_id + location = var.location + service_name = var.service_name + image = var.image + + # Optional configurations + service_annotations = { + "run.googleapis.com/ingress" = "all" + } + + template_annotations = { + "run.googleapis.com/client-name" = "terraform" + "generated-by" = "terraform" + "autoscaling.knative.dev/maxScale" = "2" + "autoscaling.knative.dev/minScale" = "1" + } + + ports = { + name = "http1" + port = 8080 + } +} + +# Allow unauthenticated access to the service +resource "google_cloud_run_service_iam_member" "public_access" { + location = module.cloud_run.location + service = module.cloud_run.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..16cfa01 --- /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 "location" { + description = "Location in which the Cloud Run service was created" + value = module.cloud_run.location +} + +output "service_name" { + description = "Name of the created service" + value = module.cloud_run.service_name +} diff --git a/infra/modules/cloud-run/variables.tf b/infra/modules/cloud-run/variables.tf new file mode 100644 index 0000000..c6a66df --- /dev/null +++ b/infra/modules/cloud-run/variables.tf @@ -0,0 +1,20 @@ + +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 +}