diff --git a/infra/environments/artifacts/main.tf b/infra/environments/artifacts/main.tf new file mode 100644 index 0000000..6d9481d --- /dev/null +++ b/infra/environments/artifacts/main.tf @@ -0,0 +1,30 @@ + +terraform { + backend "gcs" { + bucket = "infra-new-state" + prefix = "tanke/v4/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" +} + +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}" +} diff --git a/infra/environments/dev/main.tf b/infra/environments/dev/main.tf new file mode 100644 index 0000000..d0391ed --- /dev/null +++ b/infra/environments/dev/main.tf @@ -0,0 +1,38 @@ + +terraform { + backend "gcs" { + bucket = "infra-new-state" + prefix = "tanke/v4/dev" + } + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + project = "launchflow-services-dev" + region = "us-west1" +} + +# Get the artifact registry repository details +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 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..5128d5b --- /dev/null +++ b/infra/modules/cloud-run/main.tf @@ -0,0 +1,37 @@ + +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 + + # Make the service publicly accessible + 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" + } + + # Default port configuration + 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..ae16039 --- /dev/null +++ b/infra/modules/cloud-run/outputs.tf @@ -0,0 +1,15 @@ + +output "service_url" { + description = "The URL of the deployed service" + value = module.cloud_run.service_url +} + +output "location" { + description = "The location of the deployed service" + value = module.cloud_run.location +} + +output "service_name" { + description = "The name of the deployed 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..a9ff209 --- /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 = "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 +}