Task: Configure a routing policy that navigates users to the least congested endpoint of a route 53 zone using Route 53 resources. Call the zone "primary" and use "us-east-1" and "eu-central-1" regions

Specification:
Has one "aws_route53_zone" resource
    with "name"

Has two "aws_route53_record" resources
    The first "aws_route53_record" 
        with "name"
        with "type"
        with "ttl"
        with "records"
        with "zone_id" referencing the "aws_route53_zone" resource
        with "set_identifier"
        with "latency_routing_policy" block that contains "region" set to "us-east-1" 
    The second "aws_route53_record" 
        with "name"
        with "type"
        with "ttl"
        with "records"
        with "zone_id" referencing the "aws_route53_zone" resource
        with "set_identifier"
        with "latency_routing_policy" block that contains "region" set to "eu-central-1" 


Terraform configuration (main.tf):
provider "aws" {
  region = "us-east-1"
}

resource "aws_route53_zone" "primary" {
  name = "example53.com"
}


# Record for the EC2 instance in the US East region
resource "aws_route53_record" "us_east_record" {
  zone_id = aws_route53_zone.primary.zone_id
  name    = "service.example53.com"
  type    = "A"
  ttl     = "60"
  records = ["192.0.2.101"]

  set_identifier = "US East N. Virginia"
  
  latency_routing_policy {
    region = "us-east-1"
  }
}

# Record for the EC2 instance in the EU region
resource "aws_route53_record" "eu_central_record" {
  zone_id = aws_route53_zone.primary.zone_id
  name    = "service.example53.com"
  type    = "A"
  ttl     = "60"
  records = ["192.0.2.102"]

  set_identifier = "EU Frankfurt"
  
  latency_routing_policy {
    region = "eu-central-1"
  }
}

Validation policy (checks.rego):
package terraform.validation

default is_configuration_valid = false

default is_valid_r53_zone = false

default is_valid_r53_record_na = false

default is_valid_r53_record_eu = false



# Validate aws_route53_zone resource
is_valid_r53_zone {
        some i
        resource := input.configuration.root_module.resources[i]
    resource.type == "aws_route53_zone"

}

# Validate aws_route53_record
is_valid_r53_record_na {
        some i
    resource := input.configuration.root_module.resources[i]
    resource.type == "aws_route53_record"
    resource.expressions.name
    resource.expressions.latency_routing_policy[0].region.constant_value == "us-east-1"
    resource.expressions.type
    resource.expressions.ttl
    resource.expressions.records
    resource.expressions.set_identifier
    resource.expressions.zone_id.references[0] == "aws_route53_zone.primary.zone_id"

}

is_valid_r53_record_eu {
        some i
    resource := input.configuration.root_module.resources[i]
    resource.type == "aws_route53_record"
    resource.expressions.name
    resource.expressions.latency_routing_policy[0].region.constant_value == "eu-central-1"
    resource.expressions.type
    resource.expressions.ttl
    resource.expressions.records
    resource.expressions.set_identifier
    resource.expressions.zone_id.references[0] == "aws_route53_zone.primary.zone_id"
}



# Combine all checks into a final rule
is_configuration_valid {
    is_valid_r53_zone
    is_valid_r53_record_na
    is_valid_r53_record_eu
}