provider "aws" {
  region = var.aws_region
}

# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket  = "orcd-terraform-state"
    key     = "uat/kafka-infra/schema-registry/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

# data "aws_caller_identity" "current" {}

# module "vpc_info" {
#   source = "git@github.com:theorchard/terraform-vpc-info.git?ref=3.0.4"

#   environment = var.environment
# }

# data "aws_acm_certificate" "theorchard_io" {
#   domain   = "*.theorchard.io"
#   statuses = ["ISSUED"]
# }

# data "aws_route53_zone" "route53_zone" {
#   name = "theorchard.io"
# }

# module "schema_registry_fargate_environment" {
#   source = "git@github.com:theorchard/terraform-fargate.git//?ref=5.5.3"

#   providers = {
#     aws.dns = aws
#   }

#   environment                       = var.environment
#   application_family                = var.application_family
#   additional_tags                   = var.additional_tags
#   service_name                      = var.service_name
#   non_ecr_image                     = "086679231553.dkr.ecr.${var.aws_region}.amazonaws.com/${var.service_name}:latest"
#   aws_region                        = var.aws_region
#   service_platform_version          = "1.4.0"
#   desired_task_count                = 2
#   minimum_capacity                  = 2
#   maximum_capacity                  = 4
#   task_cpu                          = 1024
#   task_memory                       = 2048
#   container_port                    = 8081
#   health_check_grace_period_seconds = 120
#   web_service_health_check_command  = "/usr/bin/bash /usr/local/bin/healthcheck.sh"
#   health_check_path                 = "/schemas/types"
#   vpc_id                            = module.vpc_info.vpc_id
#   https_listener_certificate_id     = split("/", data.aws_acm_certificate.theorchard_io.arn)[1]
#   route53_zone_id                   = data.aws_route53_zone.route53_zone.id
#   propagate_tags                    = true

#   fargate_service_subnets = module.vpc_info.default_private_subnet_ids

#   load_balancer_subnets = module.vpc_info.default_private_subnet_ids

#   prod_https_listener_allow_cidr_blocks = []

#   environment_variables = [
#     {
#       Environment = var.environment
#     },
#     {
#       SCHEMA_REGISTRY_GROUP_UNIQUE_IDENTIFIER = "orchard"
#     },
#     {
#       SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS = "SSL://b-3.uatmanagedkafkacdcdest.dhuccy.c6.kafka.us-east-1.amazonaws.com:9094,b-6.uatmanagedkafkacdcdest.dhuccy.c6.kafka.us-east-1.amazonaws.com:9094,b-1.uatmanagedkafkacdcdest.dhuccy.c6.kafka.us-east-1.amazonaws.com:9094"
#     }
#   ]
# }

# # This rule will allow schema-registry tasks to communicate with each other in multi-node setup:
# # https://docs.confluent.io/platform/current/schema-registry/index.html#ak-coordinator-primary-election
# resource "aws_security_group_rule" "allow_intra_cluster_communication" {
#   from_port         = 8081
#   to_port           = 8081
#   protocol          = "tcp"
#   security_group_id = module.schema_registry_fargate_environment.fargate_security_group_id
#   self              = true
#   type              = "ingress"
# }

# module "fargate_service_datadog_dashboard" {
#   source = "git@github.com:theorchard/terraform-datadog.git//modules/service?ref=6.10.8"

#   environment        = var.environment
#   application_family = var.application_family
#   additional_tags    = var.additional_tags
#   environment_type   = "fargate"
#   service_name       = var.service_name

#   notification_endpoints            = "@slack-kafka-data-highway-alerts"
#   escalation_notification_endpoints = "@slack-data"

#   service_4xx_monitor_enabled = true
# }
