terraform {
  required_providers {
    zitadel = {
      source  = "zitadel/zitadel"
      version = "2.0.2"
    }
  }
}

resource "zitadel_project" "default" {
  depends_on = [var.wait_on]
  org_id                   = var.org_id
  name                     = var.name
  project_role_assertion   = true
  project_role_check       = true
  has_project_check        = true
  private_labeling_setting = "PRIVATE_LABELING_SETTING_ENFORCE_PROJECT_RESOURCE_OWNER_POLICY"
}

resource "zitadel_project_member" "default" {
  count = length(var.owners)

  org_id     = var.org_id
  project_id = zitadel_project.default.id
  user_id    = var.owners[count.index]
  roles = ["PROJECT_OWNER"]
}

output "installed" {
  value = true
  depends_on = [zitadel_project.default, zitadel_project_member.default]
}

output "project_id" {
  value = zitadel_project.default.id
}
