# Phase 2 Outputs

output "deployment_status" {
  value = {
    for k, v in null_resource.deploy_docker_compose : k => {
      region        = var.phase1_vm_info[k].region
      vm_name       = var.phase1_vm_info[k].vm_names[0]
      compose_file  = local.region_compose_map[var.phase1_vm_info[k].region]
      status        = "deployed"
      docker_compose_path = "/opt/docker-compose/docker-compose.yml"
    }
  }
  description = "Phase 2 docker-compose deployment status for each region"
}

output "systemd_service_status" {
  value = {
    for k, v in null_resource.create_systemd_service : k => {
      region          = var.phase1_vm_info[k].region
      service_name    = "phase2-stack.service"
      service_path    = "/etc/systemd/system/phase2-stack.service"
      status          = "installed"
      note            = "Service is enabled but not started. Use 'sudo systemctl start phase2-stack.service' to start."
    }
  }
  description = "Systemd service installation status for each region"
}

output "management_commands" {
  value = {
    for k, v in var.phase1_vm_info : k => {
      region           = v.region
      vm_name          = v.vm_names[0]
      ssh_connection   = "ssh ${var.vm_admin_username}@${length(v.private_ips) > 0 ? v.private_ips[0] : (length(v.public_ips) > 0 ? v.public_ips[0] : "N/A")}"
      start_service    = "sudo systemctl start phase2-stack.service"
      stop_service     = "sudo systemctl stop phase2-stack.service"
      restart_service  = "sudo systemctl restart phase2-stack.service"
      status_service   = "sudo systemctl status phase2-stack.service"
      view_logs        = "sudo journalctl -u phase2-stack.service -f"
      docker_compose   = "cd /opt/docker-compose && docker compose ps"
      docker_logs      = "cd /opt/docker-compose && docker compose logs -f"
    }
  }
  description = "Management commands for Phase 2 deployment"
}

output "docker_compose_files" {
  value = {
    for region, compose_file in local.region_compose_map : region => {
      compose_file = compose_file
      local_path   = "${var.docker_compose_source_path}/${compose_file}"
      remote_path  = "/opt/docker-compose/docker-compose.yml"
    }
  }
  description = "Docker compose file paths (local and remote) for each region"
}

