# Terraform configuration to create a public hosted zone and an A record in Route 53.

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

# --- 1. Create Public Hosted Zone ---
# !!! IMPORTANT: Replace "example.com" with a domain you own or a test domain !!!
# If you use a real domain, you will need to update your domain registrar's
# name servers to point to the ones provided by Route 53.
resource "aws_route53_zone" "public_zone" {
  name = "example.com" # !!! IMPORTANT: Replace with your actual domain name !!!

  tags = {
    Name = "MyTerraformPublicZone"
  }
}

# --- 2. Create A Record ---
resource "aws_route53_record" "www_record" {
  zone_id = aws_route53_zone.public_zone.zone_id
  name    = "www.${aws_route53_zone.public_zone.name}"
  type    = "A"
  ttl     = 300
  records = ["192.0.2.1"] # A sample IP address
}

# --- Outputs ---
output "hosted_zone_id" {
  value       = aws_route53_zone.public_zone.zone_id
  description = "The ID of the public hosted zone."
}

output "hosted_zone_name_servers" {
  value       = aws_route53_zone.public_zone.name_servers
  description = "The name servers for the hosted zone. Update your domain registrar with these."
}

output "a_record_name" {
  value       = aws_route53_record.www_record.fqdn
  description = "The FQDN of the A record."
}
