# Terraform configuration to create an AWS Global Accelerator.

provider "aws" {
  region = "us-east-1"
}

# --- 1. Create Accelerator ---
resource "aws_globalaccelerator_accelerator" "main" {
  name            = "MyTerraformGlobalAccelerator"
  ip_address_type = "IPV4"
  enabled         = true

  tags = {
    Name = "MyTerraformGlobalAccelerator"
  }
}

# --- 2. Create Listener ---
resource "aws_globalaccelerator_listener" "http_listener" {
  accelerator_arn = aws_globalaccelerator_accelerator.main.id
  port_range {
    from_port = 80
    to_port   = 80
  }
  protocol        = "TCP"
  client_affinity = "NONE"
}

# --- 3. Create Endpoint Group ---
# For this demo, we'll create an empty endpoint group.
# In a real scenario, you would add actual endpoints like ALBs, EC2 instances, etc.
resource "aws_globalaccelerator_endpoint_group" "primary_region" {
  listener_arn      = aws_globalaccelerator_listener.http_listener.id
  endpoint_group_region = "us-east-1" # Specify the region for your endpoints
  traffic_dial_percentage = 100

  # No endpoints defined for this simple example.
  # Example of an endpoint:
  # endpoint_configuration {
  #   endpoint_id = aws_lb.example.arn
  #   weight      = 100
  # }
}

# --- Outputs ---
output "accelerator_dns_name" {
  value       = aws_globalaccelerator_accelerator.main.dns_name
  description = "The DNS name of the Global Accelerator."
}

output "accelerator_arn" {
  value       = aws_globalaccelerator_accelerator.main.arn
  description = "The ARN of the Global Accelerator."
}
