# 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
}

locals {
  config = yamldecode(file("${path.module}/config.yaml"))
}

data "aws_eks_cluster" "this" {
  name = "${var.env}-base-us-west-2"
}

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_nat_gateway" "this" {
  for_each = toset(flatten(values(data.aws_nat_gateways.this).*.ids))
  id       = each.key
}

data "aws_caller_identity" "this" {}

data "aws_acmpca_certificate_authority" "this" {
  arn = "arn:aws:acm-pca:us-west-2:${data.aws_caller_identity.this.account_id}:certificate-authority/${local.config.pca_id[var.account]}"
}

data "aws_sqs_queue" "this" {
  name = local.config.billing_sqs_name[var.env]
}

output "account" {
  value = var.account
}

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

output "pca_arn" {
  value = data.aws_acmpca_certificate_authority.this.arn
}

output "billing_sqs_arn" {
  value = data.aws_sqs_queue.this.arn
}