diff --git a/infra/artifacts/main.tf b/infra/artifacts/main.tf new file mode 100644 index 0000000..9584293 --- /dev/null +++ b/infra/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/dev/dev.tfvars b/infra/dev/dev.tfvars new file mode 100644 index 0000000..db022de --- /dev/null +++ b/infra/dev/dev.tfvars @@ -0,0 +1,2 @@ + +# No variables to set as all values are hardcoded in main.tf diff --git a/infra/dev/main.tf b/infra/dev/main.tf new file mode 100644 index 0000000..479ec23 --- /dev/null +++ b/infra/dev/main.tf @@ -0,0 +1,36 @@ + +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_sa" { + account_id = "cloud-run-service" + display_name = "Cloud Run Service Account" + description = "Service account for Cloud Run application" +} + +# Use the Cloud Run module +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/myapp:latest" + service_account_email = google_service_account.cloud_run_sa.email +} diff --git a/infra/dev/outputs.tf b/infra/dev/outputs.tf new file mode 100644 index 0000000..30aafac --- /dev/null +++ b/infra/dev/outputs.tf @@ -0,0 +1,10 @@ + +output "service_url" { + description = "The URL of the deployed Cloud Run service" + value = module.cloud_run.service_url +} + +output "service_status" { + description = "The status of the Cloud Run service" + value = module.cloud_run.service_status +} diff --git a/infra/dev/variables.tf b/infra/dev/variables.tf new file mode 100644 index 0000000..cbb4c10 --- /dev/null +++ b/infra/dev/variables.tf @@ -0,0 +1,2 @@ + +# No variables needed for dev environment as all values are hardcoded for simplicity diff --git a/infra/modules/cloud_run/main.tf b/infra/modules/cloud_run/main.tf new file mode 100644 index 0000000..b2b3649 --- /dev/null +++ b/infra/modules/cloud_run/main.tf @@ -0,0 +1,23 @@ + +module "cloud_run" { + source = "GoogleCloudPlatform/cloud-run/google" + version = "0.17.0" + + project_id = var.project_id + location = var.location + service_name = var.service_name + image = var.image + + service_account_email = var.service_account_email + + template_annotations = { + "run.googleapis.com/client-name" = "terraform" + "generated-by" = "terraform" + "autoscaling.knative.dev/maxScale" = "2" + "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..f9e8263 --- /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 for the Cloud Run service" + type = string +}