locals {
  name = var.project_name

  tags = {
    Project     = var.project_name
    Environment = var.environment
    Owner       = var.owner
    CostCenter  = var.cost_center
    ManagedBy   = "terraform"
    Repository  = var.repository
  }

  account_id = data.aws_caller_identity.current.account_id

  # Two runtimes share one execution role. Only allowed_agent may read the demo object.
  agent_names   = ["agentA", "agentB"]
  allowed_agent = "agentA"
  demo_key      = "report.txt"

  # poc/agentctl.py creates the provider and template with these names, so their
  # ARNs and the identifier format are known before the runtimes exist.
  wi_trust_domain = coalesce(var.trust_domain, "${local.account_id}.aws.internal")
  wi_provider_arn = "arn:aws:iam::${local.account_id}:workload-identity-provider/${local.name}"

  # A runtime ID is the runtime name, a hyphen and a random suffix, and runtime
  # names cannot contain hyphens, so this matches only runtimes named allowed_agent.
  allowed_subject = "spiffe://${local.wi_trust_domain}/${var.region}/bedrock-agentcore/runtime/${local.allowed_agent}/${local.allowed_agent}-*"

  trail_arn = "arn:aws:cloudtrail:${var.region}:${local.account_id}:trail/${local.name}"
}
