terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = ">= 4.0"
    }
    local = {
      source = "hashicorp/local"
      version = ">= 2.0"
    }
  }
}

provider "google" {
  project = var.project_id
  region = var.region
  zone = var.zone
}

provider "local" {}

module "iam" {
  source = "../../modules/iam"


  project_id = var.project_id
  sa_name = "terraform-runner"
  sa_display_name = "Terraform SA for TP"
}

module "compute" {
  source = "../../modules/compute"

  project_id = var.project_id
  region = var.region
  zone = var.zone
  instance_type = var.instance_type
  network = var.network
  frontend_subnet_id = var.frontend_subnet_id
  backend_subnet_id = var.backend_subnet_id
  database_subnet_id = var.database_subnet_id
  ssh_pub_key = var.ssh_pub_key
  service_account_email = module.iam.service_account_email
}

module "network" {
  source = "../../modules/network"

  project_name = var.project_id
  region = var.region
}