terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
  }
  backend "azurerm" {}
}
provider "azurerm" {
  subscription_id = var.subscription_id
  features {
    resource_group {
      prevent_deletion_if_contains_resources = false
    }
  }
}
data "azurerm_subscription" "primary" {}

variable "env" {
  type = string
}
variable "location" {
  type = string
}
variable "aks_oidc_issuer" {
  type = string
}
variable "subscription_id" {
  type = string
}

module "o11y-agent" {
  source = "../../modules/controlplane"

  location        = var.location
  aks_oidc_issuer = var.aks_oidc_issuer
  # azure-workload-identity does not support wildcard https://github.com/Azure/azure-workload-identity/issues/373
  # namespace and service_account should be exact match
  namespace           = "logging"
  service_account     = "o11ystack-seed-vector"
  identity_name       = "o11ystack-seed-vector"
  resource_group_name = "${var.env}-${var.location}-controlplane"
}

output "principal_id" {
  value = module.o11y-agent.principal_id
}
output "client_id" {
  value = module.o11y-agent.client_id
}
