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 "network" {
  source = "../../modules/network"

  project_name      = var.project_id
  region            = var.region
  frontend_cidr     = "10.0.1.0/24"
  backend_cidr      = "10.0.2.0/24"
  database_cidr     = "10.0.3.0/24"
  ssh_source_ranges = "34.79.226.15/32"
}

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_id = module.network.vpc_id
  frontend_subnet_id = module.network.subnet_ids["frontend"]
  backend_subnet_id = module.network.subnet_ids["backend"]
  database_subnet_id = module.network.subnet_ids["database"]
  ssh_pub_key = var.ssh_pub_key
  service_account_email = module.iam.service_account_email
}