# Integration tests require actual AWS credentials and resources
# These tests validate the module works in real AWS environments

provider "aws" {
  region  = "us-east-1"
  alias   = "dev"
  profile = "dev"
}

variables {
  environment        = "dev"
  service_name       = "terraform-internal-spa-test"
  application_family = "infrastructure"
}

run "dev_test" {
  command = apply

  variables {
    vpc_id                        = "vpc-34dbfd51"  # dev VPC
    load_balancer_subnet_ids      = ["subnet-44c19a21", "subnet-b649dfef"]
    fully_qualified_domain_name   = "terraform-spa-test.dev.theorchard.io"
    certificate_domain            = "*.dev.theorchard.io"

    # Use VPN users prefix list for ingress
    ingress_prefix_list_names = ["vpn-ny-users"]

    # Static assets
    static_path_patterns = ["/assets/*", "/favicon.ico", "/index.html"]
  }

  providers = {
    aws     = aws.dev
    aws.dns = aws.dev
  }

  assert {
    condition     = startswith(output.load_balancer_arn, "arn:aws:elasticloadbalancing:")
    error_message = "Load balancer ARN should be valid"
  }

  assert {
    condition     = output.s3_bucket_name == "terraform-spa-test.dev.theorchard.io"
    error_message = "S3 bucket name should match fully qualified domain name"
  }

  assert {
    condition     = startswith(output.load_balancer_dns_name, "internal-dev-terraform-internal-spa-test-")
    error_message = "Load balancer DNS name should be valid"
  }
}

run "dev_test_with_route53" {
  command = apply

  variables {
    vpc_id                      = "vpc-34dbfd51"  # dev VPC
    load_balancer_subnet_ids    = ["subnet-44c19a21", "subnet-b649dfef"]
    fully_qualified_domain_name = "terraform-spa-test-r53.dev.theorchard.io"
    certificate_domain          = "*.dev.theorchard.io"
    route53_record_enabled      = true
    route53_zone_name           = "dev.theorchard.io"  # dev zone
    ingress_prefix_list_names   = ["vpn-ny-users"]
  }

  providers = {
    aws     = aws.dev
    aws.dns = aws.dev
  }

  assert {
    condition     = output.route53_record_fqdn != null
    error_message = "Route53 record FQDN should be set when enabled"
  }

  assert {
    condition     = output.route53_record_name == "terraform-internal-spa-test"
    error_message = "Route53 record name should match service name"
  }
}
