# 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 {
  sns_topic_name = {
    "staging" = "DMS-edcf439"
    "prod"    = "DMS-3057ba5"
  }
}

data "aws_sns_topic" "this" {
  name = local.sns_topic_name[var.env]
}

data "aws_eks_cluster" "this" {
  name = "o11y-${var.env}-global-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
}

output "account" {
  value = var.account
}

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

output "sns_topic_arn" {
  value = data.aws_sns_topic.this.arn
}