terraform {
  required_version = ">= 1.0.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = var.aws_region
}

variable "aws_region" {
  description = "AWS region used to access the Route53 hosted zone"
  type        = string
  default     = "us-east-1"
}

variable "record_name" {
  description = "The CNAME target for the DNS record"
  type        = string
}

variable "domain_zone_name" {
  description = "The Route53 hosted zone name"
  type        = string
}

variable "domain_name" {
  description = "The DNS record to create"
  type        = string
}

data "aws_route53_zone" "primary" {
  name         = var.domain_zone_name
  private_zone = false
}

resource "aws_route53_record" "dns" {
  zone_id = data.aws_route53_zone.primary.zone_id
  name    = var.domain_name
  type    = "CNAME"
  ttl     = 300
  records = [var.record_name]
}
