diff --git a/infrastructure/terraform/main.tf b/infrastructure/terraform/main.tf new file mode 100644 index 0000000..62e957d --- /dev/null +++ b/infrastructure/terraform/main.tf @@ -0,0 +1,60 @@ +provider "google" { + project = var.project_id + region = var.region +} + +resource "google_project_service" "apis" { + for_each = toset([ + "aiplatform.googleapis.com", + "storage.googleapis.com", + "cloudbilling.googleapis.com", + "cloudresourcemanager.googleapis.com", + "iam.googleapis.com", + "run.googleapis.com", + "artifactregistry.googleapis.com", + "cloudbuild.googleapis.com", + "cloudbuildv2.googleapis.com", + "secretmanager.googleapis.com", + "monitoring.googleapis.com", + "logging.googleapis.com", + "cloudtrace.googleapis.com", + "pubsub.googleapis.com", + "cloudfunctions.googleapis.com", + ]) + service = each.key + disable_dependent_services = true +} + +resource "google_service_account" "agent_sa" { + account_id = "osvauco-agent-sa" + display_name = "OSVauco Agent Runner SA" +} + +resource "google_project_iam_member" "agent_sa_roles" { + for_each = toset([ + "roles/aiplatform.user", + "roles/storage.objectAdmin", + "roles/logging.logWriter", + "roles/cloudtrace.agent", + "roles/monitoring.metricWriter", + "roles/secretmanager.secretAccessor", + "roles/run.invoker", + ]) + project = var.project_id + role = each.key + member = "serviceAccount:${google_service_account.agent_sa.email}" +} + +resource "google_pubsub_topic" "billing_alerts" { + name = "billing-alert-auto-teardown" +} + +resource "google_pubsub_subscription" "billing_alerts_sub" { + name = "billing-alert-subscription" + topic = google_pubsub_topic.billing_alerts.name + + # Push to an email address + push_config { + push_endpoint = "mailto:${var.alert_email}" + } +} diff --git a/infrastructure/terraform/variables.tf b/infrastructure/terraform/variables.tf new file mode 100644 index 0000000..78f126b --- /dev/null +++ b/infrastructure/terraform/variables.tf @@ -0,0 +1,26 @@ +variable "project_id" { + description = "The project ID to deploy the resources to." + type = string +} + +variable "region" { + description = "The region to deploy the resources to." + type = string +} + +variable "customer_id" { + description = "The customer ID for billing and labeling." + type = string + default = "osvauco" +} + +variable "alert_email" { + description = "The email address for billing alerts." + type = string + default = "billing-alerts@example.com" +} + +variable "billing_account_id" { + description = "The billing account ID to associate with the project." + type = string +} diff --git a/infrastructure/terraform/versions.tf b/infrastructure/terraform/versions.tf new file mode 100644 index 0000000..464562b --- /dev/null +++ b/infrastructure/terraform/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.5" + + required_providers { + google = { + source = "hashicorp/google" + version = ">= 5.0" + } + } +}