# check and output base eks information for future process
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }

  backend "s3" {
    bucket       = "autonomous-deployment-terraform-state"
    region       = "us-west-2"
    use_lockfile = true
  }
}

provider "aws" {
  profile = var.account
  region  = "us-west-2"
}

variable "env" {
  type = string
}

variable "account" {
  type = string
}

data "aws_eks_cluster" "this" {
  name = "clinic-${var.env}"
}

data "aws_nat_gateways" "this" {
  for_each = toset(data.aws_eks_cluster.this.vpc_config.*.vpc_id)
  vpc_id   = each.key

  filter {
    name   = "state"
    values = ["available"]
  }
}

data "aws_vpc_endpoint_service" "this" {
  filter {
    name   = "tag:Name"
    values = ["clinic-${var.env}-endpoint-service"]
  }
}

data "aws_nat_gateway" "this" {
  for_each = toset(flatten(values(data.aws_nat_gateways.this).*.ids))
  id       = each.key
}

data "aws_iam_role" "sli-cross-account-role" {
  name = "sli-cross-account-role"
}

output "account" {
  value = var.account
}

output "public_ips" {
  value = values(data.aws_nat_gateway.this).*.public_ip
}

output "sli_delivery_stream_role_arn" {
  value = data.aws_iam_role.sli-cross-account-role.arn
}

output "endpoint_service_id" {
  value = data.aws_vpc_endpoint_service.this.service_id
}

output "endpoint_service_name" {
  value = data.aws_vpc_endpoint_service.this.service_name
}
