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..1cdc7e6 --- /dev/null +++ b/infra/environments/dev/main.tf @@ -0,0 +1,37 @@ + +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 = "app-dev" + image = "us-west1-docker.pkg.dev/launchflow-services-dev/app/service:latest" +} + +output "service_url" { + description = "The URL of the deployed service" + value = module.cloud_run.service_url +} + +output "service_status" { + description = "The status of the deployed service" + 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..c749f4e --- /dev/null +++ b/infra/modules/cloud-run/main.tf @@ -0,0 +1,33 @@ + +module "cloud_run_service_account" { + source = "terraform-google-modules/service-accounts/google" + version = "4.5.3" + project_id = var.project_id + names = ["cloud-run-service"] + project_roles = [ + "${var.project_id}=>roles/run.invoker", + ] +} + +module "cloud_run" { + source = "GoogleCloudPlatform/cloud-run/google" + version = "0.17.2" + + project_id = var.project_id + location = var.location + service_name = var.service_name + image = var.image + + service_account_email = module.cloud_run_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" + } +} diff --git a/infra/modules/cloud-run/outputs.tf b/infra/modules/cloud-run/outputs.tf new file mode 100644 index 0000000..c8d1931 --- /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 "service_id" { + description = "The ID of the deployed service" + value = module.cloud_run.service_id +} + +output "service_status" { + description = "The status of the deployed 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..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 +}